|
1 |
| - |
2 | 1 | (function (root, factory) {
|
3 | 2 | if (typeof define === 'function' && define.amd) {
|
4 | 3 | define(["converse"], factory);
|
5 | 4 | } else {
|
6 | 5 | factory(converse);
|
7 | 6 | }
|
8 | 7 | }(this, function (converse) {
|
9 |
| - const MEET_MODAL_DIALOG_ID = 'sp-meet-dialog'; |
10 | 8 | var MEET_START_OPTIONS = {
|
11 | 9 | INTO_CHAT_WINDOW : "into_chat_window",
|
12 | 10 | INTO_NEW_TAB : "into_new_tab",
|
13 | 11 | JUST_CREATE_LINK : "just_create_link"
|
14 | 12 | };
|
15 |
| - var Strophe, $iq, $msg, $pres, $build, b64_sha1, _ , dayjs, _converse, html, _, __, Model, BaseModal, jitsimeet_confirm, jitsimeet_invitation, jitsimeet_tab_invitation, jitsimeet_tab_invitation_mobile; |
16 |
| - var isMobile, spUtils = undefined; |
| 13 | + var Strophe, $iq, $msg, $pres, $build, b64_sha1, _ , dayjs, _converse, html, _, __, Model, BootstrapModal, jitsimeet_confirm, jitsimeet_invitation, jitsimeet_tab_invitation; |
| 14 | + var MeetDialog = null, meetDialog = null; |
17 | 15 |
|
18 | 16 | converse.plugins.add("jitsimeet", {
|
19 |
| - dependencies : ["silverpeas-commons"], |
| 17 | + dependencies: [], |
20 | 18 |
|
21 | 19 | initialize: function () {
|
22 |
| - const __context = {}; |
23 | 20 | _converse = this._converse;
|
24 | 21 |
|
25 |
| - spUtils = converse.env.spUtils; |
26 | 22 | Strophe = converse.env.Strophe;
|
27 | 23 | $iq = converse.env.$iq;
|
28 | 24 | $msg = converse.env.$msg;
|
|
32 | 28 | dayjs = converse.env.dayjs;
|
33 | 29 | html = converse.env.html;
|
34 | 30 | Model = converse.env.Model;
|
35 |
| - BaseModal = converse.env.BaseModal; |
| 31 | + BootstrapModal = converse.env.BootstrapModal; |
36 | 32 | _ = converse.env._;
|
37 |
| - __ = function(key) { |
38 |
| - switch (key) { |
39 |
| - case 'Jitsi Meet': |
40 |
| - return sp.i18n.get('chat.client.web.visio.button'); |
41 |
| - case 'Meeting?': |
42 |
| - const confirmMsg = sp.i18n.get('chat.client.web.visio.meeting.confirm'); |
43 |
| - const intoCharWindowOpt = sp.i18n.get('chat.client.web.visio.meeting.into.chat.window'); |
44 |
| - const intoNewTabOpt = sp.i18n.get('chat.client.web.visio.meeting.into.new.tab'); |
45 |
| - const justLinkOpt = sp.i18n.get('chat.client.web.visio.meeting.links'); |
46 |
| - const setStartOption = function(value) { |
47 |
| - _converse.api.settings.set("jitsimeet_start_option", value); |
48 |
| - }; |
49 |
| - const __startOptions = [{ |
50 |
| - id : 1, value : MEET_START_OPTIONS.INTO_CHAT_WINDOW, label : intoCharWindowOpt |
51 |
| - }, { |
52 |
| - id : 2, value : MEET_START_OPTIONS.INTO_NEW_TAB, label : intoNewTabOpt |
53 |
| - }, { |
54 |
| - id : 3, value : MEET_START_OPTIONS.JUST_CREATE_LINK, label : justLinkOpt |
55 |
| - }]; |
56 |
| - return converse.env.utils.getElementFromTemplateResult(html` |
57 |
| - <div class="form-container"> |
58 |
| - <div><span>${confirmMsg}</span></div> |
59 |
| - <div class="fields"> |
60 |
| - ${__startOptions |
61 |
| - .map(o => Object.assign(o, { |
62 |
| - checked : _converse.api.settings.get("jitsimeet_start_option") === o.value |
63 |
| - })) |
64 |
| - .map(o => html` |
65 |
| - <div><label> |
66 |
| - <input type="radio" name="start-option-choice" |
67 |
| - value="${o.id}" @click="${() => setStartOption(o.value)}" ?checked="${o.checked}"> |
68 |
| - <span>${o.label}</span> |
69 |
| - </label></div> |
70 |
| - `)} |
71 |
| - </div> |
72 |
| - </div>`); |
73 |
| - case 'Please join meeting in room at': |
74 |
| - return sp.i18n.get('chat.client.web.visio.link'); |
75 |
| - case 'Or open in new tab at': |
76 |
| - return sp.i18n.get('chat.client.web.visio.tab.link'); |
77 |
| - case 'Open meeting in new tab at': |
78 |
| - return sp.i18n.get('chat.client.web.visio.tab.link.mobile'); |
79 |
| - case 'A meet is already running into room': |
80 |
| - return sp.i18n.get('chat.client.web.visio.run.already'); |
81 |
| - default: |
82 |
| - return _converse.__(key); |
83 |
| - } |
84 |
| - }; |
85 |
| - isMobile = function() { |
86 |
| - if (typeof __context.isMobile === 'undefined') { |
87 |
| - __context.isMobile = _converse.api.settings.get('view_mode') === 'mobile'; |
88 |
| - } |
89 |
| - return __context.isMobile; |
90 |
| - } |
| 33 | + __ = _converse.__; |
91 | 34 |
|
92 | 35 | _converse.api.settings.update({
|
93 | 36 | jitsimeet_start_option: MEET_START_OPTIONS.INTO_CHAT_WINDOW,
|
94 | 37 | jitsimeet_head_display_toggle: false,
|
95 | 38 | jitsimeet_modal: false,
|
96 |
| - jitsimeet_url: window.SilverChatSettings ? window.SilverChatSettings.get('v.u') : 'https://meet.jit.si', |
| 39 | + jitsimeet_url: 'https://meet.jit.si', |
97 | 40 | });
|
98 | 41 |
|
99 | 42 | jitsimeet_confirm = __('Meeting?');
|
100 | 43 | jitsimeet_invitation = __('Please join meeting in room at');
|
101 | 44 | jitsimeet_tab_invitation = __('Or open in new tab at');
|
102 |
| - jitsimeet_tab_invitation_mobile = __('Open meeting in new tab at'); |
103 | 45 |
|
104 | 46 | _converse.api.listen.on('messageNotification', function (data)
|
105 | 47 | {
|
106 |
| - sp.log.debug("messageNotification", data); |
| 48 | + console.debug("messageNotification", data); |
107 | 49 |
|
108 | 50 | var chatbox = data.chatbox;
|
109 | 51 | var bodyElement = data.stanza.querySelector('body');
|
|
147 | 89 | }
|
148 | 90 | });
|
149 | 91 |
|
150 |
| - class MeetDialog extends BaseModal { |
| 92 | + MeetDialog = BootstrapModal.extend({ |
151 | 93 | initialize() {
|
152 |
| - BaseModal.prototype.initialize.apply(this, arguments); |
| 94 | + BootstrapModal.prototype.initialize.apply(this, arguments); |
153 | 95 | this.listenTo(this.model, 'change', this.render);
|
154 |
| - } |
155 |
| - |
| 96 | + }, |
156 | 97 | toHTML() {
|
157 |
| - const view = this.model.get("view"); |
158 |
| - const label = this.model.get("label"); |
159 |
| - const room = this.model.get("room"); |
160 |
| - const url = this.model.get("url"); |
| 98 | + var view = this.model.get("view"); |
| 99 | + var label = this.model.get("label"); |
| 100 | + var room = this.model.get("room"); |
| 101 | + var url = this.model.get("url"); |
161 | 102 |
|
162 | 103 | return html`
|
163 | 104 | <div class="modal-dialog modal-lg">
|
|
166 | 107 | <h4 class="modal-title">${label} ${room}</h4>
|
167 | 108 | </div>
|
168 | 109 | <div style="text-align: center;" class="modal-body"><iframe src="${url}" id="jitsimeet" allow="microphone; camera;" frameborder="0" seamless="seamless" allowfullscreen="true" scrolling="no" style="z-index: 2147483647;width:640px;height:480px;display: inline-block"></iframe></div>
|
169 |
| - <div class="modal-footer"> <button type="button" @click="${(ev) => this.terminateCall(ev)}" class="btn btn-danger btn-terminate" data-dismiss="modal">Close</button> </div> |
| 110 | + <div class="modal-footer"> <button type="button" class="btn btn-danger btn-terminate" data-dismiss="modal">Close</button> </div> |
170 | 111 | </div>
|
171 | 112 | </div>
|
172 |
| - `} |
173 |
| - |
| 113 | + `}, |
174 | 114 | afterRender() {
|
175 |
| - const that = this; |
176 |
| - this.addEventListener('shown.bs.modal', function() { |
177 |
| - that.querySelector('.modal-body').innerHTML = '<iframe src="' + that.model.get("url") + '" id="jitsimeet" allow="microphone; camera;" frameborder="0" seamless="seamless" allowfullscreen="true" scrolling="no" style="z-index: 2147483647;width:640px;height:480px;display: inline-block"></iframe>'; |
178 |
| - }, false); |
179 |
| - } |
| 115 | + var that = this; |
180 | 116 |
|
181 |
| - terminateCall(ev) { |
182 |
| - this.querySelector('.modal-body').innerHTML = ""; |
183 |
| - } |
| 117 | + this.el.addEventListener('shown.bs.modal', function() |
| 118 | + { |
| 119 | + that.el.querySelector('.modal-body').innerHTML = '<iframe src="' + that.model.get("url") + '" id="jitsimeet" allow="microphone; camera;" frameborder="0" seamless="seamless" allowfullscreen="true" scrolling="no" style="z-index: 2147483647;width:640px;height:480px;display: inline-block"></iframe>'; |
184 | 120 |
|
185 |
| - onHide () { |
186 |
| - super.onHide(); |
187 |
| - _converse.api.modal.remove(MEET_MODAL_DIALOG_ID); |
| 121 | + }, false); |
| 122 | + }, |
| 123 | + events: { |
| 124 | + "click .btn-terminate": "terminateCall" |
| 125 | + }, |
| 126 | + |
| 127 | + terminateCall() { |
| 128 | + this.el.querySelector('.modal-body').innerHTML = "about:blank" |
188 | 129 | }
|
189 |
| - } |
190 |
| - _converse.api.elements.define(MEET_MODAL_DIALOG_ID, MeetDialog); |
| 130 | + }); |
191 | 131 |
|
192 | 132 | _converse.api.listen.on('getToolbarButtons', function(toolbar_el, buttons)
|
193 | 133 | {
|
194 |
| - sp.log.debug("getToolbarButtons", toolbar_el.model.get("jid")); |
| 134 | + console.debug("getToolbarButtons", toolbar_el.model.get("jid")); |
195 | 135 | let color = "fill:var(--chat-toolbar-btn-color);";
|
196 | 136 | if (toolbar_el.model.get("type") === "chatroom") color = "fill:var(--muc-toolbar-btn-color);";
|
197 | 137 |
|
|
210 | 150 |
|
211 | 151 | if (pos > -1 && text.indexOf(_converse.api.settings.get("jitsimeet_url")) > -1)
|
212 | 152 | {
|
213 |
| - sp.log.debug("afterMessageBodyTransformed", text); |
| 153 | + console.debug("afterMessageBodyTransformed", text); |
214 | 154 |
|
215 | 155 | const url = text.substring(pos);
|
216 | 156 | const link_room = url.substring(url.lastIndexOf("/") + 1);
|
217 | 157 | const link_label = jitsimeet_invitation;
|
218 |
| - const tab_label = isMobile() ? jitsimeet_tab_invitation_mobile : jitsimeet_tab_invitation; |
| 158 | + const tab_label = jitsimeet_tab_invitation; |
219 | 159 |
|
220 | 160 | text.references = [];
|
221 |
| - if (isMobile()) { |
222 |
| - text.addTemplateResult(0, text.length, |
223 |
| - html`<a target="_blank" rel="noopener noreferrer" |
224 |
| - href="${url}">${tab_label} ${url}</a>`); |
225 |
| - } else { |
226 |
| - text.addTemplateResult(0, text.length, html`<a |
227 |
| - @click=${clickVideo} data-room="${link_room}" data-url="${url}" |
228 |
| - href="#">${link_label} ${link_room}</a><br/><a target="_blank" rel="noopener noreferrer" |
229 |
| - href="${url}">${tab_label} ${url}</a>`); |
230 |
| - } |
| 161 | + text.addTemplateResult(0, text.length, html`<a |
| 162 | + @click=${clickVideo} data-room="${link_room}" data-url="${url}" |
| 163 | + href="#">${link_label} ${link_room}</a><br/><a target="_blank" rel="noopener noreferrer" |
| 164 | + href="${url}">${tab_label} ${url}</a>`); |
231 | 165 | }
|
232 | 166 | });
|
233 | 167 |
|
234 |
| - sp.log.debug("jitsimeet plugin is ready"); |
| 168 | + console.debug("jitsimeet plugin is ready"); |
235 | 169 | }
|
236 | 170 | });
|
237 | 171 |
|
238 | 172 | function __confirm(msg, callback) {
|
239 |
| - $.popup.confirm(msg, callback); |
| 173 | + if (confirm(jitsimeet_confirm)) { |
| 174 | + callback(); |
| 175 | + } |
240 | 176 | }
|
241 | 177 |
|
242 | 178 | function __displayError(error) {
|
243 |
| - SilverpeasError.add(error).show(); |
| 179 | + alert(error); |
| 180 | + } |
| 181 | + |
| 182 | + function getChatViewFromElement($el) { |
| 183 | + return $el.closest('converse-chat.chatbox') || $el.closest('converse-muc.chatbox'); |
244 | 184 | }
|
245 | 185 |
|
246 | 186 | function performVideo(ev)
|
247 | 187 | {
|
248 | 188 | ev.stopPropagation();
|
249 | 189 | ev.preventDefault();
|
250 | 190 |
|
251 |
| - const chatView = spUtils.getChatViewFromElement(ev.currentTarget); |
252 |
| - if (!isMobile()) { |
253 |
| - __confirm(jitsimeet_confirm, function() { |
| 191 | + const chatView = getChatViewFromElement(ev.currentTarget); |
| 192 | + __confirm(jitsimeet_confirm, function() { |
254 | 193 | doVideo(chatView);
|
255 |
| - }); |
256 |
| - } else { |
257 |
| - _converse.api.settings.set("jitsimeet_start_option", MEET_START_OPTIONS.INTO_NEW_TAB); |
258 |
| - doVideo(chatView); |
259 |
| - } |
| 194 | + }); |
260 | 195 | }
|
261 | 196 |
|
262 | 197 | function clickVideo(ev)
|
|
268 | 203 | var room = ev.target.getAttribute("data-room");
|
269 | 204 |
|
270 | 205 | if (ev.currentTarget) {
|
271 |
| - const chatView = spUtils.getChatViewFromElement(ev.currentTarget); |
| 206 | + const chatView = getChatViewFromElement(ev.currentTarget); |
272 | 207 | doLocalVideo(chatView, room, url, jitsimeet_invitation);
|
273 | 208 | }
|
274 | 209 | }
|
|
278 | 213 | const room = Strophe.getNodeFromJid(view.model.attributes.jid).toLowerCase().replace(/[\\]/g, '') + "-" + Math.random().toString(36).substr(2,9);
|
279 | 214 | const url = _converse.api.settings.get("jitsimeet_url") + '/' + room;
|
280 | 215 |
|
281 |
| - sp.log.debug("doVideo", room, url, view); |
| 216 | + console.debug("doVideo", room, url, view); |
282 | 217 |
|
283 | 218 | view.model.sendMessage({'body': url});
|
284 | 219 | const startOption = _converse.api.settings.get("jitsimeet_start_option");
|
|
291 | 226 |
|
292 | 227 | var doNewTabVideo = function doNewTabVideo(url)
|
293 | 228 | {
|
294 |
| - sp.log.debug("doNewTabVideo", url); |
| 229 | + console.debug("doNewTabVideo", url); |
295 | 230 | var newTabVideoLink = document.createElement('a');
|
296 | 231 | Object.assign(newTabVideoLink, {
|
297 | 232 | target: '_blank',
|
|
304 | 239 | var doLocalVideo = function doLocalVideo(view, room, url, label)
|
305 | 240 | {
|
306 | 241 | const chatModel = view.model;
|
307 |
| - sp.log.debug("doLocalVideo", view, room, url, label); |
| 242 | + console.debug("doLocalVideo", view, room, url, label); |
308 | 243 |
|
309 | 244 | var modal = _converse.api.settings.get("jitsimeet_modal") === true;
|
310 | 245 |
|
311 | 246 | if (modal)
|
312 | 247 | {
|
313 |
| - _converse.api.modal.show(MEET_MODAL_DIALOG_ID, { |
314 |
| - 'model' : new converse.env.Model({ |
315 |
| - 'view' : view, |
316 |
| - 'url': url, |
317 |
| - 'label' : label, |
318 |
| - 'room': room, |
319 |
| - }) |
320 |
| - }); |
| 248 | + meetDialog = new MeetDialog({'model': new converse.env.Model({})}); |
| 249 | + meetDialog.model.set("view", view); |
| 250 | + meetDialog.model.set("url", url); |
| 251 | + meetDialog.model.set("label", label); |
| 252 | + meetDialog.model.set("room", room); |
| 253 | + meetDialog.show(); |
321 | 254 | }
|
322 | 255 | else {
|
323 | 256 |
|
|
440 | 373 | }
|
441 | 374 | let jitsiIframeCloseHandler = function ()
|
442 | 375 | {
|
443 |
| - sp.log.debug("doVideo - load", this); |
| 376 | + console.debug("doVideo - load", this); |
444 | 377 | if (!firstTime) // meeting closed and root url is loaded
|
445 | 378 | {
|
446 | 379 | closeJitsi();
|
|
0 commit comments