Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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