|
1 |
| -/* global config, getRoomName, getConfigParamsFromUrl */ |
2 |
| -/* global createConnectionExternally */ |
| 1 | +/* global config, |
| 2 | + createConnectionExternally, |
| 3 | + getConfigParamsFromUrl, |
| 4 | + getRoomName */ |
| 5 | + |
3 | 6 | /**
|
4 |
| - * Implements extrnal connect using createConnectionExtenally function defined |
| 7 | + * Implements external connect using createConnectionExternally function defined |
5 | 8 | * in external_connect.js for Jitsi Meet. Parses the room name and token from
|
6 |
| - * the url and executes createConnectionExtenally. |
| 9 | + * the URL and executes createConnectionExternally. |
7 | 10 | *
|
8 | 11 | * NOTE: If you are using lib-jitsi-meet without Jitsi Meet you should use this
|
9 |
| - * file as reference only because the implementation is Jitsi Meet specific. |
| 12 | + * file as reference only because the implementation is Jitsi Meet-specific. |
10 | 13 | *
|
11 | 14 | * NOTE: For optimal results this file should be included right after
|
12 |
| - * exrnal_connect.js. |
| 15 | + * external_connect.js. |
13 | 16 | */
|
14 | 17 |
|
15 |
| -/** |
16 |
| - * Executes createConnectionExternally function. |
17 |
| - */ |
18 |
| -(function () { |
19 |
| - var hashParams = getConfigParamsFromUrl("hash", true); |
20 |
| - var searchParams = getConfigParamsFromUrl("search", true); |
| 18 | +const hashParams = getConfigParamsFromUrl('hash', true); |
| 19 | +const searchParams = getConfigParamsFromUrl('search', true); |
21 | 20 |
|
22 |
| - //Url params have higher proirity than config params |
23 |
| - var url = config.externalConnectUrl; |
24 |
| - if(hashParams.hasOwnProperty('config.externalConnectUrl')) |
25 |
| - url = hashParams["config.externalConnectUrl"]; |
| 21 | +// URL params have higher proirity than config params. |
| 22 | +let url |
| 23 | + = hashParams.hasOwnProperty('config.externalConnectUrl') |
| 24 | + ? hashParams['config.externalConnectUrl'] |
| 25 | + : config.externalConnectUrl; |
26 | 26 |
|
27 |
| - /** |
28 |
| - * Check if connect from connection.js was executed and executes the handler |
29 |
| - * that is going to finish the connect work. |
30 |
| - */ |
31 |
| - function checkForConnectHandlerAndConnect() { |
| 27 | +if (url && window.createConnectionExternally) { |
| 28 | + const roomName = getRoomName(); |
32 | 29 |
|
33 |
| - if(window.APP && window.APP.connect.status === "ready") { |
34 |
| - window.APP.connect.handler(); |
35 |
| - } |
36 |
| - } |
| 30 | + if (roomName) { |
| 31 | + url += `?room=${roomName}`; |
37 | 32 |
|
38 |
| - function error_callback(error){ |
39 |
| - if(error) //error=undefined if external connect is disabled. |
40 |
| - console.warn(error); |
41 |
| - // Sets that global variable to be used later by connect method in |
42 |
| - // connection.js |
43 |
| - window.XMPPAttachInfo = { |
44 |
| - status: "error" |
45 |
| - }; |
46 |
| - checkForConnectHandlerAndConnect(); |
47 |
| - } |
| 33 | + const token |
| 34 | + = hashParams['config.token'] || config.token || searchParams.jwt; |
48 | 35 |
|
49 |
| - if(!url || !window.createConnectionExternally) { |
50 |
| - error_callback(); |
51 |
| - return; |
52 |
| - } |
53 |
| - var room_name = getRoomName(); |
54 |
| - if(!room_name) { |
55 |
| - error_callback(); |
56 |
| - return; |
| 36 | + if (token) { |
| 37 | + url += `&token=${token}`; |
| 38 | + } |
| 39 | + |
| 40 | + createConnectionExternally( |
| 41 | + url, |
| 42 | + connectionInfo => { |
| 43 | + // Sets that global variable to be used later by connect method |
| 44 | + // in connection.js. |
| 45 | + window.XMPPAttachInfo = { |
| 46 | + status: 'success', |
| 47 | + data: connectionInfo |
| 48 | + }; |
| 49 | + checkForConnectHandlerAndConnect(); |
| 50 | + }, |
| 51 | + errorCallback); |
| 52 | + } else { |
| 53 | + errorCallback(); |
57 | 54 | }
|
| 55 | +} else { |
| 56 | + errorCallback(); |
| 57 | +} |
58 | 58 |
|
59 |
| - url += "?room=" + room_name; |
| 59 | +/** |
| 60 | + * Check if connect from connection.js was executed and executes the handler |
| 61 | + * that is going to finish the connect work. |
| 62 | + * |
| 63 | + * @returns {void} |
| 64 | + */ |
| 65 | +function checkForConnectHandlerAndConnect() { |
| 66 | + window.APP |
| 67 | + && window.APP.connect.status === 'ready' |
| 68 | + && window.APP.connect.handler(); |
| 69 | +} |
60 | 70 |
|
61 |
| - var token = hashParams["config.token"] || config.token || |
62 |
| - searchParams.jwt; |
63 |
| - if(token) |
64 |
| - url += "&token=" + token; |
| 71 | +/** |
| 72 | + * Implements a callback to be invoked if anything goes wrong. |
| 73 | + * |
| 74 | + * @param {Error} error - The specifics of what went wrong. |
| 75 | + * @returns {void} |
| 76 | + */ |
| 77 | +function errorCallback(error) { |
| 78 | + // The value of error is undefined if external connect is disabled. |
| 79 | + error && console.warn(error); |
65 | 80 |
|
66 |
| - createConnectionExternally(url, function(connectionInfo) { |
67 |
| - // Sets that global variable to be used later by connect method in |
68 |
| - // connection.js |
69 |
| - window.XMPPAttachInfo = { |
70 |
| - status: "success", |
71 |
| - data: connectionInfo |
72 |
| - }; |
73 |
| - checkForConnectHandlerAndConnect(); |
74 |
| - }, error_callback); |
75 |
| -})(); |
| 81 | + // Sets that global variable to be used later by connect method in |
| 82 | + // connection.js. |
| 83 | + window.XMPPAttachInfo = { |
| 84 | + status: 'error' |
| 85 | + }; |
| 86 | + checkForConnectHandlerAndConnect(); |
| 87 | +} |
0 commit comments