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

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