verto.js 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. 'use strict';
  2. var cur_call = null;
  3. var share_call = null;
  4. var confMan = null;
  5. var vertoHandle;
  6. var ringing = false;
  7. var autocall = false;
  8. var chatting_with = false;
  9. var vid_width = 320;
  10. var vid_height = 180;
  11. var local_vid_width = 320;
  12. var local_vid_height = 180;
  13. var is_full_screen = false;
  14. var outgoingBandwidth;
  15. var incomingBandwidth;
  16. var vqual;
  17. var sessid = null;
  18. var master = null;
  19. var canvas_id = null;
  20. var second_screen = null;
  21. var save_settings = true;
  22. var vertoHandle = null;
  23. var video_screen = "webcam"
  24. $( ".selector" ).pagecontainer({ "theme": "a" });
  25. function display(msg) {
  26. $("#calltitle").html(msg);
  27. }
  28. function clearConfMan() {
  29. if (confMan) {
  30. confMan.destroy();
  31. confMan = null;
  32. }
  33. $("#conf").hide();
  34. $("#canvasui").hide();
  35. $("#message").hide();
  36. chatting_with = null;
  37. }
  38. function goto_dialog(where) {
  39. $( ":mobile-pagecontainer" ).pagecontainer( "change", "#dialog-" + where, { role: "dialog" } );
  40. }
  41. function goto_page(where, force) {
  42. $( ":mobile-pagecontainer" ).pagecontainer( "change", "#page-" + where);
  43. }
  44. var first_login = false;
  45. var online_visible = false;
  46. function online(on) {
  47. if (on) {
  48. $("#online").show();
  49. $("#offline").hide();
  50. first_login = true;
  51. } else {
  52. $("#online").hide();
  53. $("#offline").show();
  54. }
  55. online_visible = on;
  56. }
  57. function setupChat() {
  58. $("#chatwin").html("");
  59. $("#chatsend").click(function() {
  60. if (!cur_call || !chatting_with || !confMan) {
  61. return;
  62. }
  63. confMan.sendChat($("#chatmsg").val(), "message");
  64. $("#chatmsg").val("");
  65. });
  66. $("#chatmsg").keyup(function (event) {
  67. if (event.keyCode == 13 && !event.shiftKey) {
  68. $( "#chatsend" ).trigger( "click" );
  69. }
  70. });
  71. }
  72. function full_screen(name) {
  73. var elem = document.getElementById(name);
  74. if (!elem) return;
  75. if (elem.requestFullscreen) {
  76. elem.requestFullscreen();
  77. } else if (elem.msRequestFullscreen) {
  78. elem.msRequestFullscreen();
  79. } else if (elem.mozRequestFullScreen) {
  80. elem.mozRequestFullScreen();
  81. } else if (elem.webkitRequestFullscreen) {
  82. elem.webkitRequestFullscreen();
  83. }
  84. }
  85. $("#" + video_screen).resize(function(e) {
  86. //console.log("video size changed to " + $("#" + video_screen).width() + "x" + $("#" + video_screen).height());
  87. //if ($("#" + video_screen).width() > $(window).width()) {
  88. //resize(false);
  89. //$("#" + video_screen).width("100%");
  90. //$("#" + video_screen).height("100%");
  91. //}
  92. real_size();
  93. });
  94. function resize(up) {
  95. var width = $("#" + video_screen).width();
  96. var height = $("#" + video_screen).height();
  97. if (up) {
  98. $("#" + video_screen).width(width * 1.20);
  99. $("#" + video_screen).height(height * 1.20);
  100. } else {
  101. $("#" + video_screen).width(width * .80);
  102. $("#" + video_screen).height(height * .80);
  103. }
  104. console.log("video size changed to " + $("#" + video_screen).width() + "x" + $("#" + video_screen).height());
  105. }
  106. $( window ).resize(function() {
  107. real_size();
  108. });
  109. function real_size() {
  110. /* temasys hack */
  111. setTimeout(function() {
  112. $("#" + video_screen).width("");
  113. $("#" + video_screen).height("");
  114. var w = $("#" + video_screen).width();
  115. var h = $("#" + video_screen).height();
  116. var new_w;
  117. var new_h;
  118. var aspect = 1920 / 1080; /*temasys doesn't provide video width hack aspect to wide screen*/
  119. if (w > h) {
  120. new_w = window.innerWidth;
  121. new_h = Math.round(window.innerWidth / aspect);
  122. } else {
  123. new_h = window.innerHeight;
  124. new_w = Math.round(window.innerHeight / aspect);
  125. }
  126. $("#" + video_screen).width(new_w);
  127. $("#" + video_screen).height(new_h);
  128. }, 500);
  129. console.log("video size changed to fit screen");
  130. }
  131. function check_vid_res()
  132. {
  133. if ($("#vqual_qqvga").is(':checked')) {
  134. vid_width = 160;
  135. vid_height = 120;
  136. local_vid_width = 80;
  137. local_vid_height = 60;
  138. } else if ($("#vqual_qvga").is(':checked')) {
  139. vid_width = 320;
  140. vid_height = 240;
  141. local_vid_width = 160;
  142. local_vid_height = 120;
  143. } else if ($("#vqual_vga").is(':checked')) {
  144. vid_width = 640;
  145. vid_height = 480;
  146. local_vid_width = 160;
  147. local_vid_height = 120;
  148. } else if ($("#vqual_qvga_wide").is(':checked')) {
  149. vid_width = 320;
  150. vid_height = 180;
  151. local_vid_width = 160;
  152. local_vid_height = 90;
  153. } else if ($("#vqual_vga_wide").is(':checked')) {
  154. vid_width = 640;
  155. vid_height = 360;
  156. local_vid_width = 160;
  157. local_vid_height = 90;
  158. } else if ($("#vqual_hd").is(':checked')) {
  159. vid_width = 1280;
  160. vid_height = 720;
  161. local_vid_width = 320;
  162. local_vid_height = 180;
  163. } else if ($("#vqual_hhd").is(':checked')) {
  164. vid_width = 1920;
  165. vid_height = 1080;
  166. local_vid_width = 320;
  167. local_vid_height = 180;
  168. }
  169. //$("#local_webcam").width(local_vid_width);
  170. //$("#local_webcam").height(local_vid_height);
  171. real_size();
  172. if (vertoHandle) {
  173. vertoHandle.videoParams({
  174. "minWidth": vid_width,
  175. "minHeight": vid_height,
  176. "maxWidth": vid_width,
  177. "maxHeight": vid_height,
  178. "minFrameRate": 15,
  179. "vertoBestFrameRate": 30,
  180. //chromeMediaSource: 'screen',
  181. //mediaSource: 'screen'
  182. });
  183. }
  184. }
  185. function check_vid() {
  186. var use_vid = $("#use_vid").is(':checked');
  187. return use_vid;
  188. }
  189. var DISABLE_SPEED_TEST = true;
  190. function do_speed_test(fn)
  191. {
  192. if (DISABLE_SPEED_TEST) {
  193. if (fn) {
  194. fn();
  195. }
  196. return;
  197. }
  198. goto_page("bwtest");
  199. vertoHandle.rpcClient.speedTest(1024 * 256, function(e, obj) {
  200. //console.error("Up: " + obj.upKPS, "Down: ", obj.downKPS);
  201. var vid = "default";
  202. //if (outgoingBandwidth === "default") {
  203. outgoingBandwidth = Math.ceil(obj.upKPS * .75).toString();
  204. $("#vqual_hd").prop("checked", true);
  205. vid = "1280x720";
  206. if (outgoingBandwidth < 1024) {
  207. $("#vqual_vga").prop("checked", true);
  208. vid = "640x480";
  209. }
  210. if (outgoingBandwidth < 512) {
  211. $("#vqual_qvga").prop("checked", true);
  212. vid = "320x240";
  213. }
  214. if (outgoingBandwidth < 256) {
  215. $("#vqual_qqvga").prop("checked", true);
  216. vid = "160x120";
  217. }
  218. //}
  219. if (incomingBandwidth === "default") {
  220. incomingBandwidth = Math.ceil(obj.downKPS * .75).toString();
  221. }
  222. console.info(outgoingBandwidth, incomingBandwidth);
  223. $("#bwinfo").html("<b>Bandwidth: " + "Up: " + obj.upKPS + " Down: " + obj.downKPS + " Vid: " + vid + "</b>");
  224. if (fn) {
  225. fn();
  226. }
  227. });
  228. }
  229. function messageTextToJQ(body) {
  230. // Builds a jQuery collection from body text, linkifies http/https links, imageifies http/https links to images, and doesn't allow script injection
  231. var match, $link, img_url, $body_parts = $(), rx = /(https?:\/\/[^ \n\r]+|\n\r|\n|\r)/;
  232. while ((match = rx.exec(body)) !== null) {
  233. if (match.index !== 0) {
  234. $body_parts = $body_parts.add(document.createTextNode(body.substr(0, match.index)));
  235. }
  236. if (match[0].match(/^(\n|\r|\n\r)$/)) {
  237. // Make a BR from a newline
  238. $body_parts = $body_parts.add($('<br />'));
  239. body = body.substr(match.index + match[0].length);
  240. } else {
  241. // Make a link (or image)
  242. $link = $('<a target="_blank" />').attr('href', match[0]);
  243. if (match[0].search(/\.(gif|jpe?g|png)/) > -1) {
  244. // Make an image
  245. img_url = match[0];
  246. // Handle dropbox links
  247. if (img_url.indexOf('dropbox.com') !== -1) {
  248. if (img_url.indexOf('?dl=1') === -1 && img_url.indexOf('?dl=0') === -1) {
  249. img_url += '?dl=1';
  250. } else if (img_url.indexOf('?dl=0') !== -1) {
  251. img_url = img_url.replace(/dl=0$/, 'dl=1');
  252. }
  253. }
  254. $link.append($('<img border="0" class="chatimg" />').attr('src', img_url));
  255. } else {
  256. // Make a link
  257. $link.text(match[0]);
  258. }
  259. body = body.substr(match.index + match[0].length);
  260. $body_parts = $body_parts.add($link);
  261. }
  262. }
  263. if (body) {
  264. $body_parts = $body_parts.add(document.createTextNode(body));
  265. }
  266. return $body_parts;
  267. } // END function messageTextToJQ
  268. var callbacks = {
  269. onMessage: function(verto, dialog, msg, data) {
  270. switch (msg) {
  271. case $.verto.enum.message.pvtEvent:
  272. // console.error("pvtEvent", data.pvtData);
  273. if (data.pvtData) {
  274. switch (data.pvtData.action) {
  275. case "conference-liveArray-part":
  276. clearConfMan();
  277. if (data.pvtData.secondScreen) {
  278. $("#mainButtons").show();
  279. $("#canvasButtons").hide();
  280. $("#keypad").show();
  281. }
  282. break;
  283. case "conference-liveArray-join":
  284. clearConfMan();
  285. if (data.pvtData.secondScreen) {
  286. $("#mainButtons").hide();
  287. $("#canvasButtons").show();
  288. $("#keypad").hide();
  289. } else {
  290. confMan = new $.verto.confMan(verto, {
  291. tableID: "#conf_list",
  292. statusID: "#conf_count",
  293. mainModID: "#conf_mod",
  294. displayID: "#conf_display",
  295. dialog: dialog,
  296. hasVid: check_vid(),
  297. laData: data.pvtData,
  298. chatCallback: function(v, e) {
  299. console.log(e);
  300. var from = e.data.fromDisplay || e.data.from || "Unknown";
  301. var message = e.data.message || "";
  302. $('#chatwin')
  303. .append($('<span class="chatuid" />').text(from + ':'))
  304. .append($('<br />'))
  305. .append(messageTextToJQ(message))
  306. .append($('<br />'));
  307. $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
  308. }
  309. });
  310. if (!data.pvtData.canvasCount) {
  311. data.pvtData.canvasCount = 1;
  312. }
  313. var canvasCount = data.pvtData.canvasCount + 0;
  314. if (canvasCount <= 1) {
  315. $("#canvasui").hide();
  316. } if (canvasCount > 1) {
  317. $("#canvasui").show();
  318. $("#canvasid").selectmenu({});
  319. $("#canvasid").selectmenu("enable");
  320. $("#canvasid").empty();
  321. var x;
  322. for (x = 1; x < canvasCount; x++) {
  323. $("#canvasid").append(new Option("Canvas " + (x + 1), (x + 1)));
  324. }
  325. $("#canvasid").append(new Option("Super Canvas", x + 1));
  326. $("#canvasid").selectmenu('refresh', true);
  327. $("#canvasbut").click(function() {
  328. var canvas_id = $("#canvasid").find(":selected").val();
  329. var s = window.location.href;
  330. s = s.replace(/\#.*/,'');
  331. s += "#sessid=random&master=" + cur_call.callID +
  332. "&secondScreen=true&canvas_id=" + canvas_id + "&autocall=" + $("#ext").val() + "-canvas-" + canvas_id;
  333. console.log("opening new window to " + s);
  334. window.open(s, "canvas_window_" + canvas_id, "toolbar=0,location=0,menubar=0,directories=0,width=" + ($("#" + video_screen).width() + 50) + ",height=" + ($("#" + video_screen).height() + 400));
  335. });
  336. }
  337. $("#conf").show();
  338. $("#chatwin").html("");
  339. if (data.pvtData.hipchatURL) {
  340. var namex = $("#cidname").val();
  341. if (!namex.indexOf(" ") > 0) {
  342. namex += " " + $("#cid").val();
  343. }
  344. var name = namex.replace(/ /i, '%20');
  345. $('#hcmessage').hipChatPanel({
  346. url: data.pvtData.hipchatURL + "?name=" + name,
  347. timezone: "CST"
  348. });
  349. $("#hctop").show().find('.show-hipchat').click();
  350. } else {
  351. $("#message").show();
  352. }
  353. chatting_with = data.pvtData.chatChannel;
  354. }
  355. break;
  356. }
  357. }
  358. break;
  359. case $.verto.enum.message.info:
  360. var body = data.body;
  361. /*
  362. // This section has been replaced with messageTextToJQ function
  363. if (body.match(/\.gif|\.jpg|\.jpeg|\.png/)) {
  364. var mod = "";
  365. if (body.match(/dropbox.com/)) {
  366. mod = "?dl=1";
  367. }
  368. body = body.replace(/(http[s]{0,1}:\/\/\S+)/g, "<a target='_blank' href='$1'>$1<br><img border='0' class='chatimg' src='$1'" + mod + "><\/a>");
  369. } else {
  370. body = body.replace(/(http[s]{0,1}:\/\/\S+)/g, "<a target='_blank' href='$1'>$1<\/a>");
  371. }
  372. if (body.slice(-1) !== "\n") {
  373. body += "\n";
  374. }
  375. body = body.replace(/(?:\r\n|\r|\n)/g, '<br />');
  376. var from = data.from_msg_name || data.from;
  377. $("#chatwin").append("<span class=chatuid>" + from + ":</span><br>" + body);
  378. $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
  379. */
  380. var from = data.from_msg_name || data.from;
  381. $('#chatwin')
  382. .append($('<span class="chatuid" />').text(from + ':'))
  383. .append($('<br />'))
  384. .append(messageTextToJQ(body))
  385. .append($('<br />'));
  386. $('#chatwin').animate({"scrollTop": $('#chatwin')[0].scrollHeight}, "fast");
  387. break;
  388. case $.verto.enum.message.display:
  389. var party = dialog.params.remote_caller_id_name + "<" + dialog.params.remote_caller_id_number + ">";
  390. display("Talking to: " + dialog.cidString());
  391. break;
  392. default:
  393. break;
  394. }
  395. },
  396. onDialogState: function(d) {
  397. //console.error(d, share_call, d == share_call, d.state);
  398. if (d == share_call) {
  399. switch (d.state) {
  400. case $.verto.enum.state.early:
  401. case $.verto.enum.state.active:
  402. $("#nosharebtn").show();
  403. $("#sharebtn").hide();
  404. break;
  405. case $.verto.enum.state.destroy:
  406. $("#nosharebtn").hide();
  407. $("#sharebtn").show();
  408. share_call = null;
  409. break;
  410. }
  411. return;
  412. }
  413. if (!cur_call) {
  414. cur_call = d;
  415. }
  416. if (d.state == $.verto.enum.state.ringing) {
  417. ringing = true;
  418. } else {
  419. ringing = false;
  420. }
  421. switch (d.state) {
  422. case $.verto.enum.state.ringing:
  423. display("Call From: " + d.cidString());
  424. check_vid_res();
  425. $("#ansbtn").click(function() {
  426. console.error("WTF", cur_call, d);
  427. cur_call.answer({
  428. useStereo: $("#use_stereo").is(':checked'),
  429. callee_id_name: $("#cidname").val(),
  430. callee_id_number: $("#cid").val(),
  431. useCamera: $("#usecamera").find(":selected").val(),
  432. useMic: $("#usemic").find(":selected").val(),
  433. useSpeak: $("#usespeak").find(":selected").val()
  434. });
  435. $('#dialog-incoming-call').dialog('close');
  436. });
  437. $("#declinebtn").click(function() {
  438. cur_call.hangup();
  439. $('#dialog-incoming-call').dialog('close');
  440. });
  441. goto_dialog("incoming-call");
  442. $("#dialog-incoming-call-txt").text("Incoming call from: " + d.cidString());
  443. if (d.params.wantVideo) {
  444. $("#vansbtn").click(function() {
  445. $("#use_vid").prop("checked", true);
  446. cur_call.answer({
  447. useVideo: true,
  448. useStereo: $("#use_stereo").is(':checked'),
  449. useCamera: $("#usecamera").find(":selected").val(),
  450. useMic: $("#usemic").find(":selected").val(),
  451. useSpeak: $("#usespeak").find(":selected").val()
  452. });
  453. });
  454. // the buttons in this jquery mobile wont hide .. gotta wrap them in a div as a workaround
  455. $("#vansdiv").show();
  456. } else {
  457. $("#vansdiv").hide();
  458. }
  459. break;
  460. case $.verto.enum.state.trying:
  461. display("Calling: " + d.cidString());
  462. goto_page("incall");
  463. break;
  464. case $.verto.enum.state.early:
  465. case $.verto.enum.state.active:
  466. if (sessid) {
  467. cur_call.setMute("on");
  468. display("Viewing Canvas: " + canvas_id);
  469. vertoHandle.subscribe("presence", {
  470. handler: function(v, e) {
  471. if (e.data.channelUUID === master && e.data.channelCallState === "HANGUP") {
  472. cur_call.hangup();
  473. }
  474. }
  475. });
  476. } else {
  477. display("Talking to: " + d.cidString());
  478. }
  479. goto_page("incall");
  480. real_size();
  481. break;
  482. case $.verto.enum.state.hangup:
  483. $("#main_info").html("Call ended with cause: " + d.cause);
  484. goto_page("main");
  485. exit_full_screen();
  486. case $.verto.enum.state.destroy:
  487. $("#hangup_cause").html("");
  488. clearConfMan();
  489. real_size();
  490. cur_call = null;
  491. if (sessid) {
  492. setTimeout(function() {
  493. delete $.verto.warnOnUnload;
  494. window.close();
  495. }, 500);
  496. }
  497. break;
  498. case $.verto.enum.state.held:
  499. break;
  500. default:
  501. display("");
  502. break;
  503. }
  504. },
  505. onWSLogin: function(v, success) {
  506. display("");
  507. cur_call = null;
  508. ringing = false;
  509. if (success) {
  510. do_speed_test(function() {
  511. online(true);
  512. goto_page("main");
  513. $("input[type='radio']").checkboxradio("refresh");
  514. $("input[type='checkbox']").checkboxradio("refresh");
  515. /*
  516. verto.subscribe("presence", {
  517. handler: function(v, e) {
  518. console.error("PRESENCE:", e);
  519. }
  520. });
  521. */
  522. if (!window.location.hash) {
  523. goto_page("main");
  524. }
  525. if (autocall) {
  526. autocall = false;
  527. docall();
  528. }
  529. });
  530. } else {
  531. goto_page("main");
  532. goto_dialog("login-error");
  533. }
  534. },
  535. onWSClose: function(v, success) {
  536. display("");
  537. online(false);
  538. var today = new Date();
  539. $("#errordisplay").html("Connection Error.<br>Last Attempt: " + today);
  540. goto_page("main");
  541. if (sessid) {
  542. window.close();
  543. }
  544. },
  545. onEvent: function(v, e) {
  546. console.debug("GOT EVENT", e);
  547. },
  548. };
  549. $("#hold").click(function(e) {
  550. cur_call.toggleHold();
  551. goto_dialog("hold");
  552. });
  553. $("#cancelxferbtn").click(function(e) {
  554. $("#xferto").val("");
  555. $("#xferdiv").hide();
  556. });
  557. $(".startxferbtn").click(function(e) {
  558. if ($('#xferdiv').is(':visible')) {
  559. var xfer = $("#xferto").val();
  560. if (xfer) {
  561. cur_call.transfer(xfer);
  562. }
  563. $("#xferto").val("");
  564. $("#xferdiv").hide();
  565. } else {
  566. $("#xferdiv").show();
  567. }
  568. });
  569. $("#clearbtn").click(function(e) {
  570. $("#ext").val("");
  571. });
  572. $(".dialbtn").click(function(e) {
  573. $("#ext").val($("#ext").val() + e.currentTarget.textContent);
  574. });
  575. $(".dtmf").click(function(e) {
  576. if ($('#xferdiv').is(':visible')) {
  577. $("#xferto").val($("#xferto").val() + e.currentTarget.textContent);
  578. } else {
  579. cur_call.dtmf(e.currentTarget.textContent);
  580. }
  581. });
  582. $("#hupbtn").click(function() {
  583. exit_full_screen();
  584. vertoHandle.hangup();
  585. cur_call = null;
  586. });
  587. $("#hupbtn2").click(function() {
  588. delete $.verto.warnOnUnload;
  589. vertoHandle.hangup();
  590. cur_call = null;
  591. });
  592. $("#mutebtn").click(function() {
  593. cur_call.dtmf("0");
  594. });
  595. $("#localmutebtn").click(function() {
  596. var muted = cur_call.setMute("toggle");
  597. if (muted) {
  598. display("Talking to: " + cur_call.cidString() + " [LOCALLY MUTED]");
  599. } else {
  600. display("Talking to: " + cur_call.cidString());
  601. }
  602. });
  603. $("#localvidmutebtn").click(function() {
  604. var muted = cur_call.setVideoMute("toggle");
  605. if (muted) {
  606. display("Talking to: " + cur_call.cidString() + " [VIDEO LOCALLY MUTED]");
  607. } else {
  608. display("Talking to: " + cur_call.cidString());
  609. }
  610. });
  611. $("#vmutebtn").click(function() {
  612. cur_call.dtmf("*0");
  613. });
  614. var is_full = false;
  615. var usrto;
  616. var rs;
  617. function noop() { return; }
  618. function on_full(which)
  619. {
  620. is_full = which;
  621. if (is_full) {
  622. clearTimeout(rs);
  623. $("#usr2").hide();
  624. rs = setTimeout(function() {
  625. $("#" + video_screen).width($(window).width());
  626. $("#" + video_screen).height($(window).height());
  627. }, 1500);
  628. $("#rows").css("position", "absolute").css("z-index", "2");
  629. $("#fullbtn").text("Exit Full Screen");
  630. $("#fullbtn2").text("Exit Full Screen");
  631. $("#usrctl").show();
  632. } else {
  633. $("#usrctl").hide();
  634. $("#rows").css("position", "static").css("z-index", "2");
  635. $("#fullbtn").text("Enter Full Screen");
  636. $("#fullbtn2").text("Enter Full Screen");
  637. clearTimeout(usrto);
  638. clearTimeout(rs);
  639. rs = setTimeout(function() {
  640. $("#" + video_screen).width("100%");
  641. $("#" + video_screen).height("100%");
  642. }, 1500);
  643. }
  644. }
  645. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange MSFullscreenChange',
  646. function(e) {
  647. if (!is_full) {
  648. on_full(true);
  649. } else {
  650. on_full(false);
  651. }
  652. });
  653. function exit_full_screen()
  654. {
  655. if (document.webkitFullscreenEnabled) {
  656. document.webkitExitFullscreen();
  657. } else if (document.mozFullScreenEnabled) {
  658. document.mozCancelFullScreen();
  659. }
  660. }
  661. $("#fullbtn").click(function() {
  662. if (!is_full) {
  663. full_screen("fs");
  664. } else {
  665. exit_full_screen();
  666. }
  667. });
  668. $("#fullbtn2").click(function() {
  669. if (!is_full) {
  670. full_screen("fs");
  671. } else {
  672. exit_full_screen();
  673. }
  674. });
  675. $("#biggerbtn").click(function() {
  676. resize(true);
  677. });
  678. $("#smallerbtn").click(function() {
  679. resize(false);
  680. });
  681. $("#" + video_screen).click(function() {
  682. check_vid();
  683. });
  684. function docall() {
  685. $('#ext').trigger('change');
  686. if (cur_call) {
  687. return;
  688. }
  689. $("#main_info").html("Trying");
  690. check_vid_res();
  691. console.error(outgoingBandwidth, incomingBandwidth);
  692. cur_call = vertoHandle.newCall({
  693. destination_number: $("#ext").val(),
  694. caller_id_name: $("#cidname").val(),
  695. caller_id_number: $("#cid").val(),
  696. outgoingBandwidth: outgoingBandwidth,
  697. incomingBandwidth: incomingBandwidth,
  698. useVideo: check_vid(),
  699. useStereo: $("#use_stereo").is(':checked'),
  700. useCamera: (sessid || canvas_id) ? "none" : $("#usecamera").find(":selected").val(),
  701. useMic: (sessid || canvas_id) ? "none" : $("#usemic").find(":selected").val(),
  702. useSpeak: (sessid || canvas_id) ? "none" : $("#usespeak").find(":selected").val(),
  703. dedEnc: $("#use_dedenc").is(':checked'),
  704. mirrorInput: $("#mirror_input").is(':checked'),
  705. userVariables: {
  706. avatar: $("#avatar").val(),
  707. email: $("#email").val(),
  708. },
  709. });
  710. }
  711. function doshare(on) {
  712. //$('#ext').trigger('change');
  713. if (!on) {
  714. if (share_call) {
  715. share_call.hangup();
  716. }
  717. return;
  718. }
  719. if (share_call) {
  720. return;
  721. }
  722. var sharedev = $("#useshare").find(":selected").val();
  723. if (sharedev !== "screen") {
  724. share_call = vertoHandle.newCall({
  725. destination_number: $("#ext").val() + "-screen",
  726. caller_id_name: $("#cidname").val() + " (Screen)",
  727. caller_id_number: $("#cid").val() + " (screen)",
  728. outgoingBandwidth: outgoingBandwidth,
  729. incomingBandwidth: incomingBandwidth,
  730. useCamera: sharedev,
  731. useVideo: true,
  732. screenShare: true,
  733. dedEnc: $("#use_dedenc").is(':checked'),
  734. mirrorInput: $("#mirror_input").is(':checked')
  735. });
  736. return;
  737. }
  738. console.log("Attempting Screen Capture....");
  739. var sharefunc = function(error, sourceId, screen_constraints) {
  740. share_call = vertoHandle.newCall({
  741. destination_number: $("#ext").val() + "-screen",
  742. caller_id_name: $("#cidname").val() + " (Screen)",
  743. caller_id_number: $("#cid").val() + " (screen)",
  744. outgoingBandwidth: outgoingBandwidth,
  745. incomingBandwidth: incomingBandwidth,
  746. videoParams: screen_constraints ? screen_constraints.video.mandatory : {},
  747. useVideo: true,
  748. screenShare: true,
  749. dedEnc: $("#use_dedenc").is(':checked'),
  750. mirrorInput: $("#mirror_input").is(':checked')
  751. });
  752. };
  753. if (!!navigator.mozGetUserMedia) {
  754. sharefunc();
  755. } else {
  756. getScreenId(sharefunc);
  757. }
  758. //$("#main_info").html("Trying");
  759. //check_vid_res();
  760. //cur_share = vertoHandle.newCall({
  761. // destination_number: $("#ext").val(),
  762. // caller_id_name: $("#cidname").val(),
  763. // caller_id_number: $("#cid").val(),
  764. // useVideo: check_vid(),
  765. // useStereo: $("#use_stereo").is(':checked')
  766. //});
  767. }
  768. $("#callbtn").click(function() {
  769. docall();
  770. });
  771. $("#refreshbtn").click(function() {
  772. refresh_devices();
  773. });
  774. $("#sharebtn").click(function() {
  775. doshare(true);
  776. });
  777. $("#nosharebtn").click(function() {
  778. doshare(false);
  779. });
  780. $("#nosharebtn").hide();
  781. function pop(id, cname, dft, onchange) {
  782. var tmp = $.cookie(cname) || dft;
  783. $.cookie(cname, tmp, {
  784. expires: 365
  785. });
  786. $(id).val(tmp).change(function() {
  787. if (!save_settings) return;
  788. $.cookie(cname, $(id).val(), {
  789. expires: 365
  790. });
  791. if (onchange) {
  792. onchange($(id));
  793. }
  794. });
  795. }
  796. function pop_select(id, cname, dft, onchange) {
  797. var tmp = $.cookie(cname) || dft;
  798. $.cookie(cname, tmp, {
  799. expires: 365
  800. });
  801. // $("#usecamera").find(":selected").val()
  802. $(id).change(function() {
  803. if (!save_settings) return;
  804. tmp = $(id).find(":selected").val();
  805. $.cookie(cname, tmp, {
  806. expires: 365
  807. });
  808. if (onchange) {
  809. onchange($(id));
  810. }
  811. });
  812. }
  813. function refresh_devices()
  814. {
  815. $.verto.refreshDevices();
  816. $("#useshare").selectmenu({});
  817. $("#useshare").selectmenu({});
  818. $("#usemic").selectmenu({});
  819. $("#usespeak").selectmenu({});
  820. $("#useshare").selectmenu("enable");
  821. $("#useshare").selectmenu("enable");
  822. $("#usemic").selectmenu("enable");
  823. $("#usespeak").selectmenu("enable");
  824. $("#useshare").empty();
  825. $("#usecamera").empty();
  826. $("#usemic").empty();
  827. $("#usespeak").empty();
  828. var x = 0;
  829. $("#usecamera").append(new Option("No Camera", "none"));
  830. $("#usemic").append(new Option("Do Not Specify", "any"));
  831. $("#usespeak").append(new Option("Do Not Specify", "any"));
  832. for (var i in $.verto.videoDevices) {
  833. var source = $.verto.videoDevices[i];
  834. var o = new Option(source.label, source.id);
  835. if (!x) {
  836. o.selected = true;
  837. }
  838. $("#usecamera").append(o);
  839. var oo = new Option(source.label, source.id);
  840. if (!x++) {
  841. o.selected = true;
  842. }
  843. $("#useshare").append(oo);
  844. }
  845. x = 1;
  846. for (var i in $.verto.audioInDevices) {
  847. var source = $.verto.audioInDevices[i];
  848. var o = new Option(source.label, source.id);
  849. if (!x++) {
  850. o.selected = true;
  851. }
  852. $("#usemic").append(o);
  853. }
  854. for (var i in $.verto.audioOutDevices) {
  855. var source = $.verto.audioOutDevices[i];
  856. var o = new Option(source.label, source.id);
  857. if (!x++) {
  858. o.selected = true;
  859. }
  860. $("#usespeak").append(o);
  861. }
  862. var o = new Option("Screen", "screen");
  863. o.selected = true;
  864. $("#useshare").append(o);
  865. $("#usemic").append(new Option("No Microphone", "none"));
  866. $("#usecamera").selectmenu('refresh', true);
  867. $("#usemic").selectmenu('refresh', true);
  868. $("#usespeak").selectmenu('refresh', true);
  869. $("#useshare").selectmenu('refresh', true);
  870. //$("input[type='radio']).checkboxradio({});
  871. //$("input[type='radio']").checkboxradio("refresh");
  872. //$("input[type='checkbox']").checkboxradio("refresh");
  873. //console.error($("#usecamera").find(":selected").val());
  874. //$.FSRTC.getValidRes($("#usecamera").find(":selected").val(), undefined);
  875. var tmp;
  876. tmp = $.cookie("verto_demo_camera_selected") || "false";
  877. if (tmp) {
  878. $('#usecamera option[value=' + tmp + ']').prop('selected', 'selected').change();
  879. pop_select("#usecamera","verto_demo_camera_selected", tmp);
  880. }
  881. var tmp;
  882. tmp = $.cookie("verto_demo_share_selected") || "false";
  883. if (tmp) {
  884. $('#useshare option[value=' + tmp + ']').prop('selected', 'selected').change();
  885. pop_select("#useshare","verto_demo_share_selected", tmp);
  886. }
  887. tmp = $.cookie("verto_demo_mic_selected") || "false";
  888. if (tmp) {
  889. $('#usemic option[value=' + tmp + ']').prop('selected', 'selected').change();
  890. pop_select("#usemic","verto_demo_mic_selected", tmp);
  891. }
  892. tmp = $.cookie("verto_demo_speak_selected") || "false";
  893. if (tmp) {
  894. $('#usespeak option[value=' + tmp + ']').prop('selected', 'selected').change();
  895. pop_select("#usespeak","verto_demo_speak_selected", tmp);
  896. }
  897. }
  898. function init() {
  899. cur_call = null;
  900. goto_page("bwtest");
  901. $("#usecamera").selectmenu({});
  902. $("#usemic").selectmenu({});
  903. $("#usespeak").selectmenu({});
  904. $("#useshare").selectmenu({});
  905. if (!autocall) {
  906. pop("#ext", "verto_demo_ext", "3500");
  907. }
  908. pop("#avatar", "verto_demo_avatar", "", function(jq) {
  909. $("#avatar_img").attr("src", jq.val());
  910. });
  911. pop("#cidname", "verto_demo_name", "FreeSWITCH User");
  912. pop("#cid", "verto_demo_cid", "1008");
  913. pop("#email", "verto_demo_emailaddr", "", function(jq) {
  914. $("#avatar").val("http://gravatar.com/avatar/" + md5($("#email").val()) + ".png?s=600");
  915. $("#avatar_img").attr("src", $("#avatar").val());
  916. $("#avatar").change();
  917. });
  918. pop("#textto", "verto_demo_textto", "1000");
  919. pop("#login", "verto_demo_login", "1008");
  920. pop("#passwd", "verto_demo_passwd", "1234");
  921. pop("#hostName", "verto_demo_hostname", window.location.hostname);
  922. pop("#wsURL", "verto_demo_wsurl", "wss://" + window.location.hostname + ":8082");
  923. $("#avatar_img").attr("src", $("#avatar").val());
  924. var tmp = $.cookie("verto_demo_vid_checked") || "true";
  925. $.cookie("verto_demo_vid_checked", tmp, {
  926. expires: 365
  927. });
  928. if (tmp !== "true") {
  929. $("#camdiv").hide();
  930. $(".sharediv").hide();
  931. } else {
  932. $(".sharediv").show();
  933. $("#camdiv").show();
  934. }
  935. $("#use_vid").prop("checked", tmp === "true").change(function(e) {
  936. tmp = $("#use_vid").is(':checked');
  937. if (!tmp) {
  938. $("#camdiv").hide();
  939. $(".sharediv").hide();
  940. } else {
  941. $("#camdiv").show();
  942. $(".sharediv").show();
  943. }
  944. $.cookie("verto_demo_vid_checked", tmp ? "true" : "false", {
  945. expires: 365
  946. });
  947. });
  948. tmp = $.cookie("verto_demo_dedenc_checked") || "false";
  949. $.cookie("verto_demo_dedenc_checked", tmp, {
  950. expires: 365
  951. });
  952. $("#use_dedenc").prop("checked", tmp === "true").change(function(e) {
  953. tmp = $("#use_dedenc").is(':checked');
  954. if (!tmp && $("#mirror_input").is(':checked')) {
  955. $("#mirror_input").click();
  956. }
  957. $.cookie("verto_demo_dedenc_checked", tmp ? "true" : "false", {
  958. expires: 365
  959. });
  960. });
  961. tmp = $.cookie("verto_demo_mirror_input_checked") || "false";
  962. $.cookie("verto_demo_mirror_input_checked", tmp, {
  963. expires: 365
  964. });
  965. $("#mirror_input").prop("checked", tmp === "true").change(function(e) {
  966. tmp = $("#mirror_input").is(':checked');
  967. if (tmp && !$("#use_dedenc").is(':checked')) {
  968. $("#use_dedenc").click();
  969. }
  970. $.cookie("verto_demo_mirror_input_checked", tmp ? "true" : "false", {
  971. expires: 365
  972. });
  973. });
  974. //
  975. outgoingBandwidth = $.cookie("verto_demo_outgoingBandwidth") || "default";
  976. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  977. expires: 365
  978. });
  979. $("#outgoingBandwidth_250kb").prop("checked", outgoingBandwidth === "250").change(function(e) {
  980. if ($("#outgoingBandwidth_250kb").is(':checked')) {
  981. outgoingBandwidth = "250";
  982. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  983. expires: 365
  984. });
  985. }
  986. });
  987. $("#outgoingBandwidth_500kb").prop("checked", outgoingBandwidth === "500").change(function(e) {
  988. if ($("#outgoingBandwidth_500kb").is(':checked')) {
  989. outgoingBandwidth = "500";
  990. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  991. expires: 365
  992. });
  993. }
  994. });
  995. $("#outgoingBandwidth_1024kb").prop("checked", outgoingBandwidth === "1024").change(function(e) {
  996. if ($("#outgoingBandwidth_1024kb").is(':checked')) {
  997. outgoingBandwidth = "1024";
  998. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  999. expires: 365
  1000. });
  1001. }
  1002. });
  1003. $("#outgoingBandwidth_1536kb").prop("checked", outgoingBandwidth === "1536").change(function(e) {
  1004. if ($("#outgoingBandwidth_1536kb").is(':checked')) {
  1005. outgoingBandwidth = "1536";
  1006. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  1007. expires: 365
  1008. });
  1009. }
  1010. });
  1011. $("#outgoingBandwidth_2048kb").prop("checked", outgoingBandwidth === "2048").change(function(e) {
  1012. if ($("#outgoingBandwidth_2048kb").is(':checked')) {
  1013. outgoingBandwidth = "2048";
  1014. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  1015. expires: 365
  1016. });
  1017. }
  1018. });
  1019. $("#outgoingBandwidth_5120kb").prop("checked", outgoingBandwidth === "5120").change(function(e) {
  1020. if ($("#outgoingBandwidth_5120kb").is(':checked')) {
  1021. outgoingBandwidth = "5120";
  1022. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  1023. expires: 365
  1024. });
  1025. }
  1026. });
  1027. $("#outgoingBandwidth_0kb").prop("checked", outgoingBandwidth === "0").change(function(e) {
  1028. if ($("#outgoingBandwidth_0kb").is(':checked')) {
  1029. outgoingBandwidth = "0";
  1030. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  1031. expires: 365
  1032. });
  1033. }
  1034. });
  1035. $("#outgoingBandwidth_default").prop("checked", outgoingBandwidth === "default").change(function(e) {
  1036. if ($("#outgoingBandwidth_default").is(':checked')) {
  1037. outgoingBandwidth = "default";
  1038. $.cookie("verto_demo_outgoingBandwidth", outgoingBandwidth, {
  1039. expires: 365
  1040. });
  1041. }
  1042. });
  1043. //
  1044. incomingBandwidth = $.cookie("verto_demo_incomingBandwidth") || "default";
  1045. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1046. expires: 365
  1047. });
  1048. $("#incomingBandwidth_250kb").prop("checked", incomingBandwidth === "250").change(function(e) {
  1049. if ($("#incomingBandwidth_250kb").is(':checked')) {
  1050. incomingBandwidth = "250";
  1051. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1052. expires: 365
  1053. });
  1054. }
  1055. });
  1056. $("#incomingBandwidth_500kb").prop("checked", incomingBandwidth === "500").change(function(e) {
  1057. if ($("#incomingBandwidth_500kb").is(':checked')) {
  1058. incomingBandwidth = "500";
  1059. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1060. expires: 365
  1061. });
  1062. }
  1063. });
  1064. $("#incomingBandwidth_1024kb").prop("checked", incomingBandwidth === "1024").change(function(e) {
  1065. if ($("#incomingBandwidth_1024kb").is(':checked')) {
  1066. incomingBandwidth = "1024";
  1067. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1068. expires: 365
  1069. });
  1070. }
  1071. });
  1072. $("#incomingBandwidth_1536kb").prop("checked", incomingBandwidth === "1536").change(function(e) {
  1073. if ($("#incomingBandwidth_1536kb").is(':checked')) {
  1074. incomingBandwidth = "1536";
  1075. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1076. expires: 365
  1077. });
  1078. }
  1079. });
  1080. $("#incomingBandwidth_2048kb").prop("checked", incomingBandwidth === "2048").change(function(e) {
  1081. if ($("#incomingBandwidth_2048kb").is(':checked')) {
  1082. incomingBandwidth = "2048";
  1083. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1084. expires: 365
  1085. });
  1086. }
  1087. });
  1088. $("#incomingBandwidth_5120kb").prop("checked", incomingBandwidth === "5120").change(function(e) {
  1089. if ($("#incomingBandwidth_5120kb").is(':checked')) {
  1090. incomingBandwidth = "5120";
  1091. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1092. expires: 365
  1093. });
  1094. }
  1095. });
  1096. $("#incomingBandwidth_0kb").prop("checked", incomingBandwidth === "0").change(function(e) {
  1097. if ($("#incomingBandwidth_0kb").is(':checked')) {
  1098. incomingBandwidth = "0";
  1099. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1100. expires: 365
  1101. });
  1102. }
  1103. });
  1104. $("#incomingBandwidth_default").prop("checked", incomingBandwidth === "default").change(function(e) {
  1105. if ($("#incomingBandwidth_default").is(':checked')) {
  1106. incomingBandwidth = "default";
  1107. $.cookie("verto_demo_incomingBandwidth", incomingBandwidth, {
  1108. expires: 365
  1109. });
  1110. }
  1111. });
  1112. //
  1113. vqual = $.cookie("verto_demo_vqual") || "hd";
  1114. $.cookie("verto_demo_vqual", vqual, {
  1115. expires: 365
  1116. });
  1117. $("#vqual_qqvga").prop("checked", vqual === "qqvga").change(function(e) {
  1118. if ($("#vqual_qqvga").is(':checked')) {
  1119. vqual = "qqvga";
  1120. $.cookie("verto_demo_vqual", vqual, {
  1121. expires: 365
  1122. });
  1123. }
  1124. });
  1125. $("#vqual_qvga").prop("checked", vqual === "qvga").change(function(e) {
  1126. if ($("#vqual_qvga").is(':checked')) {
  1127. vqual = "qvga";
  1128. $.cookie("verto_demo_vqual", vqual, {
  1129. expires: 365
  1130. });
  1131. }
  1132. });
  1133. $("#vqual_vga").prop("checked", vqual === "vga").change(function(e) {
  1134. if ($("#vqual_vga").is(':checked')) {
  1135. vqual = "vga";
  1136. $.cookie("verto_demo_vqual", vqual, {
  1137. expires: 365
  1138. });
  1139. }
  1140. });
  1141. $("#vqual_qvga_wide").prop("checked", vqual === "qvga_wide").change(function(e) {
  1142. if ($("#vqual_qvga_wide").is(':checked')) {
  1143. vqual = "qvga_wide";
  1144. $.cookie("verto_demo_vqual", vqual, {
  1145. expires: 365
  1146. });
  1147. }
  1148. });
  1149. $("#vqual_vga_wide").prop("checked", vqual === "vga_wide").change(function(e) {
  1150. if ($("#vqual_vga_wide").is(':checked')) {
  1151. vqual = "vga_wide";
  1152. $.cookie("verto_demo_vqual", vqual, {
  1153. expires: 365
  1154. });
  1155. }
  1156. });
  1157. $("#vqual_hd").prop("checked", vqual === "hd").change(function(e) {
  1158. if ($("#vqual_hd").is(':checked')) {
  1159. vqual = "hd";
  1160. $.cookie("verto_demo_vqual", vqual, {
  1161. expires: 365
  1162. });
  1163. }
  1164. });
  1165. $("#vqual_hhd").prop("checked", vqual === "hhd").change(function(e) {
  1166. if ($("#vqual_hhd").is(':checked')) {
  1167. vqual = "hhd";
  1168. $.cookie("verto_demo_vqual", vqual, {
  1169. expires: 365
  1170. });
  1171. }
  1172. });
  1173. tmp = $.cookie("verto_demo_stereo_checked") || "true";
  1174. $.cookie("verto_demo_stereo_checked", tmp, {
  1175. expires: 365
  1176. });
  1177. $("#use_stereo").prop("checked", tmp === "true").change(function(e) {
  1178. tmp = $("#use_stereo").is(':checked');
  1179. $.cookie("verto_demo_stereo_checked", tmp ? "true" : "false", {
  1180. expires: 365
  1181. });
  1182. });
  1183. tmp = $.cookie("verto_demo_stun_checked") || "true";
  1184. $.cookie("verto_demo_stun_checked", tmp, {
  1185. expires: 365
  1186. });
  1187. $("#use_stun").prop("checked", tmp === "true").change(function(e) {
  1188. tmp = $("#use_stun").is(':checked');
  1189. $.cookie("verto_demo_stun_checked", tmp ? "true" : "false", {
  1190. expires: 365
  1191. });
  1192. if (vertoHandle) {
  1193. vertoHandle.iceServers(tmp);
  1194. }
  1195. });
  1196. tmp = $.cookie("verto_demo_local_video_checked") || "false";
  1197. $.cookie("verto_demo_local_video_checked", tmp, {
  1198. expires: 365
  1199. });
  1200. $("#local_video").prop("checked", tmp === "true").change(function(e) {
  1201. tmp = $("#local_video").is(':checked');
  1202. $.cookie("verto_demo_local_video_checked", tmp ? "true" : "false", {
  1203. expires: 365
  1204. });
  1205. });
  1206. check_vid_res();
  1207. refresh_devices();
  1208. //console.error($("#usecamera").find(":selected"));
  1209. vertoHandle = new $.verto({
  1210. login: $("#login").val() + "@" + $("#hostName").val(),
  1211. passwd: $("#passwd").val(),
  1212. socketUrl: $("#wsURL").val(),
  1213. tag: video_screen,
  1214. //localTag: $("#local_video").is(':checked') ? "local_webcam" : null,
  1215. ringFile: "sounds/bell_ring2.wav",
  1216. sessid: sessid,
  1217. videoParams: {
  1218. "minWidth": vid_width,
  1219. "minHeight": vid_height,
  1220. "maxWidth": vid_width,
  1221. "maxHeight": vid_height,
  1222. "minFrameRate": 15,
  1223. "vertoBestFrameRate": 30
  1224. },
  1225. deviceParams: {
  1226. useCamera: $("#usecamera").find(":selected").val(), useMic: $("#usemic").find(":selected").val(),
  1227. useSpeak: $("#usespeak").find(":selected").val()
  1228. },
  1229. audioParams: {
  1230. googAutoGainControl: false,
  1231. googNoiseSuppression: false,
  1232. googHighpassFilter: false
  1233. },
  1234. iceServers: $("#use_stun").is(':checked')
  1235. },callbacks);
  1236. function handleEmailResponse(resp) {
  1237. for (var i=0; i < resp.emails.length; i++) {
  1238. if (resp.emails[i].type === 'account' && resp.emails[i].value) {
  1239. $("#email").val(resp.emails[i].value);
  1240. $("#email").change();
  1241. $("#cid").val(resp.emails[i].value);
  1242. $("#cid").change();
  1243. }
  1244. }
  1245. if (resp.displayName) {
  1246. $("#cidname").val(resp.displayName);
  1247. $("#cidname").trigger("change");
  1248. }
  1249. $("#avatar").val(resp.image.url + "0");
  1250. $("#avatar").trigger("change");
  1251. gapi.auth.signOut();
  1252. }
  1253. $("#signinButton").click(function() {
  1254. gapi.auth.signIn({callback: function(authResult) {
  1255. console.log('Sign-in state: ' + authResult['error']);
  1256. if (authResult['status']['signed_in']) {
  1257. // Update the app to reflect a signed in user
  1258. // Hide the sign-in button now that the user is authorized, for example:
  1259. //document.getElementById('signinButton').setAttribute('style', 'display: none');
  1260. gapi.client.load('plus','v1', function(){
  1261. var request = gapi.client.plus.people.get({userId: 'me'}).execute(handleEmailResponse);
  1262. });
  1263. } else {
  1264. // Update the app to reflect a signed out user
  1265. // Possible error values:
  1266. // "user_signed_out" - User is signed-out
  1267. // "access_denied" - User denied access to your app
  1268. // "immediate_failed" - Could not automatically log in the user
  1269. console.log('Sign-in state: ' + authResult['error']);
  1270. }
  1271. }});
  1272. });
  1273. $("#login").change(function(e) {
  1274. $("#cid").val(e.currentTarget.value);
  1275. $.cookie("verto_demo_cid", e.currentTarget.value, {
  1276. expires: 365
  1277. });
  1278. });
  1279. $("#vtxtbtn").click(function() {
  1280. vertoHandle.message({
  1281. to: $("#textto").val(),
  1282. body: $("#textmsg").val()
  1283. });
  1284. $("#textmsg").val("");
  1285. });
  1286. $("#logoutbtn").click(function() {
  1287. vertoHandle.logout();
  1288. online(false);
  1289. $("#errordisplay").html("");
  1290. });
  1291. $("#speedbtn").click(function() {
  1292. do_speed_test(function() {
  1293. goto_page("main");
  1294. });
  1295. $("#errordisplay").html("");
  1296. });
  1297. $("#loginbtn").click(function() {
  1298. online(false);
  1299. vertoHandle.loginData({
  1300. login: $("#login").val() + "@" + $("#hostName").val(),
  1301. passwd: $("#passwd").val()
  1302. });
  1303. vertoHandle.login();
  1304. goto_page("main");
  1305. });
  1306. $("#xferdiv").hide();
  1307. // $("#" + video_screen).hide();
  1308. online(false);
  1309. setupChat();
  1310. $("#ext").keyup(function (event) {
  1311. if (event.keyCode == 13) {
  1312. $( "#callbtn" ).trigger( "click" );
  1313. }
  1314. });
  1315. $(document).keypress(function(event) {
  1316. if (!(cur_call && event.target.id == "page-incall")) return;
  1317. var key = String.fromCharCode(event.keyCode);
  1318. var i = parseInt(key);
  1319. if (key === "#" || key === "*" || key === "0" || (i > 0 && i <= 9)) {
  1320. cur_call.dtmf(key);
  1321. }
  1322. });
  1323. if (window.location.hostname !== "webrtc.freeswitch.org") {
  1324. $("#directory").hide();
  1325. }
  1326. }
  1327. $(window).load(function() {
  1328. var hash = window.location.hash.substring(1);
  1329. var a = [];
  1330. var vars = [];
  1331. if (hash && hash.indexOf("page-") == -1) {
  1332. window.location.hash = "";
  1333. if (vars = hash.split("&")) {
  1334. for (var i in vars) {
  1335. var v = vars[i];
  1336. if (a = v.split("=")) {
  1337. var v_name = a[0];
  1338. var v_val = a[1];
  1339. if (v_name === "sessid") {
  1340. sessid = v_val;
  1341. if (sessid === "random") {
  1342. sessid = $.verto.genUUID();
  1343. }
  1344. save_settings = false;
  1345. $.verto.warnOnUnload = "WARNING: DO NOT RELOAD THIS PAGE! Please Close it Instead\n";
  1346. $.verto.unloadJobs.push(function() {
  1347. exit_full_screen();
  1348. vertoHandle.hangup();
  1349. cur_call = null;
  1350. });
  1351. } else if (v_name === "master") {
  1352. master = v_val;
  1353. } else if (v_name === "canvas_id") {
  1354. canvas_id = v_val;
  1355. } else if (v_name === "autocall") {
  1356. $("#ext").val(v_val);
  1357. autocall = true;
  1358. }
  1359. }
  1360. }
  1361. }
  1362. }
  1363. //if (hash && (a = hash.split("&"))) {
  1364. // window.location.hash = a[0];
  1365. // }
  1366. $("#" + video_screen).hide();
  1367. $("#camdiv").hide();
  1368. $('#demos').hide();
  1369. $('#devices').hide();
  1370. $('#showdemo').show();
  1371. // $("#rows").css("position", "absolute").css("z-index", "2");
  1372. //$("#usrctl").show();
  1373. //$("#usr2").hide();
  1374. $("#usrctl").hide();
  1375. $("#rows").mouseover(function() {
  1376. $("#usr2").show();
  1377. });
  1378. $("#usr2").mouseover(function() {
  1379. clearTimeout(usrto);
  1380. });
  1381. $("#usr2").mouseleave(function() {
  1382. if (is_full) {
  1383. usrto = setTimeout(function() { $("#usr2").hide(); }, 2000);
  1384. }
  1385. });
  1386. $("#search").show();
  1387. goto_page("enum");
  1388. setTimeout(function() {
  1389. $.verto.init({skipPermCheck: false}, init);
  1390. }, 1000);
  1391. });
  1392. var lastTo = 0;
  1393. $(document).bind("pagecontainerchange", function(e, data) {
  1394. if (lastTo) {
  1395. clearTimeout(lastTo);
  1396. }
  1397. switch (window.location.hash) {
  1398. case "#page-incall":
  1399. lastTo = setTimeout(function() {
  1400. if (!cur_call) {
  1401. goto_page("main");
  1402. }
  1403. }, 1000);
  1404. break;
  1405. case "#page-main":
  1406. if (cur_call) {
  1407. goto_page("incall");
  1408. }
  1409. break;
  1410. case "#page-login":
  1411. lastTo = setTimeout(function() {
  1412. if (online_visible) {
  1413. goto_page("main");
  1414. }
  1415. },
  1416. 1000);
  1417. break;
  1418. }
  1419. });