Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

app.js 45KB

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