Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

app.js 43KB

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