You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 45KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. /* jshint -W117 */
  2. /* application specific logic */
  3. var connection = null;
  4. var authenticatedUser = false;
  5. var focus = null;
  6. var activecall = null;
  7. var RTC = null;
  8. var nickname = null;
  9. var sharedKey = '';
  10. var recordingToken ='';
  11. var roomUrl = null;
  12. var roomName = null;
  13. var ssrc2jid = {};
  14. var mediaStreams = [];
  15. /**
  16. * The stats collector that process stats data and triggers updates to app.js.
  17. * @type {StatsCollector}
  18. */
  19. var statsCollector = null;
  20. /**
  21. * The stats collector for the local stream.
  22. * @type {LocalStatsCollector}
  23. */
  24. var localStatsCollector = null;
  25. /**
  26. * Indicates whether ssrc is camera video or desktop stream.
  27. * FIXME: remove those maps
  28. */
  29. var ssrc2videoType = {};
  30. var videoSrcToSsrc = {};
  31. /**
  32. * Currently focused video "src"(displayed in large video).
  33. * @type {String}
  34. */
  35. var focusedVideoSrc = null;
  36. var mutedAudios = {};
  37. var localVideoSrc = null;
  38. var flipXLocalVideo = true;
  39. var isFullScreen = false;
  40. var toolbarTimeout = null;
  41. var currentVideoWidth = null;
  42. var currentVideoHeight = null;
  43. /**
  44. * Method used to calculate large video size.
  45. * @type {function ()}
  46. */
  47. var getVideoSize;
  48. /**
  49. * Method used to get large video position.
  50. * @type {function ()}
  51. */
  52. var getVideoPosition;
  53. /* window.onbeforeunload = closePageWarning; */
  54. var sessionTerminated = false;
  55. function init() {
  56. RTC = setupRTC();
  57. if (RTC === null) {
  58. window.location.href = 'webrtcrequired.html';
  59. return;
  60. } else if (RTC.browser !== 'chrome') {
  61. window.location.href = 'chromeonly.html';
  62. return;
  63. }
  64. obtainAudioAndVideoPermissions(function (stream) {
  65. var audioStream = new webkitMediaStream();
  66. var videoStream = new webkitMediaStream();
  67. var audioTracks = stream.getAudioTracks();
  68. var videoTracks = stream.getVideoTracks();
  69. for (var i = 0; i < audioTracks.length; i++) {
  70. audioStream.addTrack(audioTracks[i]);
  71. }
  72. VideoLayout.changeLocalAudio(audioStream);
  73. startLocalRtpStatsCollector(audioStream);
  74. for (i = 0; i < videoTracks.length; i++) {
  75. videoStream.addTrack(videoTracks[i]);
  76. }
  77. VideoLayout.changeLocalVideo(videoStream, true);
  78. maybeDoJoin();
  79. });
  80. var jid = document.getElementById('jid').value || config.hosts.anonymousdomain || config.hosts.domain || window.location.hostname;
  81. connect(jid);
  82. }
  83. function connect(jid, password) {
  84. var localAudio, localVideo;
  85. if (connection && connection.jingle) {
  86. localAudio = connection.jingle.localAudio;
  87. localVideo = connection.jingle.localVideo;
  88. }
  89. connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
  90. if (nickname) {
  91. connection.emuc.addDisplayNameToPresence(nickname);
  92. }
  93. if (connection.disco) {
  94. // for chrome, add multistream cap
  95. }
  96. connection.jingle.pc_constraints = RTC.pc_constraints;
  97. if (config.useIPv6) {
  98. // https://code.google.com/p/webrtc/issues/detail?id=2828
  99. if (!connection.jingle.pc_constraints.optional) connection.jingle.pc_constraints.optional = [];
  100. connection.jingle.pc_constraints.optional.push({googIPv6: true});
  101. }
  102. if (localAudio) connection.jingle.localAudio = localAudio;
  103. if (localVideo) connection.jingle.localVideo = localVideo;
  104. if(!password)
  105. password = document.getElementById('password').value;
  106. var anonymousConnectionFailed = false;
  107. connection.connect(jid, password, function (status, msg) {
  108. if (status === Strophe.Status.CONNECTED) {
  109. console.log('connected');
  110. if (config.useStunTurn) {
  111. connection.jingle.getStunAndTurnCredentials();
  112. }
  113. document.getElementById('connect').disabled = true;
  114. if(password)
  115. authenticatedUser = true;
  116. maybeDoJoin();
  117. } else if (status === Strophe.Status.CONNFAIL) {
  118. if(msg === 'x-strophe-bad-non-anon-jid') {
  119. anonymousConnectionFailed = true;
  120. }
  121. console.log('status', status);
  122. } else if (status === Strophe.Status.DISCONNECTED) {
  123. if(anonymousConnectionFailed) {
  124. // prompt user for username and password
  125. $(document).trigger('passwordrequired.main');
  126. }
  127. } else if (status === Strophe.Status.AUTHFAIL) {
  128. // wrong password or username, prompt user
  129. $(document).trigger('passwordrequired.main');
  130. } else {
  131. console.log('status', status);
  132. }
  133. });
  134. }
  135. /**
  136. * We ask for audio and video combined stream in order to get permissions and
  137. * not to ask twice.
  138. */
  139. function obtainAudioAndVideoPermissions(callback) {
  140. // Get AV
  141. getUserMediaWithConstraints(
  142. ['audio', 'video'],
  143. function (avStream) {
  144. callback(avStream);
  145. },
  146. function (error) {
  147. console.error('failed to obtain audio/video stream - stop', error);
  148. },
  149. config.resolution || '360');
  150. }
  151. function maybeDoJoin() {
  152. if (connection && connection.connected && Strophe.getResourceFromJid(connection.jid) // .connected is true while connecting?
  153. && (connection.jingle.localAudio || connection.jingle.localVideo)) {
  154. doJoin();
  155. }
  156. }
  157. function doJoin() {
  158. var roomnode = null;
  159. var path = window.location.pathname;
  160. var roomjid;
  161. // determinde the room node from the url
  162. // TODO: just the roomnode or the whole bare jid?
  163. if (config.getroomnode && typeof config.getroomnode === 'function') {
  164. // custom function might be responsible for doing the pushstate
  165. roomnode = config.getroomnode(path);
  166. } else {
  167. /* fall back to default strategy
  168. * this is making assumptions about how the URL->room mapping happens.
  169. * It currently assumes deployment at root, with a rewrite like the
  170. * following one (for nginx):
  171. location ~ ^/([a-zA-Z0-9]+)$ {
  172. rewrite ^/(.*)$ / break;
  173. }
  174. */
  175. if (path.length > 1) {
  176. roomnode = path.substr(1).toLowerCase();
  177. } else {
  178. var word = RoomNameGenerator.generateRoomWithoutSeparator(3);
  179. roomnode = word.toLowerCase();
  180. window.history.pushState('VideoChat',
  181. 'Room: ' + word, window.location.pathname + word);
  182. }
  183. }
  184. roomName = roomnode + '@' + config.hosts.muc;
  185. roomjid = roomName;
  186. if (config.useNicks) {
  187. var nick = window.prompt('Your nickname (optional)');
  188. if (nick) {
  189. roomjid += '/' + nick;
  190. } else {
  191. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  192. }
  193. } else {
  194. var tmpJid = Strophe.getNodeFromJid(connection.jid);
  195. if(!authenticatedUser)
  196. tmpJid = tmpJid.substr(0, 8);
  197. roomjid += '/' + tmpJid;
  198. }
  199. connection.emuc.doJoin(roomjid);
  200. }
  201. function waitForRemoteVideo(selector, ssrc, stream) {
  202. if (selector.removed || !selector.parent().is(":visible")) {
  203. console.warn("Media removed before had started", selector);
  204. return;
  205. }
  206. if (stream.id === 'mixedmslabel') return;
  207. if (selector[0].currentTime > 0) {
  208. var simulcast = new Simulcast();
  209. var videoStream = simulcast.getReceivingVideoStream(stream);
  210. RTC.attachMediaStream(selector, videoStream); // FIXME: why do i have to do this for FF?
  211. // FIXME: add a class that will associate peer Jid, video.src, it's ssrc and video type
  212. // in order to get rid of too many maps
  213. if (ssrc && selector.attr('src')) {
  214. videoSrcToSsrc[selector.attr('src')] = ssrc;
  215. } else {
  216. console.warn("No ssrc given for video", selector);
  217. }
  218. $(document).trigger('videoactive.jingle', [selector]);
  219. } else {
  220. setTimeout(function () {
  221. waitForRemoteVideo(selector, ssrc, stream);
  222. }, 250);
  223. }
  224. }
  225. $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
  226. waitForPresence(data, sid);
  227. });
  228. function waitForPresence(data, sid) {
  229. var sess = connection.jingle.sessions[sid];
  230. var thessrc;
  231. // look up an associated JID for a stream id
  232. if (data.stream.id.indexOf('mixedmslabel') === -1) {
  233. // look only at a=ssrc: and _not_ at a=ssrc-group: lines
  234. var ssrclines
  235. = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc:');
  236. ssrclines = ssrclines.filter(function (line) {
  237. return line.indexOf('mslabel:' + data.stream.label) !== -1;
  238. });
  239. if (ssrclines.length) {
  240. thessrc = ssrclines[0].substring(7).split(' ')[0];
  241. // We signal our streams (through Jingle to the focus) before we set
  242. // our presence (through which peers associate remote streams to
  243. // jids). So, it might arrive that a remote stream is added but
  244. // ssrc2jid is not yet updated and thus data.peerjid cannot be
  245. // successfully set. Here we wait for up to a second for the
  246. // presence to arrive.
  247. if (!ssrc2jid[thessrc]) {
  248. setTimeout(function(d, s) {
  249. return function() {
  250. waitForPresence(d, s);
  251. }
  252. }(data, sid), 250);
  253. return;
  254. }
  255. // ok to overwrite the one from focus? might save work in colibri.js
  256. console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
  257. if (ssrc2jid[thessrc]) {
  258. data.peerjid = ssrc2jid[thessrc];
  259. }
  260. }
  261. }
  262. // NOTE(gp) now that we have simulcast, a media stream can have more than 1
  263. // ssrc. We should probably take that into account in our MediaStream
  264. // wrapper.
  265. mediaStreams.push(new MediaStream(data, sid, thessrc));
  266. var container;
  267. var remotes = document.getElementById('remoteVideos');
  268. if (data.peerjid) {
  269. VideoLayout.ensurePeerContainerExists(data.peerjid);
  270. container = document.getElementById(
  271. 'participant_' + Strophe.getResourceFromJid(data.peerjid));
  272. } else {
  273. if (data.stream.id !== 'mixedmslabel') {
  274. console.error( 'can not associate stream',
  275. data.stream.id,
  276. 'with a participant');
  277. // We don't want to add it here since it will cause troubles
  278. return;
  279. }
  280. // FIXME: for the mixed ms we dont need a video -- currently
  281. container = document.createElement('span');
  282. container.id = 'mixedstream';
  283. container.className = 'videocontainer';
  284. remotes.appendChild(container);
  285. Util.playSoundNotification('userJoined');
  286. }
  287. var isVideo = data.stream.getVideoTracks().length > 0;
  288. if (container) {
  289. VideoLayout.addRemoteStreamElement( container,
  290. sid,
  291. data.stream,
  292. data.peerjid,
  293. thessrc);
  294. }
  295. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  296. if (isVideo &&
  297. data.peerjid && sess.peerjid === data.peerjid &&
  298. data.stream.getVideoTracks().length === 0 &&
  299. connection.jingle.localVideo.getVideoTracks().length > 0) {
  300. //
  301. window.setTimeout(function () {
  302. sendKeyframe(sess.peerconnection);
  303. }, 3000);
  304. }
  305. }
  306. /**
  307. * Returns the JID of the user to whom given <tt>videoSrc</tt> belongs.
  308. * @param videoSrc the video "src" identifier.
  309. * @returns {null | String} the JID of the user to whom given <tt>videoSrc</tt>
  310. * belongs.
  311. */
  312. function getJidFromVideoSrc(videoSrc)
  313. {
  314. if (videoSrc === localVideoSrc)
  315. return connection.emuc.myroomjid;
  316. var ssrc = videoSrcToSsrc[videoSrc];
  317. if (!ssrc)
  318. {
  319. return null;
  320. }
  321. return ssrc2jid[ssrc];
  322. }
  323. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  324. function sendKeyframe(pc) {
  325. console.log('sendkeyframe', pc.iceConnectionState);
  326. if (pc.iceConnectionState !== 'connected') return; // safe...
  327. pc.setRemoteDescription(
  328. pc.remoteDescription,
  329. function () {
  330. pc.createAnswer(
  331. function (modifiedAnswer) {
  332. pc.setLocalDescription(
  333. modifiedAnswer,
  334. function () {
  335. // noop
  336. },
  337. function (error) {
  338. console.log('triggerKeyframe setLocalDescription failed', error);
  339. }
  340. );
  341. },
  342. function (error) {
  343. console.log('triggerKeyframe createAnswer failed', error);
  344. }
  345. );
  346. },
  347. function (error) {
  348. console.log('triggerKeyframe setRemoteDescription failed', error);
  349. }
  350. );
  351. }
  352. // Really mute video, i.e. dont even send black frames
  353. function muteVideo(pc, unmute) {
  354. // FIXME: this probably needs another of those lovely state safeguards...
  355. // which checks for iceconn == connected and sigstate == stable
  356. pc.setRemoteDescription(pc.remoteDescription,
  357. function () {
  358. pc.createAnswer(
  359. function (answer) {
  360. var sdp = new SDP(answer.sdp);
  361. if (sdp.media.length > 1) {
  362. if (unmute)
  363. sdp.media[1] = sdp.media[1].replace('a=recvonly', 'a=sendrecv');
  364. else
  365. sdp.media[1] = sdp.media[1].replace('a=sendrecv', 'a=recvonly');
  366. sdp.raw = sdp.session + sdp.media.join('');
  367. answer.sdp = sdp.raw;
  368. }
  369. pc.setLocalDescription(answer,
  370. function () {
  371. console.log('mute SLD ok');
  372. },
  373. function (error) {
  374. console.log('mute SLD error');
  375. }
  376. );
  377. },
  378. function (error) {
  379. console.log(error);
  380. }
  381. );
  382. },
  383. function (error) {
  384. console.log('muteVideo SRD error');
  385. }
  386. );
  387. }
  388. /**
  389. * Callback for audio levels changed.
  390. * @param jid JID of the user
  391. * @param audioLevel the audio level value
  392. */
  393. function audioLevelUpdated(jid, audioLevel)
  394. {
  395. var resourceJid;
  396. if(jid === LocalStatsCollector.LOCAL_JID)
  397. {
  398. resourceJid = AudioLevels.LOCAL_LEVEL;
  399. if(isAudioMuted())
  400. return;
  401. }
  402. else
  403. {
  404. resourceJid = Strophe.getResourceFromJid(jid);
  405. }
  406. AudioLevels.updateAudioLevel(resourceJid, audioLevel);
  407. }
  408. /**
  409. * Starts the {@link StatsCollector} if the feature is enabled in config.js.
  410. */
  411. function startRtpStatsCollector()
  412. {
  413. stopRTPStatsCollector();
  414. if (config.enableRtpStats)
  415. {
  416. statsCollector = new StatsCollector(
  417. getConferenceHandler().peerconnection, 200, audioLevelUpdated);
  418. statsCollector.start();
  419. }
  420. }
  421. /**
  422. * Stops the {@link StatsCollector}.
  423. */
  424. function stopRTPStatsCollector()
  425. {
  426. if (statsCollector)
  427. {
  428. statsCollector.stop();
  429. statsCollector = null;
  430. }
  431. }
  432. /**
  433. * Starts the {@link LocalStatsCollector} if the feature is enabled in config.js
  434. * @param stream the stream that will be used for collecting statistics.
  435. */
  436. function startLocalRtpStatsCollector(stream)
  437. {
  438. if(config.enableRtpStats)
  439. {
  440. localStatsCollector = new LocalStatsCollector(stream, 100, audioLevelUpdated);
  441. localStatsCollector.start();
  442. }
  443. }
  444. /**
  445. * Stops the {@link LocalStatsCollector}.
  446. */
  447. function stopLocalRtpStatsCollector()
  448. {
  449. if(localStatsCollector)
  450. {
  451. localStatsCollector.stop();
  452. localStatsCollector = null;
  453. }
  454. }
  455. $(document).bind('callincoming.jingle', function (event, sid) {
  456. var sess = connection.jingle.sessions[sid];
  457. // TODO: do we check activecall == null?
  458. activecall = sess;
  459. startRtpStatsCollector();
  460. // Bind data channel listener in case we're a regular participant
  461. if (config.openSctp)
  462. {
  463. bindDataChannelListener(sess.peerconnection);
  464. }
  465. // TODO: check affiliation and/or role
  466. console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
  467. sess.usedrip = true; // not-so-naive trickle ice
  468. sess.sendAnswer();
  469. sess.accept();
  470. });
  471. $(document).bind('conferenceCreated.jingle', function (event, focus)
  472. {
  473. startRtpStatsCollector();
  474. });
  475. $(document).bind('conferenceCreated.jingle', function (event, focus)
  476. {
  477. // Bind data channel listener in case we're the focus
  478. if (config.openSctp)
  479. {
  480. bindDataChannelListener(focus.peerconnection);
  481. }
  482. });
  483. $(document).bind('callterminated.jingle', function (event, sid, jid, reason) {
  484. // Leave the room if my call has been remotely terminated.
  485. if (connection.emuc.joined && focus == null && reason === 'kick') {
  486. sessionTerminated = true;
  487. connection.emuc.doLeave();
  488. openMessageDialog( "Session Terminated",
  489. "Ouch! You have been kicked out of the meet!");
  490. }
  491. });
  492. $(document).bind('setLocalDescription.jingle', function (event, sid) {
  493. // put our ssrcs into presence so other clients can identify our stream
  494. var sess = connection.jingle.sessions[sid];
  495. var newssrcs = [];
  496. var simulcast = new Simulcast();
  497. var media = simulcast.parseMedia(sess.peerconnection.localDescription);
  498. media.forEach(function (media) {
  499. // TODO(gp) maybe exclude FID streams?
  500. Object.keys(media.sources).forEach(function(ssrc) {
  501. newssrcs.push({
  502. 'ssrc': ssrc,
  503. 'type': media.type,
  504. 'direction': media.direction
  505. });
  506. });
  507. });
  508. console.log('new ssrcs', newssrcs);
  509. // Have to clear presence map to get rid of removed streams
  510. connection.emuc.clearPresenceMedia();
  511. if (newssrcs.length > 0) {
  512. for (var i = 1; i <= newssrcs.length; i ++) {
  513. // Change video type to screen
  514. if (newssrcs[i-1].type === 'video' && isUsingScreenStream) {
  515. newssrcs[i-1].type = 'screen';
  516. }
  517. connection.emuc.addMediaToPresence(i,
  518. newssrcs[i-1].type, newssrcs[i-1].ssrc, newssrcs[i-1].direction);
  519. }
  520. connection.emuc.sendPresence();
  521. }
  522. });
  523. $(document).bind('joined.muc', function (event, jid, info) {
  524. updateRoomUrl(window.location.href);
  525. document.getElementById('localNick').appendChild(
  526. document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
  527. );
  528. if (Object.keys(connection.emuc.members).length < 1) {
  529. focus = new ColibriFocus(connection, config.hosts.bridge);
  530. if (nickname !== null) {
  531. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  532. nickname);
  533. }
  534. Toolbar.showSipCallButton(true);
  535. Toolbar.showRecordingButton(false);
  536. }
  537. if (!focus)
  538. {
  539. Toolbar.showSipCallButton(false);
  540. }
  541. if (focus && config.etherpad_base) {
  542. Etherpad.init();
  543. }
  544. VideoLayout.showFocusIndicator();
  545. // Add myself to the contact list.
  546. ContactList.addContact(jid);
  547. // Once we've joined the muc show the toolbar
  548. ToolbarToggler.showToolbar();
  549. if (info.displayName)
  550. $(document).trigger('displaynamechanged',
  551. ['localVideoContainer', info.displayName + ' (me)']);
  552. });
  553. $(document).bind('entered.muc', function (event, jid, info, pres) {
  554. console.log('entered', jid, info);
  555. console.log('is focus? ' + (focus ? 'true' : 'false'));
  556. // Add Peer's container
  557. VideoLayout.ensurePeerContainerExists(jid);
  558. if (focus !== null) {
  559. // FIXME: this should prepare the video
  560. if (focus.confid === null) {
  561. console.log('make new conference with', jid);
  562. focus.makeConference(Object.keys(connection.emuc.members));
  563. Toolbar.showRecordingButton(true);
  564. } else {
  565. console.log('invite', jid, 'into conference');
  566. focus.addNewParticipant(jid);
  567. }
  568. }
  569. else if (sharedKey) {
  570. Toolbar.updateLockButton();
  571. }
  572. });
  573. $(document).bind('left.muc', function (event, jid) {
  574. console.log('left.muc', jid);
  575. // Need to call this with a slight delay, otherwise the element couldn't be
  576. // found for some reason.
  577. window.setTimeout(function () {
  578. var container = document.getElementById(
  579. 'participant_' + Strophe.getResourceFromJid(jid));
  580. if (container) {
  581. // hide here, wait for video to close before removing
  582. $(container).hide();
  583. VideoLayout.resizeThumbnails();
  584. }
  585. }, 10);
  586. // Unlock large video
  587. if (focusedVideoSrc)
  588. {
  589. if (getJidFromVideoSrc(focusedVideoSrc) === jid)
  590. {
  591. console.info("Focused video owner has left the conference");
  592. focusedVideoSrc = null;
  593. }
  594. }
  595. connection.jingle.terminateByJid(jid);
  596. if (focus == null
  597. // I shouldn't be the one that left to enter here.
  598. && jid !== connection.emuc.myroomjid
  599. && connection.emuc.myroomjid === connection.emuc.list_members[0]
  600. // If our session has been terminated for some reason
  601. // (kicked, hangup), don't try to become the focus
  602. && !sessionTerminated) {
  603. console.log('welcome to our new focus... myself');
  604. focus = new ColibriFocus(connection, config.hosts.bridge);
  605. if (nickname !== null) {
  606. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  607. nickname);
  608. }
  609. Toolbar.showSipCallButton(true);
  610. if (Object.keys(connection.emuc.members).length > 0) {
  611. focus.makeConference(Object.keys(connection.emuc.members));
  612. Toolbar.showRecordingButton(true);
  613. }
  614. $(document).trigger('focusechanged.muc', [focus]);
  615. }
  616. else if (focus && Object.keys(connection.emuc.members).length === 0) {
  617. console.log('everyone left');
  618. // FIXME: closing the connection is a hack to avoid some
  619. // problems with reinit
  620. disposeConference();
  621. focus = new ColibriFocus(connection, config.hosts.bridge);
  622. if (nickname !== null) {
  623. focus.setEndpointDisplayName(connection.emuc.myroomjid,
  624. nickname);
  625. }
  626. Toolbar.showSipCallButton(true);
  627. Toolbar.showRecordingButton(false);
  628. }
  629. if (connection.emuc.getPrezi(jid)) {
  630. $(document).trigger('presentationremoved.muc',
  631. [jid, connection.emuc.getPrezi(jid)]);
  632. }
  633. });
  634. $(document).bind('presence.muc', function (event, jid, info, pres) {
  635. // Remove old ssrcs coming from the jid
  636. Object.keys(ssrc2jid).forEach(function (ssrc) {
  637. if (ssrc2jid[ssrc] == jid) {
  638. delete ssrc2jid[ssrc];
  639. }
  640. if (ssrc2videoType[ssrc] == jid) {
  641. delete ssrc2videoType[ssrc];
  642. }
  643. });
  644. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  645. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  646. var ssrcV = ssrc.getAttribute('ssrc');
  647. ssrc2jid[ssrcV] = jid;
  648. var type = ssrc.getAttribute('type');
  649. ssrc2videoType[ssrcV] = type;
  650. // might need to update the direction if participant just went from sendrecv to recvonly
  651. if (type === 'video' || type === 'screen') {
  652. var el = $('#participant_' + Strophe.getResourceFromJid(jid) + '>video');
  653. switch (ssrc.getAttribute('direction')) {
  654. case 'sendrecv':
  655. el.show();
  656. break;
  657. case 'recvonly':
  658. el.hide();
  659. // FIXME: Check if we have to change large video
  660. //VideoLayout.updateLargeVideo(el);
  661. break;
  662. }
  663. }
  664. });
  665. if (info.displayName && info.displayName.length > 0)
  666. $(document).trigger('displaynamechanged',
  667. [jid, info.displayName]);
  668. if (focus !== null && info.displayName !== null) {
  669. focus.setEndpointDisplayName(jid, info.displayName);
  670. }
  671. });
  672. $(document).bind('presence.status.muc', function (event, jid, info, pres) {
  673. VideoLayout.setPresenceStatus(
  674. 'participant_' + Strophe.getResourceFromJid(jid), info.status);
  675. });
  676. $(document).bind('passwordrequired.muc', function (event, jid) {
  677. console.log('on password required', jid);
  678. $.prompt('<h2>Password required</h2>' +
  679. '<input id="lockKey" type="text" placeholder="shared key" autofocus>', {
  680. persistent: true,
  681. buttons: { "Ok": true, "Cancel": false},
  682. defaultButton: 1,
  683. loaded: function (event) {
  684. document.getElementById('lockKey').focus();
  685. },
  686. submit: function (e, v, m, f) {
  687. if (v) {
  688. var lockKey = document.getElementById('lockKey');
  689. if (lockKey.value !== null) {
  690. setSharedKey(lockKey.value);
  691. connection.emuc.doJoin(jid, lockKey.value);
  692. }
  693. }
  694. }
  695. });
  696. });
  697. $(document).bind('passwordrequired.main', function (event) {
  698. console.log('password is required');
  699. $.prompt('<h2>Password required</h2>' +
  700. '<input id="passwordrequired.username" type="text" placeholder="user@domain.net" autofocus>' +
  701. '<input id="passwordrequired.password" type="password" placeholder="user password">', {
  702. persistent: true,
  703. buttons: { "Ok": true, "Cancel": false},
  704. defaultButton: 1,
  705. loaded: function (event) {
  706. document.getElementById('passwordrequired.username').focus();
  707. },
  708. submit: function (e, v, m, f) {
  709. if (v) {
  710. var username = document.getElementById('passwordrequired.username');
  711. var password = document.getElementById('passwordrequired.password');
  712. if (username.value !== null && password.value != null) {
  713. connect(username.value, password.value);
  714. }
  715. }
  716. }
  717. });
  718. });
  719. /**
  720. * Checks if video identified by given src is desktop stream.
  721. * @param videoSrc eg.
  722. * blob:https%3A//pawel.jitsi.net/9a46e0bd-131e-4d18-9c14-a9264e8db395
  723. * @returns {boolean}
  724. */
  725. function isVideoSrcDesktop(videoSrc) {
  726. // FIXME: fix this mapping mess...
  727. // figure out if large video is desktop stream or just a camera
  728. var isDesktop = false;
  729. if (localVideoSrc === videoSrc) {
  730. // local video
  731. isDesktop = isUsingScreenStream;
  732. } else {
  733. // Do we have associations...
  734. var videoSsrc = videoSrcToSsrc[videoSrc];
  735. if (videoSsrc) {
  736. var videoType = ssrc2videoType[videoSsrc];
  737. if (videoType) {
  738. // Finally there...
  739. isDesktop = videoType === 'screen';
  740. } else {
  741. console.error("No video type for ssrc: " + videoSsrc);
  742. }
  743. } else {
  744. console.error("No ssrc for src: " + videoSrc);
  745. }
  746. }
  747. return isDesktop;
  748. }
  749. function getConferenceHandler() {
  750. return focus ? focus : activecall;
  751. }
  752. function toggleVideo() {
  753. buttonClick("#video", "icon-camera icon-camera-disabled");
  754. if (!(connection && connection.jingle.localVideo))
  755. return;
  756. var sess = getConferenceHandler();
  757. if (sess) {
  758. sess.toggleVideoMute(
  759. function (isMuted) {
  760. if (isMuted) {
  761. $('#video').removeClass("icon-camera");
  762. $('#video').addClass("icon-camera icon-camera-disabled");
  763. } else {
  764. $('#video').removeClass("icon-camera icon-camera-disabled");
  765. $('#video').addClass("icon-camera");
  766. }
  767. }
  768. );
  769. }
  770. sess = focus || activecall;
  771. if (!sess) {
  772. return;
  773. }
  774. sess.pendingop = ismuted ? 'unmute' : 'mute';
  775. // connection.emuc.addVideoInfoToPresence(!ismuted);
  776. // connection.emuc.sendPresence();
  777. sess.modifySources();
  778. }
  779. /**
  780. * Mutes / unmutes audio for the local participant.
  781. */
  782. function toggleAudio() {
  783. if (!(connection && connection.jingle.localAudio)) {
  784. preMuted = true;
  785. // We still click the button.
  786. buttonClick("#mute", "icon-microphone icon-mic-disabled");
  787. return;
  788. }
  789. var localAudio = connection.jingle.localAudio;
  790. for (var idx = 0; idx < localAudio.getAudioTracks().length; idx++) {
  791. var audioEnabled = localAudio.getAudioTracks()[idx].enabled;
  792. localAudio.getAudioTracks()[idx].enabled = !audioEnabled;
  793. // isMuted is the opposite of audioEnabled
  794. connection.emuc.addAudioInfoToPresence(audioEnabled);
  795. connection.emuc.sendPresence();
  796. }
  797. buttonClick("#mute", "icon-microphone icon-mic-disabled");
  798. }
  799. /**
  800. * Checks whether the audio is muted or not.
  801. * @returns {boolean} true if audio is muted and false if not.
  802. */
  803. function isAudioMuted()
  804. {
  805. var localAudio = connection.jingle.localAudio;
  806. for (var idx = 0; idx < localAudio.getAudioTracks().length; idx++) {
  807. if(localAudio.getAudioTracks()[idx].enabled === true)
  808. return false;
  809. }
  810. return true;
  811. }
  812. // Starts or stops the recording for the conference.
  813. function toggleRecording() {
  814. if (focus === null || focus.confid === null) {
  815. console.log('non-focus, or conference not yet organized: not enabling recording');
  816. return;
  817. }
  818. if (!recordingToken)
  819. {
  820. $.prompt('<h2>Enter recording token</h2>' +
  821. '<input id="recordingToken" type="text" placeholder="token" autofocus>',
  822. {
  823. persistent: false,
  824. buttons: { "Save": true, "Cancel": false},
  825. defaultButton: 1,
  826. loaded: function (event) {
  827. document.getElementById('recordingToken').focus();
  828. },
  829. submit: function (e, v, m, f) {
  830. if (v) {
  831. var token = document.getElementById('recordingToken');
  832. if (token.value) {
  833. setRecordingToken(Util.escapeHtml(token.value));
  834. toggleRecording();
  835. }
  836. }
  837. }
  838. }
  839. );
  840. return;
  841. }
  842. var oldState = focus.recordingEnabled;
  843. Toolbar.toggleRecordingButtonState();
  844. focus.setRecording(!oldState,
  845. recordingToken,
  846. function (state) {
  847. console.log("New recording state: ", state);
  848. if (state == oldState) //failed to change, reset the token because it might have been wrong
  849. {
  850. Toolbar.toggleRecordingButtonState();
  851. setRecordingToken(null);
  852. }
  853. }
  854. );
  855. }
  856. /**
  857. * Returns an array of the video horizontal and vertical indents,
  858. * so that if fits its parent.
  859. *
  860. * @return an array with 2 elements, the horizontal indent and the vertical
  861. * indent
  862. */
  863. function getCameraVideoPosition(videoWidth,
  864. videoHeight,
  865. videoSpaceWidth,
  866. videoSpaceHeight) {
  867. // Parent height isn't completely calculated when we position the video in
  868. // full screen mode and this is why we use the screen height in this case.
  869. // Need to think it further at some point and implement it properly.
  870. var isFullScreen = document.fullScreen ||
  871. document.mozFullScreen ||
  872. document.webkitIsFullScreen;
  873. if (isFullScreen)
  874. videoSpaceHeight = window.innerHeight;
  875. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  876. var verticalIndent = (videoSpaceHeight - videoHeight) / 2;
  877. return [horizontalIndent, verticalIndent];
  878. }
  879. /**
  880. * Returns an array of the video horizontal and vertical indents.
  881. * Centers horizontally and top aligns vertically.
  882. *
  883. * @return an array with 2 elements, the horizontal indent and the vertical
  884. * indent
  885. */
  886. function getDesktopVideoPosition(videoWidth,
  887. videoHeight,
  888. videoSpaceWidth,
  889. videoSpaceHeight) {
  890. var horizontalIndent = (videoSpaceWidth - videoWidth) / 2;
  891. var verticalIndent = 0;// Top aligned
  892. return [horizontalIndent, verticalIndent];
  893. }
  894. /**
  895. * Returns an array of the video dimensions, so that it covers the screen.
  896. * It leaves no empty areas, but some parts of the video might not be visible.
  897. *
  898. * @return an array with 2 elements, the video width and the video height
  899. */
  900. function getCameraVideoSize(videoWidth,
  901. videoHeight,
  902. videoSpaceWidth,
  903. videoSpaceHeight) {
  904. if (!videoWidth)
  905. videoWidth = currentVideoWidth;
  906. if (!videoHeight)
  907. videoHeight = currentVideoHeight;
  908. var aspectRatio = videoWidth / videoHeight;
  909. var availableWidth = Math.max(videoWidth, videoSpaceWidth);
  910. var availableHeight = Math.max(videoHeight, videoSpaceHeight);
  911. if (availableWidth / aspectRatio < videoSpaceHeight) {
  912. availableHeight = videoSpaceHeight;
  913. availableWidth = availableHeight * aspectRatio;
  914. }
  915. if (availableHeight * aspectRatio < videoSpaceWidth) {
  916. availableWidth = videoSpaceWidth;
  917. availableHeight = availableWidth / aspectRatio;
  918. }
  919. return [availableWidth, availableHeight];
  920. }
  921. $(document).ready(function () {
  922. document.title = brand.appName;
  923. if(config.enableWelcomePage && window.location.pathname == "/" &&
  924. (!window.localStorage.welcomePageDisabled || window.localStorage.welcomePageDisabled == "false"))
  925. {
  926. $("#videoconference_page").hide();
  927. $("#domain_name").text(window.location.protocol + "//" + window.location.host + "/");
  928. $("span[name='appName']").text(brand.appName);
  929. function enter_room()
  930. {
  931. var val = $("#enter_room_field").val();
  932. if(!val)
  933. val = $("#enter_room_field").attr("room_name");
  934. window.location.pathname = "/" + val;
  935. }
  936. $("#enter_room_button").click(function()
  937. {
  938. enter_room();
  939. });
  940. $("#enter_room_field").keydown(function (event) {
  941. if (event.keyCode === 13) {
  942. enter_room();
  943. }
  944. });
  945. var updateTimeout;
  946. var animateTimeout;
  947. $("#reload_roomname").click(function () {
  948. clearTimeout(updateTimeout);
  949. clearTimeout(animateTimeout);
  950. update_roomname();
  951. });
  952. function animate(word) {
  953. var currentVal = $("#enter_room_field").attr("placeholder");
  954. $("#enter_room_field").attr("placeholder", currentVal + word.substr(0, 1));
  955. animateTimeout = setTimeout(function() {
  956. animate(word.substring(1, word.length))
  957. }, 70);
  958. }
  959. function update_roomname()
  960. {
  961. var word = RoomNameGenerator.generateRoomWithoutSeparator();
  962. $("#enter_room_field").attr("room_name", word);
  963. $("#enter_room_field").attr("placeholder", "");
  964. animate(word);
  965. updateTimeout = setTimeout(update_roomname, 10000);
  966. }
  967. update_roomname();
  968. $("#disable_welcome").click(function () {
  969. window.localStorage.welcomePageDisabled = $("#disable_welcome").is(":checked");
  970. });
  971. return;
  972. }
  973. $("#welcome_page").hide();
  974. Chat.init();
  975. $('body').popover({ selector: '[data-toggle=popover]',
  976. trigger: 'click hover',
  977. content: function() {
  978. return this.getAttribute("content") +
  979. KeyboardShortcut.getShortcut(this.getAttribute("shortcut"));
  980. }
  981. });
  982. // Set the defaults for prompt dialogs.
  983. jQuery.prompt.setDefaults({persistent: false});
  984. // Set default desktop sharing method
  985. setDesktopSharing(config.desktopSharing);
  986. // Initialize Chrome extension inline installs
  987. if (config.chromeExtensionId) {
  988. initInlineInstalls();
  989. }
  990. // By default we use camera
  991. getVideoSize = getCameraVideoSize;
  992. getVideoPosition = getCameraVideoPosition;
  993. VideoLayout.resizeLargeVideoContainer();
  994. $(window).resize(function () {
  995. VideoLayout.resizeLargeVideoContainer();
  996. VideoLayout.positionLarge();
  997. });
  998. // Listen for large video size updates
  999. document.getElementById('largeVideo')
  1000. .addEventListener('loadedmetadata', function (e) {
  1001. currentVideoWidth = this.videoWidth;
  1002. currentVideoHeight = this.videoHeight;
  1003. VideoLayout.positionLarge(currentVideoWidth, currentVideoHeight);
  1004. });
  1005. if (!$('#settings').is(':visible')) {
  1006. console.log('init');
  1007. init();
  1008. } else {
  1009. loginInfo.onsubmit = function (e) {
  1010. if (e.preventDefault) e.preventDefault();
  1011. $('#settings').hide();
  1012. init();
  1013. };
  1014. }
  1015. });
  1016. $(window).bind('beforeunload', function () {
  1017. if (connection && connection.connected) {
  1018. // ensure signout
  1019. $.ajax({
  1020. type: 'POST',
  1021. url: config.bosh,
  1022. async: false,
  1023. cache: false,
  1024. contentType: 'application/xml',
  1025. data: "<body rid='" + (connection.rid || connection._proto.rid) + "' xmlns='http://jabber.org/protocol/httpbind' sid='" + (connection.sid || connection._proto.sid) + "' type='terminate'><presence xmlns='jabber:client' type='unavailable'/></body>",
  1026. success: function (data) {
  1027. console.log('signed out');
  1028. console.log(data);
  1029. },
  1030. error: function (XMLHttpRequest, textStatus, errorThrown) {
  1031. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  1032. }
  1033. });
  1034. }
  1035. disposeConference(true);
  1036. });
  1037. function disposeConference(onUnload) {
  1038. var handler = getConferenceHandler();
  1039. if (handler && handler.peerconnection) {
  1040. // FIXME: probably removing streams is not required and close() should be enough
  1041. if (connection.jingle.localAudio) {
  1042. handler.peerconnection.removeStream(connection.jingle.localAudio);
  1043. }
  1044. if (connection.jingle.localVideo) {
  1045. handler.peerconnection.removeStream(connection.jingle.localVideo);
  1046. }
  1047. handler.peerconnection.close();
  1048. }
  1049. stopRTPStatsCollector();
  1050. if(onUnload) {
  1051. stopLocalRtpStatsCollector();
  1052. }
  1053. focus = null;
  1054. activecall = null;
  1055. }
  1056. function dump(elem, filename) {
  1057. elem = elem.parentNode;
  1058. elem.download = filename || 'meetlog.json';
  1059. elem.href = 'data:application/json;charset=utf-8,\n';
  1060. var data = {};
  1061. if (connection.jingle) {
  1062. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  1063. var session = connection.jingle.sessions[sid];
  1064. if (session.peerconnection && session.peerconnection.updateLog) {
  1065. // FIXME: should probably be a .dump call
  1066. data["jingle_" + session.sid] = {
  1067. updateLog: session.peerconnection.updateLog,
  1068. stats: session.peerconnection.stats,
  1069. url: window.location.href
  1070. };
  1071. }
  1072. });
  1073. }
  1074. metadata = {};
  1075. metadata.time = new Date();
  1076. metadata.url = window.location.href;
  1077. metadata.ua = navigator.userAgent;
  1078. if (connection.logger) {
  1079. metadata.xmpp = connection.logger.log;
  1080. }
  1081. data.metadata = metadata;
  1082. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  1083. return false;
  1084. }
  1085. /**
  1086. * Changes the style class of the element given by id.
  1087. */
  1088. function buttonClick(id, classname) {
  1089. $(id).toggleClass(classname); // add the class to the clicked element
  1090. }
  1091. /**
  1092. * Shows a message to the user.
  1093. *
  1094. * @param titleString the title of the message
  1095. * @param messageString the text of the message
  1096. */
  1097. function openMessageDialog(titleString, messageString) {
  1098. $.prompt(messageString,
  1099. {
  1100. title: titleString,
  1101. persistent: false
  1102. }
  1103. );
  1104. }
  1105. /**
  1106. * Locks / unlocks the room.
  1107. */
  1108. function lockRoom(lock) {
  1109. if (lock)
  1110. connection.emuc.lockRoom(sharedKey);
  1111. else
  1112. connection.emuc.lockRoom('');
  1113. Toolbar.updateLockButton();
  1114. }
  1115. /**
  1116. * Sets the shared key.
  1117. */
  1118. function setSharedKey(sKey) {
  1119. sharedKey = sKey;
  1120. }
  1121. function setRecordingToken(token) {
  1122. recordingToken = token;
  1123. }
  1124. /**
  1125. * Updates the room invite url.
  1126. */
  1127. function updateRoomUrl(newRoomUrl) {
  1128. roomUrl = newRoomUrl;
  1129. // If the invite dialog has been already opened we update the information.
  1130. var inviteLink = document.getElementById('inviteLinkRef');
  1131. if (inviteLink) {
  1132. inviteLink.value = roomUrl;
  1133. inviteLink.select();
  1134. document.getElementById('jqi_state0_buttonInvite').disabled = false;
  1135. }
  1136. }
  1137. /**
  1138. * Warning to the user that the conference window is about to be closed.
  1139. */
  1140. function closePageWarning() {
  1141. if (focus !== null)
  1142. return "You are the owner of this conference call and"
  1143. + " you are about to end it.";
  1144. else
  1145. return "You are about to leave this conversation.";
  1146. }
  1147. /**
  1148. * Resizes and repositions videos in full screen mode.
  1149. */
  1150. $(document).on('webkitfullscreenchange mozfullscreenchange fullscreenchange',
  1151. function () {
  1152. VideoLayout.resizeLargeVideoContainer();
  1153. VideoLayout.positionLarge();
  1154. isFullScreen = document.fullScreen ||
  1155. document.mozFullScreen ||
  1156. document.webkitIsFullScreen;
  1157. if (isFullScreen) {
  1158. setView("fullscreen");
  1159. }
  1160. else {
  1161. setView("default");
  1162. }
  1163. }
  1164. );
  1165. /**
  1166. * Sets the current view.
  1167. */
  1168. function setView(viewName) {
  1169. // if (viewName == "fullscreen") {
  1170. // document.getElementById('videolayout_fullscreen').disabled = false;
  1171. // document.getElementById('videolayout_default').disabled = true;
  1172. // }
  1173. // else {
  1174. // document.getElementById('videolayout_default').disabled = false;
  1175. // document.getElementById('videolayout_fullscreen').disabled = true;
  1176. // }
  1177. }
  1178. function hangUp() {
  1179. if (connection && connection.connected) {
  1180. // ensure signout
  1181. $.ajax({
  1182. type: 'POST',
  1183. url: config.bosh,
  1184. async: false,
  1185. cache: false,
  1186. contentType: 'application/xml',
  1187. data: "<body rid='" + (connection.rid || connection._proto.rid) + "' xmlns='http://jabber.org/protocol/httpbind' sid='" + (connection.sid || connection._proto.sid) + "' type='terminate'><presence xmlns='jabber:client' type='unavailable'/></body>",
  1188. success: function (data) {
  1189. console.log('signed out');
  1190. console.log(data);
  1191. },
  1192. error: function (XMLHttpRequest, textStatus, errorThrown) {
  1193. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  1194. }
  1195. });
  1196. }
  1197. disposeConference(true);
  1198. }
  1199. $(document).bind('fatalError.jingle',
  1200. function (event, session, error)
  1201. {
  1202. sessionTerminated = true;
  1203. connection.emuc.doLeave();
  1204. openMessageDialog( "Sorry",
  1205. "Your browser version is too old. Please update and try again...");
  1206. }
  1207. );
  1208. function callSipButtonClicked()
  1209. {
  1210. $.prompt('<h2>Enter SIP number</h2>' +
  1211. '<input id="sipNumber" type="text" value="" autofocus>',
  1212. {
  1213. persistent: false,
  1214. buttons: { "Dial": true, "Cancel": false},
  1215. defaultButton: 2,
  1216. loaded: function (event)
  1217. {
  1218. document.getElementById('sipNumber').focus();
  1219. },
  1220. submit: function (e, v, m, f)
  1221. {
  1222. if (v)
  1223. {
  1224. var numberInput = document.getElementById('sipNumber');
  1225. if (numberInput.value && numberInput.value.length)
  1226. {
  1227. connection.rayo.dial(
  1228. numberInput.value, 'fromnumber', roomName);
  1229. }
  1230. }
  1231. }
  1232. }
  1233. );
  1234. }
  1235. function hangup() {
  1236. disposeConference();
  1237. sessionTerminated = true;
  1238. connection.emuc.doLeave();
  1239. var buttons = {};
  1240. if(config.enableWelcomePage)
  1241. {
  1242. setTimeout(function()
  1243. {
  1244. window.localStorage.welcomePageDisabled = false;
  1245. window.location.pathname = "/";
  1246. }, 10000);
  1247. }
  1248. $.prompt("Session Terminated",
  1249. {
  1250. title: "You hung up the call",
  1251. persistent: true,
  1252. buttons: {
  1253. "Join again": true
  1254. },
  1255. closeText: '',
  1256. submit: function(event, value, message, formVals)
  1257. {
  1258. window.location.reload();
  1259. return false;
  1260. }
  1261. }
  1262. );
  1263. }