ajamdemo.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <!--
  2. Asterisk -- An open source telephony toolkit.
  3. Copyright (C) 1999 - 2012, Digium, Inc.
  4. Mark Spencer <markster@digium.com>
  5. See http://www.asterisk.org for more information about
  6. the Asterisk project. Please do not directly contact
  7. any of the maintainers of this project for assistance;
  8. the project provides a web site, mailing lists and IRC
  9. channels for your use.
  10. This program is free software, distributed under the terms of
  11. the GNU General Public License Version 2. See the LICENSE file
  12. at the top of the source tree.
  13. -->
  14. <script src="prototype.js"></script>
  15. <script src="astman.js"></script>
  16. <link href="astman.css" media="all" rel="Stylesheet" type="text/css" />
  17. <script>
  18. var logins = new Object;
  19. var logoffs = new Object;
  20. var channels = new Object;
  21. var pongs = new Object;
  22. var loggedon = -1;
  23. var selectedchan = null;
  24. var hungupchan = "";
  25. var transferedchan = "";
  26. var demo = new Object;
  27. function loggedOn() {
  28. if (loggedon == 1)
  29. return;
  30. loggedon = 1;
  31. updateButtons();
  32. $('statusbar').innerHTML = "<i>Retrieving channel status...</i>";
  33. astmanEngine.pollEvents();
  34. astmanEngine.sendRequest('action=status', demo.channels);
  35. }
  36. function clearChannelList() {
  37. $('channellist').innerHTML = "<i class='light'>Not connected</i>";
  38. }
  39. function loggedOff() {
  40. if (loggedon == 0)
  41. return;
  42. loggedon = 0;
  43. selectedchan = null;
  44. updateButtons();
  45. astmanEngine.channelClear();
  46. clearChannelList();
  47. }
  48. function updateButtons()
  49. {
  50. if ($(selectedchan)) {
  51. $('transfer').disabled = 0;
  52. $('hangup').disabled = 0;
  53. } else {
  54. $('transfer').disabled = 1;
  55. $('hangup').disabled = 1;
  56. selectedchan = null;
  57. }
  58. if (loggedon) {
  59. $('username').disabled = 1;
  60. $('secret').disabled = 1;
  61. $('logoff').disabled = 0;
  62. $('login').disabled = 1;
  63. $('refresh').disabled = 0;
  64. } else {
  65. $('username').disabled = 0;
  66. $('secret').disabled = 0;
  67. $('logoff').disabled = 1;
  68. $('login').disabled = 0;
  69. $('refresh').disabled = 1;
  70. }
  71. }
  72. demo.channelCallback = function(target) {
  73. selectedchan = target;
  74. updateButtons();
  75. }
  76. demo.channels = function(msgs) {
  77. resp = msgs[0].headers['response'];
  78. if (resp == "Success") {
  79. loggedOn();
  80. } else
  81. loggedOff();
  82. for (i=1;i<msgs.length - 1;i++)
  83. astmanEngine.channelUpdate(msgs[i]);
  84. $('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
  85. $('statusbar').innerHTML = "Ready";
  86. }
  87. demo.logins = function(msgs) {
  88. $('statusbar').innerHTML = msgs[0].headers['message'];
  89. resp = msgs[0].headers['response'];
  90. if (resp == "Success")
  91. loggedOn();
  92. else
  93. loggedOff();
  94. };
  95. demo.logoffs = function(msgs) {
  96. $('statusbar').innerHTML = msgs[0].headers['message'];
  97. loggedOff();
  98. };
  99. demo.hungup = function(msgs) {
  100. $('statusbar').innerHTML = "Hungup " + hungupchan;
  101. }
  102. demo.transferred = function(msgs) {
  103. $('statusbar').innerHTML = "Transferred " + transferredchan;
  104. }
  105. function doHangup() {
  106. hungupchan = selectedchan;
  107. astmanEngine.sendRequest('action=hangup&channel=' + selectedchan, demo.hungup);
  108. }
  109. function doStatus() {
  110. $('statusbar').innerHTML = "<i>Updating channel status...</i>";
  111. astmanEngine.channelClear();
  112. astmanEngine.sendRequest('action=status', demo.channels);
  113. }
  114. function doLogin() {
  115. $('statusbar').innerHTML = "<i>Logging in...</i>";
  116. astmanEngine.sendRequest('action=login&username=' + $('username').value + "&secret=" + $('secret').value, demo.logins);
  117. }
  118. function doTransfer() {
  119. var channel = astmanEngine.channelInfo(selectedchan);
  120. var exten = prompt("Enter new extension for " + selectedchan);
  121. var altchan;
  122. if (exten) {
  123. if (channel.link) {
  124. if (confirm("Transfer " + channel.link + " too?"))
  125. altchan = channel.link;
  126. }
  127. if (altchan) {
  128. transferredchan = selectedchan + " and " + altchan + " to " + exten;
  129. astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&extrachannel=" + altchan + "&exten=" + exten, demo.transferred);
  130. } else {
  131. transferredchan = selectedchan + " to " + exten;
  132. astmanEngine.sendRequest('action=redirect&channel=' + selectedchan + "&priority=1&exten=" + exten, demo.transferred);
  133. }
  134. }
  135. }
  136. function doLogoff() {
  137. $('statusbar').innerHTML = "<i>Logging off...</i>";
  138. astmanEngine.sendRequest('action=logoff', demo.logoffs);
  139. }
  140. demo.pongs = function(msgs) {
  141. resp = msgs[0].headers['response'];
  142. if (resp == "Pong") {
  143. $('statusbar').innerHTML = "<i>Already connected...</i>";
  144. loggedOn();
  145. } else {
  146. $('statusbar').innerHTML = "<i>Please login...</i>";
  147. loggedOff();
  148. }
  149. }
  150. demo.eventcb = function(msgs) {
  151. var x;
  152. if (loggedon) {
  153. for (i=1;i<msgs.length - 1;i++) {
  154. astmanEngine.channelUpdate(msgs[i]);
  155. }
  156. $('channellist').innerHTML = astmanEngine.channelTable(demo.channelCallback);
  157. astmanEngine.pollEvents();
  158. }
  159. updateButtons();
  160. }
  161. function localajaminit() {
  162. astmanEngine.setURL('../rawman');
  163. astmanEngine.setEventCallback(demo.eventcb);
  164. //astmanEngine.setDebug($('ditto'));
  165. clearChannelList();
  166. astmanEngine.sendRequest('action=ping', demo.pongs);
  167. }
  168. </script>
  169. <title>Asterisk&trade; AJAM Demo</title>
  170. <body onload="localajaminit()">
  171. <table align="center" width=600>
  172. <tr valign="top"><td>
  173. <table align="left">
  174. <tr><td colspan="2"><h2>Asterisk&trade; AJAM Demo</h2></td>
  175. <tr><td>Username:</td><td><input id="username"></td></tr>
  176. <tr><td>Secret:</td><td><input type="password" id="secret"></td></tr>
  177. <tr><td colspan=2 align="center">
  178. <div id="statusbar">
  179. <span style="margin-left: 4px;font-weight:bold">&nbsp;</span>
  180. </div>
  181. </td></tr>
  182. <tr><td><input type="submit" id="login" value="Login" onClick="doLogin()"></td>
  183. <td><input type="submit" id="logoff" value="Logoff" disabled=1 onClick="doLogoff()"></td></tr>
  184. </table>
  185. </td><td valign='bottom'>
  186. <table>
  187. <div style="margin-left:10;margin-right:50;margin-top:10;margin-bottom:20">
  188. <i>This is a demo of the Asynchronous Javascript Asterisk Manager interface. You can login with a
  189. valid, appropriately permissioned manager username and secret.</i>
  190. </div>
  191. <tr>
  192. <td><input type="submit" onClick="doStatus()" id="refresh" value="Refresh"></td>
  193. <td><input type="submit" onClick="doTransfer()" id="transfer" value="Transfer..."></td>
  194. <td><input type="submit" onClick="doHangup()" id="hangup" value="Hangup"></td>
  195. </tr>
  196. </table>
  197. </td></tr>
  198. <tr><td colspan=2>
  199. <div id="channellist" class="chanlist">
  200. </div>
  201. </td></tr>
  202. <tr><td align="center" colspan=2>
  203. <font size=-1><i>
  204. Copyright (C) 2006 Digium, Inc. Asterisk and Digium are trademarks of Digium, Inc.
  205. </i></font>
  206. </td></tr>
  207. </table>
  208. </body>