@reactoo/watchtogether-sdk-js 2.5.32 → 2.5.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,26 @@ let generateUUID = function () {
27
27
  });
28
28
  };
29
29
 
30
+
31
+ const janusDisplayDelimiter = ',';
32
+ const decodeJanusDisplay = display => {
33
+ let output = { userId: null, role: "participant", start: Date.now(), displayName: "?" };
34
+ if(display && typeof display === "string") {
35
+ if(display.indexOf(janusDisplayDelimiter) >= 0) {
36
+ let values = display
37
+ .split( new RegExp(`\\${janusDisplayDelimiter}(?=(?:(?:[^"]*"){2})*[^"]*$)`, 'mi') )
38
+ .map(v => (v && v.startsWith('"') || v.endsWith('"')) ? v.substring(1, v.length-1) : ( /^\d+$/.test(v) ? parseInt(v) : v ));
39
+ Object.keys(output).forEach((key, i) => values[i] ? output[key] = values[i] : null);
40
+ } else {
41
+ output.userId = display;
42
+ }
43
+ return output;
44
+ } else if(display && typeof display === "object") {
45
+ return Object.assign({}, output, display);
46
+ }
47
+ return null;
48
+ }
49
+
30
50
  const setExactTimeout = function(callback, duration, resolution) {
31
51
  const start = (new Date()).getTime();
32
52
  const timeout = setInterval(function(){
@@ -43,4 +63,6 @@ const clearExactTimeout = function(timeout) {
43
63
  clearInterval(timeout);
44
64
  };
45
65
 
46
- export {wait, getBrowserFingerprint, generateUUID, setExactTimeout, clearExactTimeout}
66
+
67
+
68
+ export {wait, getBrowserFingerprint, generateUUID, decodeJanusDisplay, setExactTimeout, clearExactTimeout}