You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.js 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  1. /* jshint -W117 */
  2. /* application specific logic */
  3. var connection = null;
  4. var focus = null;
  5. var RTC;
  6. var RTCPeerConnection = null;
  7. var nickname = null;
  8. var sharedKey = '';
  9. var roomUrl = null;
  10. var ssrc2jid = {};
  11. var localVideoSrc = null;
  12. var preziPlayer = null;
  13. /* window.onbeforeunload = closePageWarning; */
  14. function init() {
  15. RTC = setupRTC();
  16. if (RTC === null) {
  17. window.location.href = 'webrtcrequired.html';
  18. return;
  19. } else if (RTC.browser != 'chrome') {
  20. window.location.href = 'chromeonly.html';
  21. return;
  22. }
  23. RTCPeerconnection = TraceablePeerConnection;
  24. connection = new Strophe.Connection(document.getElementById('boshURL').value || config.bosh || '/http-bind');
  25. if (nickname) {
  26. connection.emuc.addDisplayNameToPresence(nickname);
  27. }
  28. if (connection.disco) {
  29. // for chrome, add multistream cap
  30. }
  31. connection.jingle.pc_constraints = RTC.pc_constraints;
  32. if (config.useIPv6) {
  33. // https://code.google.com/p/webrtc/issues/detail?id=2828
  34. if (!connection.jingle.pc_constraints.optional) connection.jingle.pc_constraints.optional = [];
  35. connection.jingle.pc_constraints.optional.push({googIPv6: true});
  36. }
  37. var jid = document.getElementById('jid').value || config.hosts.domain || window.location.hostname;
  38. connection.connect(jid, document.getElementById('password').value, function (status) {
  39. if (status == Strophe.Status.CONNECTED) {
  40. console.log('connected');
  41. if (config.useStunTurn) {
  42. connection.jingle.getStunAndTurnCredentials();
  43. }
  44. if (RTC.browser == 'firefox') {
  45. getUserMediaWithConstraints(['audio']);
  46. } else {
  47. getUserMediaWithConstraints(['audio', 'video'], config.resolution || '360');
  48. }
  49. document.getElementById('connect').disabled = true;
  50. } else {
  51. console.log('status', status);
  52. }
  53. });
  54. }
  55. function doJoin() {
  56. var roomnode = null;
  57. var path = window.location.pathname;
  58. var roomjid;
  59. // determinde the room node from the url
  60. // TODO: just the roomnode or the whole bare jid?
  61. if (config.getroomnode && typeof config.getroomnode === 'function') {
  62. // custom function might be responsible for doing the pushstate
  63. roomnode = config.getroomnode(path);
  64. } else {
  65. /* fall back to default strategy
  66. * this is making assumptions about how the URL->room mapping happens.
  67. * It currently assumes deployment at root, with a rewrite like the
  68. * following one (for nginx):
  69. location ~ ^/([a-zA-Z0-9]+)$ {
  70. rewrite ^/(.*)$ / break;
  71. }
  72. */
  73. if (path.length > 1) {
  74. roomnode = path.substr(1).toLowerCase();
  75. } else {
  76. roomnode = Math.random().toString(36).substr(2, 20);
  77. window.history.pushState('VideoChat', 'Room: ' + roomnode, window.location.pathname + roomnode);
  78. }
  79. }
  80. roomjid = roomnode + '@' + config.hosts.muc;
  81. if (config.useNicks) {
  82. var nick = window.prompt('Your nickname (optional)');
  83. if (nick) {
  84. roomjid += '/' + nick;
  85. } else {
  86. roomjid += '/' + Strophe.getNodeFromJid(connection.jid);
  87. }
  88. } else {
  89. roomjid += '/' + Strophe.getNodeFromJid(connection.jid).substr(0,8);
  90. }
  91. connection.emuc.doJoin(roomjid);
  92. }
  93. $(document).bind('mediaready.jingle', function (event, stream) {
  94. connection.jingle.localStream = stream;
  95. RTC.attachMediaStream($('#localVideo'), stream);
  96. document.getElementById('localVideo').autoplay = true;
  97. document.getElementById('localVideo').volume = 0;
  98. localVideoSrc = document.getElementById('localVideo').src;
  99. updateLargeVideo(localVideoSrc, true, 0);
  100. $('#localVideo').click(function () {
  101. updateLargeVideo($(this).attr('src'), true, 0);
  102. $('video').each(function (idx, el) {
  103. if (el.id.indexOf('mixedmslabel') != -1) {
  104. el.volume = 0;
  105. el.volume = 1;
  106. }
  107. });
  108. });
  109. doJoin();
  110. });
  111. $(document).bind('mediafailure.jingle', function () {
  112. // FIXME
  113. });
  114. $(document).bind('remotestreamadded.jingle', function (event, data, sid) {
  115. function waitForRemoteVideo(selector, sid) {
  116. var sess = connection.jingle.sessions[sid];
  117. if (data.stream.id == 'mixedmslabel') return;
  118. videoTracks = data.stream.getVideoTracks();
  119. if (videoTracks.length === 0 || selector[0].currentTime > 0) {
  120. RTC.attachMediaStream(selector, data.stream); // FIXME: why do i have to do this for FF?
  121. $(document).trigger('callactive.jingle', [selector, sid]);
  122. console.log('waitForremotevideo', sess.peerconnection.iceConnectionState, sess.peerconnection.signalingState);
  123. } else {
  124. setTimeout(function () { waitForRemoteVideo(selector, sid); }, 250);
  125. }
  126. }
  127. var sess = connection.jingle.sessions[sid];
  128. // look up an associated JID for a stream id
  129. if (data.stream.id.indexOf('mixedmslabel') == -1) {
  130. var ssrclines = SDPUtil.find_lines(sess.peerconnection.remoteDescription.sdp, 'a=ssrc');
  131. ssrclines = ssrclines.filter(function (line) {
  132. return line.indexOf('mslabel:' + data.stream.label) != -1;
  133. });
  134. if (ssrclines.length) {
  135. thessrc = ssrclines[0].substring(7).split(' ')[0];
  136. // ok to overwrite the one from focus? might save work in colibri.js
  137. console.log('associated jid', ssrc2jid[thessrc], data.peerjid);
  138. if (ssrc2jid[thessrc]) {
  139. data.peerjid = ssrc2jid[thessrc];
  140. }
  141. }
  142. }
  143. var container;
  144. var remotes = document.getElementById('remoteVideos');
  145. if (data.peerjid) {
  146. container = document.getElementById('participant_' + Strophe.getResourceFromJid(data.peerjid));
  147. if (!container) {
  148. console.warn('no container for', data.peerjid);
  149. // create for now...
  150. // FIXME: should be removed
  151. container = addRemoteVideoContainer('participant_' + Strophe.getResourceFromJid(data.peerjid));
  152. } else {
  153. //console.log('found container for', data.peerjid);
  154. }
  155. } else {
  156. if (data.stream.id != 'mixedmslabel') {
  157. console.warn('can not associate stream', data.stream.id, 'with a participant');
  158. }
  159. // FIXME: for the mixed ms we dont need a video -- currently
  160. container = document.createElement('span');
  161. container.className = 'videocontainer';
  162. remotes.appendChild(container);
  163. }
  164. var vid = document.createElement('video');
  165. var id = 'remoteVideo_' + sid + '_' + data.stream.id;
  166. vid.id = id;
  167. vid.autoplay = true;
  168. vid.oncontextmenu = function () { return false; };
  169. container.appendChild(vid);
  170. // TODO: make mixedstream display:none via css?
  171. if (id.indexOf('mixedmslabel') != -1) {
  172. container.id = 'mixedstream';
  173. $(container).hide();
  174. }
  175. var sel = $('#' + id);
  176. sel.hide();
  177. RTC.attachMediaStream(sel, data.stream);
  178. waitForRemoteVideo(sel, sid);
  179. data.stream.onended = function () {
  180. console.log('stream ended', this.id);
  181. var src = $('#' + id).attr('src');
  182. if (src === $('#largeVideo').attr('src')) {
  183. // this is currently displayed as large
  184. // pick the last visible video in the row
  185. // if nobody else is left, this picks the local video
  186. var pick = $('#remoteVideos>span[id!="mixedstream"]:visible:last>video').get(0);
  187. // mute if localvideo
  188. var isLocalVideo = false;
  189. if (pick) {
  190. if (pick.src === localVideoSrc)
  191. isLocalVideo = true;
  192. updateLargeVideo(pick.src, isLocalVideo, pick.volume);
  193. }
  194. }
  195. $('#' + id).parent().remove();
  196. resizeThumbnails();
  197. };
  198. sel.click(
  199. function () {
  200. updateLargeVideo($(this).attr('src'), false, 1);
  201. }
  202. );
  203. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  204. if (data.peerjid && sess.peerjid == data.peerjid &&
  205. data.stream.getVideoTracks().length == 0 &&
  206. connection.jingle.localStream.getVideoTracks().length > 0) {
  207. window.setTimeout(function() {
  208. sendKeyframe(sess.peerconnection);
  209. }, 3000);
  210. }
  211. });
  212. // an attempt to work around https://github.com/jitsi/jitmeet/issues/32
  213. function sendKeyframe(pc) {
  214. console.log('sendkeyframe', pc.iceConnectionState);
  215. if (pc.iceConnectionState != 'connected') return; // safe...
  216. pc.setRemoteDescription(
  217. pc.remoteDescription,
  218. function () {
  219. pc.createAnswer(
  220. function (modifiedAnswer) {
  221. pc.setLocalDescription(modifiedAnswer,
  222. function () {
  223. },
  224. function (error) {
  225. console.log('triggerKeyframe setLocalDescription failed', error);
  226. }
  227. );
  228. },
  229. function (error) {
  230. console.log('triggerKeyframe createAnswer failed', error);
  231. }
  232. );
  233. },
  234. function (error) {
  235. console.log('triggerKeyframe setRemoteDescription failed', error);
  236. }
  237. );
  238. }
  239. $(document).bind('callincoming.jingle', function (event, sid) {
  240. var sess = connection.jingle.sessions[sid];
  241. // TODO: check affiliation and/or role
  242. console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
  243. sess.usedrip = true; // not-so-naive trickle ice
  244. sess.sendAnswer();
  245. sess.accept();
  246. });
  247. $(document).bind('callactive.jingle', function (event, videoelem, sid) {
  248. if (videoelem.attr('id').indexOf('mixedmslabel') == -1) {
  249. // ignore mixedmslabela0 and v0
  250. videoelem.show();
  251. resizeThumbnails();
  252. updateLargeVideo(videoelem.attr('src'), false, 1);
  253. showFocusIndicator();
  254. }
  255. });
  256. $(document).bind('callterminated.jingle', function (event, sid, reason) {
  257. // FIXME
  258. });
  259. $(document).bind('setLocalDescription.jingle', function (event, sid) {
  260. // put our ssrcs into presence so other clients can identify our stream
  261. var sess = connection.jingle.sessions[sid];
  262. var newssrcs = {};
  263. var localSDP = new SDP(sess.peerconnection.localDescription.sdp);
  264. localSDP.media.forEach(function (media) {
  265. var type = SDPUtil.parse_mline(media.split('\r\n')[0]).media;
  266. if (SDPUtil.find_line(media, 'a=ssrc:')) {
  267. var ssrc = SDPUtil.find_line(media, 'a=ssrc:').substring(7).split(' ')[0];
  268. // assumes a single local ssrc
  269. newssrcs[type] = ssrc;
  270. }
  271. });
  272. console.log('new ssrcs', newssrcs);
  273. var i = 0;
  274. Object.keys(newssrcs).forEach(function (mtype) {
  275. i++;
  276. connection.emuc.addMediaToPresence(i, mtype, newssrcs[mtype]);
  277. });
  278. if (i > 0) {
  279. connection.emuc.sendPresence();
  280. }
  281. });
  282. $(document).bind('joined.muc', function (event, jid, info) {
  283. updateRoomUrl(window.location.href);
  284. document.getElementById('localNick').appendChild(
  285. document.createTextNode(Strophe.getResourceFromJid(jid) + ' (me)')
  286. );
  287. if (Object.keys(connection.emuc.members).length < 1) {
  288. focus = new ColibriFocus(connection, config.hosts.bridge);
  289. }
  290. showFocusIndicator();
  291. // Once we've joined the muc show the toolbar
  292. showToolbar();
  293. var displayName = '';
  294. if (info.displayName)
  295. displayName = info.displayName + ' (me)';
  296. showDisplayName('localVideoContainer', displayName);
  297. });
  298. $(document).bind('entered.muc', function (event, jid, info, pres) {
  299. console.log('entered', jid, info);
  300. console.log(focus);
  301. var videoSpanId = 'participant_' + Strophe.getResourceFromJid(jid);
  302. var container = addRemoteVideoContainer(videoSpanId);
  303. if (info.displayName)
  304. showDisplayName(videoSpanId, info.displayName);
  305. var nickfield = document.createElement('span');
  306. nickfield.appendChild(document.createTextNode(Strophe.getResourceFromJid(jid)));
  307. container.appendChild(nickfield);
  308. resizeThumbnails();
  309. if (focus !== null) {
  310. // FIXME: this should prepare the video
  311. if (focus.confid === null) {
  312. console.log('make new conference with', jid);
  313. focus.makeConference(Object.keys(connection.emuc.members));
  314. } else {
  315. console.log('invite', jid, 'into conference');
  316. focus.addNewParticipant(jid);
  317. }
  318. }
  319. else if (sharedKey) {
  320. updateLockButton();
  321. }
  322. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  323. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  324. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  325. });
  326. });
  327. $(document).bind('left.muc', function (event, jid) {
  328. console.log('left', jid);
  329. connection.jingle.terminateByJid(jid);
  330. var container = document.getElementById('participant_' + Strophe.getResourceFromJid(jid));
  331. if (container) {
  332. // hide here, wait for video to close before removing
  333. $(container).hide();
  334. resizeThumbnails();
  335. }
  336. if (focus === null && connection.emuc.myroomjid == connection.emuc.list_members[0]) {
  337. console.log('welcome to our new focus... myself');
  338. focus = new ColibriFocus(connection, config.hosts.bridge);
  339. if (Object.keys(connection.emuc.members).length > 0) {
  340. focus.makeConference(Object.keys(connection.emuc.members));
  341. }
  342. }
  343. else if (focus && Object.keys(connection.emuc.members).length === 0) {
  344. console.log('everyone left');
  345. if (focus !== null) {
  346. // FIXME: closing the connection is a hack to avoid some
  347. // problemswith reinit
  348. if (focus.peerconnection !== null) {
  349. focus.peerconnection.close();
  350. }
  351. focus = new ColibriFocus(connection, config.hosts.bridge);
  352. }
  353. }
  354. if (connection.emuc.getPrezi(jid)) {
  355. $(document).trigger('presentationremoved.muc', [jid, connection.emuc.getPrezi(jid)]);
  356. }
  357. });
  358. $(document).bind('presence.muc', function (event, jid, info, pres) {
  359. $(pres).find('>media[xmlns="http://estos.de/ns/mjs"]>source').each(function (idx, ssrc) {
  360. //console.log(jid, 'assoc ssrc', ssrc.getAttribute('type'), ssrc.getAttribute('ssrc'));
  361. ssrc2jid[ssrc.getAttribute('ssrc')] = jid;
  362. });
  363. if (info.displayName) {
  364. if (jid === connection.emuc.myroomjid)
  365. showDisplayName('localVideoContainer', info.displayName + ' (me)');
  366. else
  367. showDisplayName('participant_' + Strophe.getResourceFromJid(jid), info.displayName);
  368. }
  369. });
  370. $(document).bind('passwordrequired.muc', function (event, jid) {
  371. console.log('on password required', jid);
  372. $.prompt('<h2>Password required</h2>' +
  373. '<input id="lockKey" type="text" placeholder="shared key" autofocus>',
  374. {
  375. persistent: true,
  376. buttons: { "Ok": true , "Cancel": false},
  377. defaultButton: 1,
  378. loaded: function(event) {
  379. document.getElementById('lockKey').focus();
  380. },
  381. submit: function(e,v,m,f){
  382. if(v)
  383. {
  384. var lockKey = document.getElementById('lockKey');
  385. if (lockKey.value != null)
  386. {
  387. setSharedKey(lockKey.value);
  388. connection.emuc.doJoin(jid, lockKey.value);
  389. }
  390. }
  391. }
  392. });
  393. });
  394. /*
  395. * Presentation has been removed.
  396. */
  397. $(document).bind('presentationremoved.muc', function(event, jid, presUrl) {
  398. console.log('presentation removed', presUrl);
  399. var presId = getPresentationId(presUrl);
  400. setPresentationVisible(false);
  401. $('#participant_' + Strophe.getResourceFromJid(jid) + '_' + presId).remove();
  402. $('#presentation>iframe').remove();
  403. if (preziPlayer != null) {
  404. preziPlayer.destroy();
  405. preziPlayer = null;
  406. }
  407. });
  408. /*
  409. * Presentation has been added.
  410. */
  411. $(document).bind('presentationadded.muc', function (event, jid, presUrl, currentSlide) {
  412. console.log("presentation added", presUrl);
  413. var presId = getPresentationId(presUrl);
  414. var elementId = 'participant_' + Strophe.getResourceFromJid(jid) + '_' + presId;
  415. var container = addRemoteVideoContainer(elementId);
  416. resizeThumbnails();
  417. var controlsEnabled = false;
  418. if (jid === connection.emuc.myroomjid)
  419. controlsEnabled = true;
  420. setPresentationVisible(true);
  421. $('#largeVideoContainer').hover(
  422. function (event) {
  423. if ($('#largeVideo').css('visibility') == 'hidden')
  424. $('#reloadPresentation').css({display:'inline-block'});
  425. },
  426. function (event) {
  427. if ($('#largeVideo').css('visibility') == 'visible')
  428. $('#reloadPresentation').css({display:'none'});
  429. else {
  430. var e = event.toElement || event.relatedTarget;
  431. while(e && e.parentNode && e.parentNode != window) {
  432. if (e.parentNode == this || e == this) {
  433. return false;
  434. }
  435. e = e.parentNode;
  436. }
  437. $('#reloadPresentation').css({display:'none'});
  438. }
  439. });
  440. preziPlayer = new PreziPlayer(
  441. 'presentation',
  442. {preziId: presId,
  443. width: $('#largeVideoContainer').width(),
  444. height: $('#largeVideoContainer').height(),
  445. controls: controlsEnabled,
  446. debug: true
  447. });
  448. $('#presentation>iframe').attr('id', preziPlayer.options.preziId);
  449. preziPlayer.on(PreziPlayer.EVENT_STATUS, function(event) {
  450. console.log("prezi status", event.value);
  451. if (event.value == PreziPlayer.STATUS_CONTENT_READY) {
  452. if (jid != connection.emuc.myroomjid)
  453. preziPlayer.flyToStep(currentSlide);
  454. }
  455. });
  456. preziPlayer.on(PreziPlayer.EVENT_CURRENT_STEP, function(event) {
  457. console.log("event value", event.value);
  458. connection.emuc.addCurrentSlideToPresence(event.value);
  459. connection.emuc.sendPresence();
  460. });
  461. $("#" + elementId).css('background-image','url(../images/avatarprezi.png)');
  462. $("#" + elementId).click(
  463. function () {
  464. setPresentationVisible(true);
  465. }
  466. );
  467. });
  468. /*
  469. * Indicates presentation slide change.
  470. */
  471. $(document).bind('gotoslide.muc', function (event, jid, presUrl, current) {
  472. if (preziPlayer) {
  473. preziPlayer.flyToStep(current);
  474. }
  475. });
  476. /**
  477. * Returns the presentation id from the given url.
  478. */
  479. function getPresentationId (presUrl) {
  480. var presIdTmp = presUrl.substring(presUrl.indexOf("prezi.com/") + 10);
  481. return presIdTmp.substring(0, presIdTmp.indexOf('/'));
  482. }
  483. /*
  484. * Reloads the current presentation.
  485. */
  486. function reloadPresentation() {
  487. var iframe = document.getElementById(preziPlayer.options.preziId);
  488. iframe.src = iframe.src;
  489. }
  490. /*
  491. * Shows/hides a presentation.
  492. */
  493. function setPresentationVisible(visible) {
  494. if (visible) {
  495. $('#largeVideo').fadeOut(300, function () {
  496. $('#largeVideo').css({visibility:'hidden'});
  497. $('#presentation>iframe').fadeIn(300, function() {
  498. $('#presentation>iframe').css({opacity:'1'});
  499. });
  500. });
  501. }
  502. else {
  503. if ($('#presentation>iframe')) {
  504. $('#presentation>iframe').fadeOut(300, function () {
  505. $('#presentation>iframe').css({opacity:'0'});
  506. $('#largeVideo').fadeIn(300, function() {
  507. $('#largeVideo').css({visibility:'visible'});
  508. });
  509. });
  510. }
  511. }
  512. }
  513. /**
  514. * Updates the large video with the given new video source.
  515. */
  516. function updateLargeVideo(newSrc, localVideo, vol) {
  517. console.log('hover in', newSrc);
  518. setPresentationVisible(false);
  519. if ($('#largeVideo').attr('src') != newSrc) {
  520. document.getElementById('largeVideo').volume = vol;
  521. $('#largeVideo').fadeOut(300, function () {
  522. $(this).attr('src', newSrc);
  523. var videoTransform = document.getElementById('largeVideo').style.webkitTransform;
  524. if (localVideo && videoTransform != 'scaleX(-1)') {
  525. document.getElementById('largeVideo').style.webkitTransform = "scaleX(-1)";
  526. }
  527. else if (!localVideo && videoTransform == 'scaleX(-1)') {
  528. document.getElementById('largeVideo').style.webkitTransform = "none";
  529. }
  530. $(this).fadeIn(300);
  531. });
  532. }
  533. }
  534. function toggleVideo() {
  535. if (!(connection && connection.jingle.localStream)) return;
  536. for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) {
  537. connection.jingle.localStream.getVideoTracks()[idx].enabled = !connection.jingle.localStream.getVideoTracks()[idx].enabled;
  538. }
  539. }
  540. function toggleAudio() {
  541. if (!(connection && connection.jingle.localStream)) return;
  542. for (var idx = 0; idx < connection.jingle.localStream.getAudioTracks().length; idx++) {
  543. connection.jingle.localStream.getAudioTracks()[idx].enabled = !connection.jingle.localStream.getAudioTracks()[idx].enabled;
  544. }
  545. }
  546. function resizeLarge() {
  547. resizeChat();
  548. var availableHeight = window.innerHeight;
  549. var chatspaceWidth = $('#chatspace').is(":visible")
  550. ? $('#chatspace').width()
  551. : 0;
  552. var numvids = $('#remoteVideos>video:visible').length;
  553. if (numvids < 5)
  554. availableHeight -= 100; // min thumbnail height for up to 4 videos
  555. else
  556. availableHeight -= 50; // min thumbnail height for more than 5 videos
  557. availableHeight -= 79; // padding + link ontop
  558. var availableWidth = window.innerWidth - chatspaceWidth;
  559. var aspectRatio = 16.0 / 9.0;
  560. if (availableHeight < availableWidth / aspectRatio) {
  561. availableWidth = Math.floor(availableHeight * aspectRatio);
  562. }
  563. if (availableWidth < 0 || availableHeight < 0) return;
  564. $('#largeVideo').parent().width(availableWidth);
  565. $('#largeVideo').parent().height(availableWidth / aspectRatio);
  566. if ($('#presentation>iframe')) {
  567. $('#presentation>iframe').width(availableWidth);
  568. $('#presentation>iframe').height(availableWidth / aspectRatio);
  569. }
  570. resizeThumbnails();
  571. }
  572. function resizeThumbnails() {
  573. // Calculate the available height, which is the inner window height minus 39px for the header
  574. // minus 4px for the delimiter lines on the top and bottom of the large video,
  575. // minus the 36px space inside the remoteVideos container used for highlighting shadow.
  576. var availableHeight = window.innerHeight - $('#largeVideo').height() - 79;
  577. var numvids = $('#remoteVideos>span:visible').length;
  578. // Remove the 1px borders arround videos and the chat width.
  579. var availableWinWidth = $('#remoteVideos').width() - 2 * numvids - 50;
  580. var availableWidth = availableWinWidth / numvids;
  581. var aspectRatio = 16.0 / 9.0;
  582. var maxHeight = Math.min(160, availableHeight);
  583. availableHeight = Math.min(maxHeight, availableWidth / aspectRatio);
  584. if (availableHeight < availableWidth / aspectRatio) {
  585. availableWidth = Math.floor(availableHeight * aspectRatio);
  586. }
  587. // size videos so that while keeping AR and max height, we have a nice fit
  588. $('#remoteVideos').height(availableHeight+26); // add the 2*18px-padding-top border used for highlighting shadow.
  589. $('#remoteVideos>span').width(availableWidth);
  590. $('#remoteVideos>span').height(availableHeight);
  591. }
  592. function resizeChat() {
  593. var availableHeight = window.innerHeight;
  594. var availableWidth = window.innerWidth;
  595. var chatWidth = 200;
  596. if (availableWidth*0.2 < 200)
  597. chatWidth = availableWidth*0.2;
  598. $('#chatspace').width(chatWidth);
  599. $('#chatspace').height(availableHeight - 40);
  600. resizeChatConversation();
  601. }
  602. function resizeChatConversation() {
  603. var usermsgStyleHeight = document.getElementById("usermsg").style.height;
  604. var usermsgHeight = usermsgStyleHeight.substring(0, usermsgStyleHeight.indexOf('px'));
  605. $('#chatconversation').width($('#chatspace').width() - 10);
  606. $('#chatconversation').height(window.innerHeight - 50 - parseInt(usermsgHeight));
  607. }
  608. $(document).ready(function () {
  609. var storedDisplayName = window.localStorage.displayname;
  610. if (storedDisplayName) {
  611. nickname = storedDisplayName;
  612. setChatConversationMode(true);
  613. }
  614. $('#nickinput').keydown(function(event) {
  615. if (event.keyCode == 13) {
  616. event.preventDefault();
  617. var val = this.value;
  618. this.value = '';
  619. if (!nickname) {
  620. nickname = val;
  621. window.localStorage.displayname = nickname;
  622. connection.emuc.addDisplayNameToPresence(nickname);
  623. connection.emuc.sendPresence();
  624. setChatConversationMode(true);
  625. return;
  626. }
  627. }
  628. });
  629. $('#usermsg').keydown(function(event) {
  630. if (event.keyCode == 13) {
  631. event.preventDefault();
  632. var message = this.value;
  633. $('#usermsg').val('').trigger('autosize.resize');
  634. this.focus();
  635. connection.emuc.sendMessage(message, nickname);
  636. }
  637. });
  638. var onTextAreaResize = function() {
  639. resizeChatConversation();
  640. scrollChatToBottom();
  641. };
  642. $('#usermsg').autosize({callback: onTextAreaResize});
  643. // Set the defaults for prompt dialogs.
  644. jQuery.prompt.setDefaults({persistent: false});
  645. resizeLarge();
  646. $(window).resize(function () {
  647. resizeLarge();
  648. });
  649. if (!$('#settings').is(':visible')) {
  650. console.log('init');
  651. init();
  652. } else {
  653. loginInfo.onsubmit = function (e) {
  654. if (e.preventDefault) e.preventDefault();
  655. $('#settings').hide();
  656. init();
  657. };
  658. }
  659. });
  660. $(window).bind('beforeunload', function () {
  661. if (connection && connection.connected) {
  662. // ensure signout
  663. $.ajax({
  664. type: 'POST',
  665. url: config.bosh,
  666. async: false,
  667. cache: false,
  668. contentType: 'application/xml',
  669. 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>",
  670. success: function (data) {
  671. console.log('signed out');
  672. console.log(data);
  673. },
  674. error: function (XMLHttpRequest, textStatus, errorThrown) {
  675. console.log('signout error', textStatus + ' (' + errorThrown + ')');
  676. }
  677. });
  678. }
  679. });
  680. function dump(elem, filename){
  681. elem = elem.parentNode;
  682. elem.download = filename || 'meetlog.json';
  683. elem.href = 'data:application/json;charset=utf-8,\n';
  684. var data = {};
  685. if (connection.jingle) {
  686. Object.keys(connection.jingle.sessions).forEach(function (sid) {
  687. var session = connection.jingle.sessions[sid];
  688. if (session.peerconnection && session.peerconnection.updateLog) {
  689. // FIXME: should probably be a .dump call
  690. data["jingle_" + session.sid] = {
  691. updateLog: session.peerconnection.updateLog,
  692. stats: session.peerconnection.stats,
  693. url: window.location.href}
  694. ;
  695. }
  696. });
  697. }
  698. metadata = {};
  699. metadata.time = new Date();
  700. metadata.url = window.location.href;
  701. metadata.ua = navigator.userAgent;
  702. if (connection.logger) {
  703. metadata.xmpp = connection.logger.log;
  704. }
  705. data.metadata = metadata;
  706. elem.href += encodeURIComponent(JSON.stringify(data, null, ' '));
  707. return false;
  708. }
  709. /*
  710. * Appends the given message to the chat conversation.
  711. */
  712. function updateChatConversation(nick, message)
  713. {
  714. var divClassName = '';
  715. if (nickname == nick)
  716. divClassName = "localuser";
  717. else
  718. divClassName = "remoteuser";
  719. //replace links and smileys
  720. message = processReplacements(message);
  721. $('#chatconversation').append('<div class="' + divClassName + '"><b>' + nick + ': </b>' + message + '</div>');
  722. $('#chatconversation').animate({ scrollTop: $('#chatconversation')[0].scrollHeight}, 1000);
  723. }
  724. /*
  725. * Changes the style class of the element given by id.
  726. */
  727. function buttonClick(id, classname) {
  728. $(id).toggleClass(classname); // add the class to the clicked element
  729. }
  730. /*
  731. * Opens the lock room dialog.
  732. */
  733. function openLockDialog() {
  734. // Only the focus is able to set a shared key.
  735. if (focus == null) {
  736. if (sharedKey)
  737. $.prompt("This conversation is currently protected by a shared secret key.",
  738. {
  739. title: "Secrect key",
  740. persistent: false
  741. });
  742. else
  743. $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.",
  744. {
  745. title: "Secrect key",
  746. persistent: false
  747. });
  748. }
  749. else {
  750. if (sharedKey)
  751. $.prompt("Are you sure you would like to remove your secret key?",
  752. {
  753. title: "Remove secrect key",
  754. persistent: false,
  755. buttons: { "Remove": true, "Cancel": false},
  756. defaultButton: 1,
  757. submit: function(e,v,m,f){
  758. if(v)
  759. {
  760. setSharedKey('');
  761. lockRoom(false);
  762. }
  763. }
  764. });
  765. else
  766. $.prompt('<h2>Set a secrect key to lock your room</h2>' +
  767. '<input id="lockKey" type="text" placeholder="your shared key" autofocus>',
  768. {
  769. persistent: false,
  770. buttons: { "Save": true , "Cancel": false},
  771. defaultButton: 1,
  772. loaded: function(event) {
  773. document.getElementById('lockKey').focus();
  774. },
  775. submit: function(e,v,m,f){
  776. if(v)
  777. {
  778. var lockKey = document.getElementById('lockKey');
  779. if (lockKey.value)
  780. {
  781. setSharedKey(lockKey.value);
  782. lockRoom(true);
  783. }
  784. }
  785. }
  786. });
  787. }
  788. }
  789. /*
  790. * Opens the invite link dialog.
  791. */
  792. function openLinkDialog() {
  793. $.prompt('<input id="inviteLinkRef" type="text" value="' + roomUrl + '" onclick="this.select();">',
  794. {
  795. title: "Share this link with everyone you want to invite",
  796. persistent: false,
  797. buttons: { "Cancel": false},
  798. loaded: function(event) {
  799. document.getElementById('inviteLinkRef').select();
  800. }
  801. });
  802. }
  803. /*
  804. * Opens the settings dialog.
  805. */
  806. function openSettingsDialog() {
  807. $.prompt('<h2>Configure your conference</h2>' +
  808. '<input type="checkbox" id="initMuted"> Participants join muted<br/>' +
  809. '<input type="checkbox" id="requireNicknames"> Require nicknames<br/><br/>' +
  810. 'Set a secrect key to lock your room: <input id="lockKey" type="text" placeholder="your shared key" autofocus>',
  811. {
  812. persistent: false,
  813. buttons: { "Save": true , "Cancel": false},
  814. defaultButton: 1,
  815. loaded: function(event) {
  816. document.getElementById('lockKey').focus();
  817. },
  818. submit: function(e,v,m,f){
  819. if(v)
  820. {
  821. if ($('#initMuted').is(":checked"))
  822. {
  823. // it is checked
  824. }
  825. if ($('#requireNicknames').is(":checked"))
  826. {
  827. // it is checked
  828. }
  829. /*
  830. var lockKey = document.getElementById('lockKey');
  831. if (lockKey.value)
  832. {
  833. setSharedKey(lockKey.value);
  834. lockRoom(true);
  835. }
  836. */
  837. }
  838. }
  839. });
  840. }
  841. /*
  842. * Opens the Prezi dialog, from which the user could choose a presentation to load.
  843. */
  844. function openPreziDialog() {
  845. var myprezi = connection.emuc.getPrezi(connection.emuc.myroomjid);
  846. if (myprezi) {
  847. $.prompt("Are you sure you would like to remove your Prezi?",
  848. {
  849. title: "Remove Prezi",
  850. buttons: { "Remove": true, "Cancel": false},
  851. defaultButton: 1,
  852. submit: function(e,v,m,f){
  853. if(v)
  854. {
  855. connection.emuc.removePreziFromPresence();
  856. connection.emuc.sendPresence();
  857. }
  858. }
  859. });
  860. }
  861. else if (preziPlayer != null) {
  862. $.prompt("Another participant is already sharing a Prezi. This conference allows only one Prezi at a time.",
  863. {
  864. title: "Share a Prezi",
  865. buttons: { "Ok": true},
  866. defaultButton: 0,
  867. submit: function(e,v,m,f){
  868. $.prompt.close();
  869. }
  870. });
  871. }
  872. else {
  873. var openPreziState = {
  874. state0: {
  875. html: '<h2>Share a Prezi</h2>' +
  876. '<input id="preziUrl" type="text" placeholder="e.g. http://prezi.com/wz7vhjycl7e6/my-prezi" autofocus>',
  877. persistent: false,
  878. buttons: { "Share": true , "Cancel": false},
  879. defaultButton: 1,
  880. submit: function(e,v,m,f){
  881. e.preventDefault();
  882. if(v)
  883. {
  884. var preziUrl = document.getElementById('preziUrl');
  885. if (preziUrl.value)
  886. {
  887. if (preziUrl.value.indexOf('http://prezi.com/') != 0
  888. && preziUrl.value.indexOf('https://prezi.com/') != 0)
  889. {
  890. $.prompt.goToState('state1');
  891. return false;
  892. }
  893. else {
  894. var presIdTmp = preziUrl.value.substring(preziUrl.value.indexOf("prezi.com/") + 10);
  895. if (presIdTmp.indexOf('/') < 2) {
  896. $.prompt.goToState('state1');
  897. return false;
  898. }
  899. else {
  900. connection.emuc.addPreziToPresence(preziUrl.value, 0);
  901. connection.emuc.sendPresence();
  902. $.prompt.close();
  903. }
  904. }
  905. }
  906. }
  907. else
  908. $.prompt.close();
  909. }
  910. },
  911. state1: {
  912. html: '<h2>Share a Prezi</h2>' +
  913. 'Please provide a correct prezi link.',
  914. persistent: false,
  915. buttons: { "Back": true, "Cancel": false },
  916. defaultButton: 1,
  917. submit:function(e,v,m,f) {
  918. e.preventDefault();
  919. if(v==0)
  920. $.prompt.close();
  921. else
  922. $.prompt.goToState('state0');
  923. }
  924. }
  925. };
  926. var myPrompt = jQuery.prompt(openPreziState);
  927. myPrompt.on('impromptu:loaded', function(e) {
  928. document.getElementById('preziUrl').focus();
  929. });
  930. myPrompt.on('impromptu:statechanged', function(e) {
  931. document.getElementById('preziUrl').focus();
  932. });
  933. }
  934. }
  935. /*
  936. * Locks / unlocks the room.
  937. */
  938. function lockRoom(lock) {
  939. if (lock)
  940. connection.emuc.lockRoom(sharedKey);
  941. else
  942. connection.emuc.lockRoom('');
  943. updateLockButton();
  944. }
  945. /*
  946. * Sets the shared key.
  947. */
  948. function setSharedKey(sKey) {
  949. sharedKey = sKey;
  950. }
  951. /*
  952. * Updates the lock button state.
  953. */
  954. function updateLockButton() {
  955. buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg");
  956. }
  957. /*
  958. * Opens / closes the chat area.
  959. */
  960. function openChat() {
  961. var chatspace = $('#chatspace');
  962. var videospace = $('#videospace');
  963. var onShow = function () {
  964. resizeLarge();
  965. $('#chatspace').show("slide", { direction: "right", duration: 500});
  966. };
  967. var onHide = function () {
  968. $('#chatspace').hide("slide", { direction: "right", duration: 500});
  969. resizeLarge();
  970. };
  971. if (chatspace.css("display") == 'block') {
  972. videospace.animate({right: 0}, {queue: false, duration: 500, progress: onHide});
  973. }
  974. else {
  975. videospace.animate({right: chatspace.width()},
  976. {queue: false,
  977. duration: 500,
  978. progress: onShow,
  979. complete: function() {
  980. scrollChatToBottom();
  981. }
  982. });
  983. }
  984. // Request the focus in the nickname field or the chat input field.
  985. if ($('#nickname').css('visibility') == 'visible')
  986. $('#nickinput').focus();
  987. else {
  988. $('#usermsg').focus();
  989. }
  990. }
  991. /*
  992. * Shows the call main toolbar.
  993. */
  994. function showToolbar() {
  995. $('#toolbar').css({visibility:"visible"});
  996. if (focus != null)
  997. {
  998. // TODO: Enable settings functionality. Need to uncomment the settings button in index.html.
  999. // $('#settingsButton').css({visibility:"visible"});
  1000. }
  1001. }
  1002. /*
  1003. * Updates the room invite url.
  1004. */
  1005. function updateRoomUrl(newRoomUrl) {
  1006. roomUrl = newRoomUrl;
  1007. }
  1008. /*
  1009. * Warning to the user that the conference window is about to be closed.
  1010. */
  1011. function closePageWarning() {
  1012. if (focus != null)
  1013. return "You are the owner of this conference call and you are about to end it.";
  1014. else
  1015. return "You are about to leave this conversation.";
  1016. }
  1017. /*
  1018. * Shows a visual indicator for the focus of the conference.
  1019. * Currently if we're not the owner of the conference we obtain the focus
  1020. * from the connection.jingle.sessions.
  1021. */
  1022. function showFocusIndicator() {
  1023. if (focus != null) {
  1024. var indicatorSpan = $('#localVideoContainer .focusindicator');
  1025. if (indicatorSpan.children().length == 0)
  1026. {
  1027. createFocusIndicatorElement(indicatorSpan[0]);
  1028. }
  1029. }
  1030. else if (Object.keys(connection.jingle.sessions).length > 0) {
  1031. // If we're only a participant the focus will be the only session we have.
  1032. var session = connection.jingle.sessions[Object.keys(connection.jingle.sessions)[0]];
  1033. var focusId = 'participant_' + Strophe.getResourceFromJid(session.peerjid);
  1034. var focusContainer = document.getElementById(focusId);
  1035. var indicatorSpan = $('#' + focusId + ' .focusindicator');
  1036. if (!indicatorSpan || indicatorSpan.length == 0) {
  1037. indicatorSpan = document.createElement('span');
  1038. indicatorSpan.className = 'focusindicator';
  1039. focusContainer.appendChild(indicatorSpan);
  1040. createFocusIndicatorElement(indicatorSpan);
  1041. }
  1042. }
  1043. }
  1044. function addRemoteVideoContainer(id) {
  1045. var container = document.createElement('span');
  1046. container.id = id;
  1047. container.className = 'videocontainer';
  1048. var remotes = document.getElementById('remoteVideos');
  1049. remotes.appendChild(container);
  1050. return container;
  1051. }
  1052. /*
  1053. * Creates the element indicating the focus of the conference.
  1054. */
  1055. function createFocusIndicatorElement(parentElement) {
  1056. var focusIndicator = document.createElement('i');
  1057. focusIndicator.className = 'fa fa-star';
  1058. focusIndicator.title = "The owner of this conference"
  1059. parentElement.appendChild(focusIndicator);
  1060. }
  1061. function scrollChatToBottom() {
  1062. setTimeout(function() {
  1063. $('#chatconversation').scrollTop($('#chatconversation')[0].scrollHeight);
  1064. }, 5);
  1065. }
  1066. /*
  1067. * Toggles the application in and out of full screen mode
  1068. * (a.k.a. presentation mode in Chrome).
  1069. */
  1070. function toggleFullScreen() {
  1071. var fsElement = document.documentElement;
  1072. if (!document.mozFullScreen && !document.webkitIsFullScreen){
  1073. //Enter Full Screen
  1074. if (fsElement.mozRequestFullScreen) {
  1075. fsElement.mozRequestFullScreen();
  1076. }
  1077. else {
  1078. fsElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
  1079. }
  1080. } else {
  1081. //Exit Full Screen
  1082. if (document.mozCancelFullScreen) {
  1083. document.mozCancelFullScreen();
  1084. } else {
  1085. document.webkitCancelFullScreen();
  1086. document.webkitCancelFullScreen();
  1087. }
  1088. }
  1089. }
  1090. /**
  1091. *
  1092. */
  1093. function showDisplayName(videoSpanId, displayName) {
  1094. var nameSpan = $('#' + videoSpanId + '>span.displayname');
  1095. // If we already have a display name for this video.
  1096. if (nameSpan.length > 0) {
  1097. var nameSpanElement = nameSpan.get(0);
  1098. if (nameSpanElement.id == 'localDisplayName'
  1099. && $('#localDisplayName').html() != displayName)
  1100. $('#localDisplayName').html(displayName);
  1101. else
  1102. $('#' + videoSpanId + '_name').html(displayName);
  1103. }
  1104. else {
  1105. var editButton = null;
  1106. if (videoSpanId == 'localVideoContainer') {
  1107. editButton = createEditDisplayNameButton();
  1108. }
  1109. if (displayName.length) {
  1110. nameSpan = document.createElement('span');
  1111. nameSpan.className = 'displayname';
  1112. nameSpan.innerHTML = displayName;
  1113. $('#' + videoSpanId)[0].appendChild(nameSpan);
  1114. }
  1115. if (!editButton) {
  1116. nameSpan.id = videoSpanId + '_name';
  1117. }
  1118. else {
  1119. nameSpan.id = 'localDisplayName';
  1120. $('#' + videoSpanId)[0].appendChild(editButton);
  1121. var editableText = document.createElement('input');
  1122. editableText.className = 'displayname';
  1123. editableText.id = 'editDisplayName';
  1124. if (displayName.length)
  1125. editableText.value = displayName.substring(0, displayName.indexOf(' (me)'));
  1126. editableText.setAttribute('style', 'display:none;');
  1127. editableText.setAttribute('placeholder', 'ex. Jane Pink');
  1128. $('#' + videoSpanId)[0].appendChild(editableText);
  1129. $('#localVideoContainer .displayname').bind("click", function(e) {
  1130. e.preventDefault();
  1131. $('#localDisplayName').hide();
  1132. $('#editDisplayName').show();
  1133. $('#editDisplayName').focus();
  1134. $('#editDisplayName').select();
  1135. var inputDisplayNameHandler = function(name) {
  1136. if (nickname != name) {
  1137. nickname = name;
  1138. window.localStorage.displayname = nickname;
  1139. connection.emuc.addDisplayNameToPresence(nickname);
  1140. connection.emuc.sendPresence();
  1141. setChatConversationMode(true);
  1142. }
  1143. if (!$('#localDisplayName').is(":visible")) {
  1144. $('#localDisplayName').html(name + " (me)");
  1145. $('#localDisplayName').show();
  1146. $('#editDisplayName').hide();
  1147. }
  1148. };
  1149. $('#editDisplayName').one("focusout", function (e) {
  1150. inputDisplayNameHandler(this.value);
  1151. });
  1152. $('#editDisplayName').on('keydown', function (e) {
  1153. if (e.keyCode == 13) {
  1154. e.preventDefault();
  1155. inputDisplayNameHandler(this.value);
  1156. }
  1157. });
  1158. });
  1159. }
  1160. }
  1161. }
  1162. function createEditDisplayNameButton() {
  1163. var editButton = document.createElement('a');
  1164. editButton.className = 'displayname';
  1165. editButton.innerHTML = '<i class="fa fa-pencil"></i>';
  1166. return editButton;
  1167. }
  1168. function setChatConversationMode(isConversationMode) {
  1169. if (isConversationMode) {
  1170. $('#nickname').css({visibility:"hidden"});
  1171. $('#chatconversation').css({visibility:'visible'});
  1172. $('#usermsg').css({visibility:'visible'});
  1173. $('#usermsg').focus();
  1174. }
  1175. }