index.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2018
  17. the Initial Developer. All Rights Reserved.
  18. */
  19. //includes
  20. require_once "root.php";
  21. require_once "resources/require.php";
  22. //check permissions
  23. require_once "resources/check_auth.php";
  24. //show the header
  25. require_once "resources/header.php";
  26. //get the user ID
  27. $sql = "SELECT d.domain_name,e.extension,e.password FROM ";
  28. $sql .= "v_extension_users as t, v_extensions as e, v_users as u, v_domains as d ";
  29. $sql .= "WHERE u.user_uuid = t.user_uuid ";
  30. $sql .= "AND e.extension_uuid = t.extension_uuid ";
  31. $sql .= "AND e.domain_uuid = d.domain_uuid ";
  32. $sql .= "AND u.user_uuid = '" . $_SESSION['user_uuid'] . "' ";
  33. $sql .= "AND e.domain_uuid = '" . $_SESSION["domain_uuid"] . "' LIMIT 1";
  34. $prep_statement = $db->prepare($sql);
  35. if ($prep_statement) {
  36. $prep_statement->execute();
  37. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  38. $domain_name = $row['domain_name'];
  39. $user_extension = $row['extension'];
  40. $user_password = $row['password'];
  41. }
  42. ?>
  43. <style type="text/css">
  44. .inner {
  45. position: absolute;
  46. }
  47. .buttons{
  48. position: fixed;
  49. bottom: 0;
  50. right: 0;
  51. /*width: 200px;*/
  52. border: 10px solid rgba(255, 255, 255, 0);
  53. }
  54. </style>
  55. <div class="">
  56. <div style="position: absolute;"><video id="remote_video" width="640" height="480" muted="muted"></video></div>
  57. <div style="position: absolute;"><video id="local_video" width="160" height="120" muted="muted"></video></div>
  58. <!--<input id='send' name="send" type="button" class='btn btn-success' onclick="send();" value="Send" />-->
  59. </div>
  60. <div class="buttons">
  61. <input id='answer' name="answer" type="button" class='btn btn-success' style="display: none;" onclick="answer();" value="Answer" />
  62. <input id='decline' name="decline" type="button" class='btn btn-danger' style="display: none;" onclick="" value="Decline" />
  63. <input id='mute_audio' name="mute_audio" type="button" class='btn btn-danger' style="display: none;" onclick="mute_audio();" value="Mute Audio" />
  64. <input id='mute_video' name="mute_video" type="button" class='btn btn-danger' style="display: none;" onclick="mute_video();" value="Mute Video" />
  65. <input id='unmute_audio' name="unmute_audio" type="button" class='btn btn-danger' style="display: none;" onclick="unmute_audio();" value="Unmute Audio" />
  66. <input id='unmute_video' name="unmute_video" type="button" class='btn btn-danger' style="display: none;" onclick="unmute_video();" value="Unmute Video" />
  67. <input id='end' name="end" type="button" class='btn btn-danger' style="display: none;" onclick="hangup();" value="End" />
  68. <br />
  69. </div>
  70. <script src="resources/sip-0.7.8.min.js"></script>
  71. <script language="JavaScript" type="text/javascript">
  72. <?php
  73. echo " var session;\n";
  74. echo " var config = {\n";
  75. echo " uri: '".$user_extension."@".$domain_name."',\n";
  76. echo " ws_servers: 'wss://".$domain_name.":7443',\n";
  77. echo " authorizationUser: '".$user_extension."',\n";
  78. echo " password: atob('".base64_encode($user_password)."')\n";
  79. echo " };\n";
  80. ?>
  81. var user_agent = new SIP.UA(config);
  82. //here you determine whether the call has video and audio
  83. var options = {
  84. media: {
  85. constraints: {
  86. audio: true,
  87. video: true
  88. },
  89. render: {
  90. remote: document.getElementById('remote_video'),
  91. local: document.getElementById('local_video')
  92. }
  93. }
  94. };
  95. //makes the call
  96. //session = user_agent.invite('sip:[email protected]', options);
  97. //answer
  98. user_agent.on('invite', function (session) {
  99. document.getElementById('dialplad').style.display = "none";
  100. document.getElementById('answer').style.display = "inline";
  101. document.getElementById('decline').style.display = "inline";
  102. document.getElementById('end').style.display = "none";
  103. document.getElementById('mute_audio').style.display = "inline";
  104. document.getElementById('mute_video').style.display = "inline";
  105. var answer = document.getElementById('answer');
  106. answer.addEventListener("click", function () {
  107. session.accept({
  108. media: {
  109. render: {
  110. remote: document.getElementById('remote_video'),
  111. local: document.getElementById('local_video')
  112. }
  113. }
  114. });
  115. }, false);
  116. var decline = document.getElementById('decline');
  117. decline.addEventListener("click", function () {
  118. session.cancel();
  119. document.getElementById('dialplad').style.display = "grid";
  120. document.getElementById('answer').style.display = "none";
  121. document.getElementById('decline').style.display = "none";
  122. document.getElementById('end').style.display = "none";
  123. }, false);
  124. });
  125. user_agent.on('cancel', function (session) {
  126. document.getElementById('dialplad').style.display = "grid";
  127. document.getElementById('answer').style.display = "none";
  128. document.getElementById('decline').style.display = "none";
  129. document.getElementById('end').style.display = "none";
  130. document.getElementById('dialpad').style.display = "inline";
  131. });
  132. user_agent.on('bye', function (session) {
  133. hangup();
  134. });
  135. function answer() {
  136. document.getElementById('dialplad').style.display = "none";
  137. document.getElementById('answer').style.display = "none";
  138. document.getElementById('decline').style.display = "none";
  139. document.getElementById('end').style.display = "inline";
  140. }
  141. function hangup() {
  142. //session.bye();
  143. session.terminate();
  144. //session.cancel();
  145. end();
  146. }
  147. function send() {
  148. destination = document.getElementById('destination').value;
  149. document.getElementById('dialplad').style.display = "none";
  150. document.getElementById('answer').style.display = "none";
  151. document.getElementById('decline').style.display = "none";
  152. document.getElementById('end').style.display = "inline";
  153. document.getElementById('local_video').style.display = "inline";
  154. document.getElementById('remote_video').style.display = "inline";
  155. document.getElementById('mute_audio').style.display = "inline";
  156. document.getElementById('mute_video').style.display = "inline";
  157. session = user_agent.invite('sip:'+destination+'@<?php echo $domain_name; ?>', options);
  158. var remote_video = document.getElementById("remote_video");
  159. remote_video.setAttribute("controls","controls");
  160. }
  161. function mute_audio(destination) {
  162. session.mute({audio: true});
  163. document.getElementById('mute_audio').style.display = "none";
  164. document.getElementById('unmute_audio').style.display = "inline";
  165. }
  166. function mute_video(destination) {
  167. session.mute({video: true});
  168. document.getElementById('local_video').style.display = "none";
  169. document.getElementById('mute_video').style.display = "none";
  170. document.getElementById('unmute_video').style.display = "inline";
  171. }
  172. function unmute_audio(destination) {
  173. session.unmute({audio: true});
  174. document.getElementById('mute_audio').style.display = "inline";
  175. document.getElementById('unmute_audio').style.display = "none";
  176. }
  177. function unmute_video(destination) {
  178. session.unmute({video: true});
  179. document.getElementById('local_video').style.display = "inline";
  180. document.getElementById('mute_video').style.display = "inline";
  181. document.getElementById('unmute_video').style.display = "none";
  182. }
  183. function end() {
  184. document.getElementById('dialplad').style.display = "grid";
  185. document.getElementById('answer').style.display = "none";
  186. document.getElementById('decline').style.display = "none";
  187. document.getElementById('end').style.display = "none";
  188. document.getElementById('local_video').style.display = "none";
  189. document.getElementById('remote_video').style.display = "none";
  190. document.getElementById('mute_audio').style.display = "none";
  191. document.getElementById('mute_video').style.display = "none";
  192. document.getElementById('unmute_audio').style.display = "none";
  193. document.getElementById('unmute_video').style.display = "none";
  194. document.getElementById('dialpad').style.display = "grid";
  195. }
  196. function digit_add($digit) {
  197. document.getElementById('destination').value = document.getElementById('destination').value + $digit;
  198. }
  199. function digit_delete($digit) {
  200. destination = document.getElementById('destination').value;
  201. document.getElementById('destination').value = destination.substring(0, destination.length -1);
  202. }
  203. function digit_clear($digit) {
  204. document.getElementById('destination').value = '';
  205. }
  206. </script>
  207. <div id='dialplad' class='dialpad' style='position:absolute;z-index:999;'>
  208. <div style="align: left">
  209. <input type="text" id="destination" name="destination" class="destination" value="" />
  210. </div>
  211. <div class="dialpad_wrapper">
  212. <div class="dialpad_box" onclick="digit_add('1');"><strong>1</strong><sup>&nbsp;&nbsp;&nbsp;</sup></div>
  213. <div class="dialpad_box"onclick="digit_add('2');"><strong>2</strong><sup>ABC</sup></div>
  214. <div class="dialpad_box" onclick="digit_add('3');"><strong>3</strong><sup>DEF</sup></div>
  215. <div class="dialpad_box" onclick="digit_add('4');"><strong>4</strong><sup>GHI</sup></div>
  216. <div class="dialpad_box" onclick="digit_add('5');"><strong>5</strong><sup>JKL</sup></div>
  217. <div class="dialpad_box" onclick="digit_add('6');"><strong>6</strong><sup>MNO</sup></div>
  218. <div class="dialpad_box" onclick="digit_add('7');"><strong>7</strong><sup>PQRS</sup></div>
  219. <div class="dialpad_box" onclick="digit_add('8');"><strong>8</strong><sup>TUV</sup></div>
  220. <div class="dialpad_box" onclick="digit_add('9');"><strong>9</strong><sup>WXYZ</sup></div>
  221. <div class="dialpad_box" onclick="digit_add('*');"><strong>*</strong><sup></sup></div>
  222. <div class="dialpad_box" onclick="digit_add('0');"><strong>0</strong><sup></sup></div>
  223. <div class="dialpad_box" onclick="digit_add('#');"><strong>#</strong><sup></sup></div>
  224. <div class="dialpad_box" onclick="digit_clear();"><strong></strong><sup>CLEAR</sup></div>
  225. <div class="dialpad_box" onclick="digit_delete();"><strong></strong><sup>DELETE</sup></div>
  226. <div class="dialpad_box" onclick="send();"><strong></strong><sup>SEND</sup></div>
  227. </div>
  228. </div>
  229. <style type="text/css" style="display: none;">
  230. .destination {
  231. /*background-color: #333333;*/
  232. background-color: rgba(255, 255, 255, 0.5);
  233. color: #333333;
  234. border-radius: 5px;
  235. padding: 10px;
  236. margin: 3px;
  237. width: 305px;
  238. }
  239. .dialpad_wrapper {
  240. display: grid;
  241. grid-template-columns: 100px 100px 100px;
  242. grid-gap: 5px;
  243. color: #444444;
  244. }
  245. .dialpad_box {
  246. /*background-color: #333333;*/
  247. background-color: rgba(0, 0, 0, 0.7);
  248. color: #FFFFFF;
  249. border-radius: 5px;
  250. padding: 10px;
  251. }
  252. strong {
  253. padding: 5px 5px;
  254. color: #FFFFFF;
  255. font-size: 30px;
  256. }
  257. sup {
  258. padding: 3px 3px;
  259. color: #FFFFFF;
  260. font-size: 10px;
  261. }
  262. </style>
  263. <?php
  264. //show the footer
  265. require_once "resources/footer.php";
  266. ?>