Newer
Older
<!--
Asterisk -- An open source telephony toolkit.
See http://www.asterisk.org for more information about
the Asterisk project. Please do not directly contact
any of the maintainers of this project for assistance;
the project provides a web site, mailing lists and IRC
channels for your use.
This program is free software, distributed under the terms of
the GNU General Public License Version 2. See the LICENSE file
at the top of the source tree.
-->
Mark Spencer
committed
<script src="prototype.js"></script>
<script src="astman.js"></script>
<link href="astman.css" media="all" rel="Stylesheet" type="text/css" />
<script>
var logins = new Object;
var logoffs = new Object;
var channels = new Object;
var pongs = new Object;
Mark Spencer
committed
var selectedchan = null;
var hungupchan = "";
var transferedchan = "";
Mark Spencer
committed
var demo = new Object;
Mark Spencer
committed
function loggedOn() {
Mark Spencer
committed
return;
loggedon = 1;
updateButtons();
$('statusbar').innerHTML = "<i>Retrieving channel status...</i>";
astmanEngine.pollEvents();
astmanEngine.sendRequest('action=status', demo.channels);
}
Mark Spencer
committed
function clearChannelList() {
$('channellist').innerHTML = "<i class='light'>Not connected</i>";
}
function loggedOff() {
Mark Spencer
committed
return;
loggedon = 0;
selectedchan = null;
updateButtons();
astmanEngine.channelClear();
clearChannelList();
}
Mark Spencer
committed
function updateButtons()
{
if ($(selectedchan)) {
$('transfer').disabled = 0;
$('hangup').disabled = 0;
} else {
$('transfer').disabled = 1;
$('hangup').disabled = 1;
selectedchan = null;
}
if (loggedon) {
$('username').disabled = 1;
$('secret').disabled = 1;
Mark Spencer
committed
$('logoff').disabled = 0;
$('login').disabled = 1;
$('refresh').disabled = 0;
} else {
$('username').disabled = 0;
$('secret').disabled = 0;
Mark Spencer
committed
$('logoff').disabled = 1;
$('login').disabled = 0;
$('refresh').disabled = 1;
}
}
Mark Spencer
committed
demo.channelCallback = function(target) {
selectedchan = target;
updateButtons();
}
Mark Spencer
committed
demo.channels = function(msgs) {
resp = msgs[0].headers['response'];
if (resp == "Success") {
loggedOn();
} else
loggedOff();
for (i=1;i<msgs.length - 1;i++)
Mark Spencer
committed
astmanEngine.channelUpdate(msgs[i]);
$('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
$('statusbar').innerHTML = "Ready";
}
demo.logins = function(msgs) {
$('statusbar').innerHTML = msgs[0].headers['message'];
resp = msgs[0].headers['response'];
if (resp == "Success")
loggedOn();
else
loggedOff();
};
Mark Spencer
committed
demo.logoffs = function(msgs) {
$('statusbar').innerHTML = msgs[0].headers['message'];
loggedOff();
};
demo.hungup = function(msgs) {
$('statusbar').innerHTML = "Hungup " + hungupchan;
}
Mark Spencer
committed
demo.transferred = function(msgs) {
$('statusbar').innerHTML = "Transferred " + transferredchan;
}
function doHangup() {
hungupchan = selectedchan;
astmanEngine.sendRequest('action=hangup&channel=' + selectedchan, demo.hungup);
}
function doStatus() {
$('statusbar').innerHTML = "<i>Updating channel status...</i>";
astmanEngine.channelClear();
astmanEngine.sendRequest('action=status', demo.channels);
Mark Spencer
committed
function doLogin() {
$('statusbar').innerHTML = "<i>Logging in...</i>";
astmanEngine.sendRequest('action=login&username=' + $('username').value + "&secret=" + $('secret').value, demo.logins);
}
Mark Spencer
committed
function doTransfer() {
var channel = astmanEngine.channelInfo(selectedchan);
var exten = prompt("Enter new extension for " + selectedchan);
var altchan;
if (exten) {
if (channel.link) {
if (confirm("Transfer " + channel.link + " too?"))
altchan = channel.link;
}
if (altchan) {
transferredchan = selectedchan + " and " + altchan + " to " + exten;
astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&extrachannel=" + altchan + "&exten=" + exten, demo.transferred);
} else {
transferredchan = selectedchan + " to " + exten;
astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&exten=" + exten, demo.transferred);
}
}
}
Mark Spencer
committed
function doLogoff() {
$('statusbar').innerHTML = "<i>Logging off...</i>";
astmanEngine.sendRequest('action=logoff', demo.logoffs);
}
Mark Spencer
committed
demo.pongs = function(msgs) {
resp = msgs[0].headers['response'];
if (resp == "Pong") {
$('statusbar').innerHTML = "<i>Already connected...</i>";
loggedOn();
} else {
$('statusbar').innerHTML = "<i>Please login...</i>";
loggedOff();
}
}
Mark Spencer
committed
demo.eventcb = function(msgs) {
var x;
if (loggedon) {
for (i=1;i<msgs.length - 1;i++) {
astmanEngine.channelUpdate(msgs[i]);
}
$('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
astmanEngine.pollEvents();
}
updateButtons();
}
Mark Spencer
committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
function localajaminit() {
astmanEngine.setURL('../rawman');
astmanEngine.setEventCallback(demo.eventcb);
//astmanEngine.setDebug($('ditto'));
clearChannelList();
astmanEngine.sendRequest('action=ping', demo.pongs);
}
</script>
<title>Asterisk™ AJAM Demo</title>
<body onload="localajaminit()">
<table align="center" width=600>
<tr valign="top"><td>
<table align="left">
<tr><td colspan="2"><h2>Asterisk™ AJAM Demo</h2></td>
<tr><td>Username:</td><td><input id="username"></td></tr>
<tr><td>Secret:</td><td><input type="password" id="secret"></td></tr>
<tr><td colspan=2 align="center">
<div id="statusbar">
<span style="margin-left: 4px;font-weight:bold"> </span>
</div>
</td></tr>
<tr><td><input type="submit" id="login" value="Login" onClick="doLogin()"></td>
<td><input type="submit" id="logoff" value="Logoff" disabled=1 onClick="doLogoff()"></td></tr>
</table>
</td><td valign='bottom'>
<table>
<div style="margin-left:10;margin-right:50;margin-top:10;margin-bottom:20">
<i>This is a demo of the Asynchronous Javascript Asterisk Manager interface. You can login with a
valid, appropriately permissioned manager username and secret.</i>
</div>
<tr>
<td><input type="submit" onClick="doStatus()" id="refresh" value="Refresh"></td>
<td><input type="submit" onClick="doTransfer()" id="transfer" value="Transfer..."></td>
<td><input type="submit" onClick="doHangup()" id="hangup" value="Hangup"></td>
</tr>
</table>
</td></tr>
<tr><td colspan=2>
<div id="channellist" class="chanlist">
</div>
</td></tr>
<tr><td align="center" colspan=2>
<font size=-1><i>
Copyright (C) 2006 Digium, Inc. Asterisk and Digium are trademarks of Digium, Inc.
</i></font>
</td></tr>
</table>
</body>