Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

app.js 46KB

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