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 44KB

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