@digitalsamba/embedded-sdk 0.0.19 → 0.0.21

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.
@@ -0,0 +1,305 @@
1
+
2
+ html, body, div, span, applet, object, iframe,
3
+ h1, h2, h3, h4, h5, h6, p, blockquote, pre,
4
+ a, abbr, acronym, address, big, cite, code,
5
+ del, dfn, em, img, ins, kbd, q, s, samp,
6
+ small, strike, strong, sub, sup, tt, var,
7
+ b, u, i, center,
8
+ dl, dt, dd, ol, ul, li,
9
+ fieldset, form, label, legend,
10
+ table, caption, tbody, tfoot, thead, tr, th, td,
11
+ article, aside, canvas, details, embed,
12
+ figure, figcaption, footer, header, hgroup,
13
+ menu, nav, output, ruby, section, summary,
14
+ time, mark, audio, video {
15
+ margin: 0;
16
+ padding: 0;
17
+ border: 0;
18
+ font-size: 100%;
19
+ font: inherit;
20
+ vertical-align: baseline;
21
+ }
22
+ button {
23
+ cursor: pointer;
24
+ }
25
+ /* HTML5 display-role reset for older browsers */
26
+ article, aside, details, figcaption, figure,
27
+ footer, header, hgroup, menu, nav, section {
28
+ display: block;
29
+ }
30
+ body {
31
+ color: rgb(50, 63, 102);
32
+ line-height: 1;
33
+ }
34
+ ol, ul {
35
+ list-style: none;
36
+ }
37
+ blockquote, q {
38
+ quotes: none;
39
+ }
40
+ blockquote:before, blockquote:after,
41
+ q:before, q:after {
42
+ content: '';
43
+ content: none;
44
+ }
45
+ table {
46
+ border-collapse: collapse;
47
+ border-spacing: 0;
48
+ }
49
+
50
+ body {
51
+ background: #f4f5f8;
52
+ font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
53
+ }
54
+
55
+ .topbar {
56
+ background: #fff;
57
+ box-shadow: 0 8px 16px rgba(34,35,38,.05), 0 4px 8px rgba(34,35,38,.05);
58
+ }
59
+
60
+ a {
61
+ font-size: 16px;
62
+ color: rgb(55, 113, 224);
63
+ text-decoration: none;
64
+ }
65
+
66
+ .user-list-row {
67
+ display: flex;
68
+ margin: 12px 0 8px;
69
+ align-items: center;
70
+ }
71
+
72
+ .user-list-avatar {
73
+ width: 24px;
74
+ height: 24px;
75
+ display: block;
76
+ border-radius: 50%;
77
+ margin-right: 8px;
78
+ text-align: center;
79
+ font-size: 20px;
80
+ line-height: 1;
81
+ color: #fff;
82
+ }
83
+
84
+ .speaker-indicator {
85
+ width: 8px;
86
+ height: 8px;
87
+ display: block;
88
+ border-radius: 50%;
89
+ margin-right: 8px;
90
+ background: #4cd964;
91
+ opacity: 0;
92
+ margin-left: 8px;
93
+ }
94
+
95
+ .speaker-indicator.show {
96
+ opacity: 1
97
+ }
98
+
99
+ .container {
100
+ padding: 0 15px;
101
+ display: flex;
102
+ flex-grow: 1;
103
+ flex-wrap: wrap;
104
+ }
105
+
106
+ .topbar .container {
107
+ padding: 7.5px 15px;
108
+ align-items: center;
109
+ justify-content: space-between;
110
+ }
111
+
112
+ .logo {
113
+ width: 327px;
114
+ border-width: 0px;
115
+ border: 0px;
116
+ height: auto;
117
+ max-width: 100%;
118
+ vertical-align: middle;
119
+ }
120
+
121
+ .room-content {
122
+ display: flex;
123
+ }
124
+
125
+ .screen {
126
+ display: none;
127
+ min-height: calc(100vh - 75px);
128
+ }
129
+
130
+ .screen.show {
131
+ display: flex;
132
+ }
133
+
134
+ .room-url-field .container {
135
+ display: flex;
136
+ flex-direction: column;
137
+ align-items: center;
138
+ justify-content: center;
139
+ }
140
+
141
+ .room-url-field label {
142
+ margin-bottom: 10px;
143
+ display: block;
144
+ }
145
+ .room-url-field label b {
146
+ font-size: 18px;
147
+
148
+ display: block;
149
+ margin-bottom: 5px;
150
+ font-weight: 700;
151
+ }
152
+
153
+ .checkbox-label {
154
+ display: flex;
155
+ align-items: center;
156
+ margin-right: 15px;
157
+ }
158
+
159
+ .room-url-field label.radio-label {
160
+ margin: 0;
161
+ margin-right: 8px;
162
+ }
163
+
164
+ .init-settings-title {
165
+ font-size: 18px;
166
+ font-weight: 700;
167
+ margin-bottom: 5px;
168
+ }
169
+
170
+ .room-url-field input[type=text] {
171
+ border: 2px solid rgb(50, 63, 102);
172
+ margin-bottom: 10px;
173
+ border-radius: 8px;
174
+ width: 420px;
175
+ padding: 8px;
176
+ font-size: 14px;
177
+ }
178
+
179
+ .room-url-field select {
180
+ border: 2px solid rgb(50, 63, 102);
181
+ margin-bottom: 10px;
182
+ border-radius: 8px;
183
+ padding: 8px;
184
+ font-size: 14px;
185
+ }
186
+
187
+ .room-url-error {
188
+ color: crimson;
189
+ }
190
+
191
+ .room-url-field button {
192
+ margin-bottom: 10px;
193
+ border-radius: 8px;
194
+ padding: 8px 16px;
195
+ background: rgb(55, 113, 224);
196
+ border: 2px solid rgb(55, 113, 224);
197
+ color: #fff;
198
+ font-size: 14px;
199
+ text-transform: uppercase;
200
+ }
201
+
202
+ .room-url-field .vertical {
203
+ display: flex;
204
+ flex-direction: column;
205
+ }
206
+ .room-content {
207
+ flex-grow: 1;
208
+ align-items: flex-start;
209
+ max-width: 100%;
210
+ }
211
+
212
+ .room-frame {
213
+ align-items: flex-start;
214
+ }
215
+
216
+ .room-frame .container {
217
+ padding: 15px 15px;
218
+ }
219
+
220
+ .sidebar {
221
+ padding-left: 15px;
222
+ flex-grow: 1;
223
+ max-width: calc(100vw - 1055px);
224
+ }
225
+
226
+ .sidebar-block {
227
+ border: 1px solid #dfdfdf;
228
+ background: #fff;
229
+ padding: 15px;
230
+ border-radius: 8px;
231
+ margin-bottom: 15px;
232
+ }
233
+ .hint-title {
234
+ margin-bottom: 10px;
235
+ }
236
+ .hint-link-url {
237
+ font-size: 18px;
238
+ font-weight: 700;
239
+ margin-bottom: 10px;
240
+ word-wrap: break-word;
241
+ line-height: 1.25;
242
+ }
243
+
244
+ .logs-toggle {
245
+ background: none;
246
+ border: none;
247
+ color: rgb(55, 113, 224);
248
+ margin-bottom: 7.5px;
249
+ }
250
+
251
+ .log-list {
252
+ max-height: 60vh;
253
+ overflow-y: auto;
254
+ word-wrap: break-word;
255
+ }
256
+
257
+ .log-list div {
258
+ max-width: 90%;
259
+ }
260
+
261
+ .log-list p {
262
+ font-size: 14px;
263
+ margin-bottom: 4px;
264
+ }
265
+ .log-list b {
266
+ font-weight: 700;
267
+ }
268
+
269
+ .frame-controls {
270
+ margin-top: 15px;
271
+ }
272
+
273
+ .frame-controls button {
274
+ border-radius: 8px;
275
+ padding: 8px 16px;
276
+ background: #fff;
277
+ border: 2px solid rgb(55, 113, 224);
278
+ color: rgb(55, 113, 224);
279
+ font-size: 14px;
280
+ text-transform: uppercase;
281
+ margin-right: 8px;
282
+ }
283
+
284
+ .vb-value {
285
+ display: none;
286
+ }
287
+ .vb-value.show {
288
+ display: block;
289
+ }
290
+
291
+ .participants {
292
+ display: none;
293
+ }
294
+ .participants.show {
295
+ display: block
296
+ }
297
+
298
+ .user-list-row button {
299
+ margin: 0px 4px;
300
+ font-size: 14px;
301
+ border: none;
302
+ background: none;
303
+ font-weight: 700;
304
+ color: rgb(55, 113, 224);
305
+ }
@@ -0,0 +1,137 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
6
+ <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
+ <title>Simple videoroom</title>
8
+ <script src="./index.js"></script>
9
+ <script src="./helper.js"></script>
10
+ <link rel="stylesheet" href="./style.css">
11
+ </head>
12
+
13
+ <body>
14
+ <nav class="topbar">
15
+ <div class="container">
16
+ <img class="logo" src="logo.png" alt="DigitalSamba">
17
+ <a href="https://github.com/digitalsamba/embedded-sdk" target="_blank" rel="noopener nofollow">View on GitHub</a>
18
+ </div>
19
+ </nav>
20
+
21
+
22
+ <div class="screen room-url-field show">
23
+ <div class="container">
24
+ <div class="vertical">
25
+ <label for="custom-room-url">
26
+ <span><b>Room URL</b></span>
27
+ <span>Can be found in <a href="https://dashboard.digitalsamba.com/" target="_blank" rel="noopener nofollow">dashboard</a></span>.
28
+ </label>
29
+ <div>
30
+ <input type="text" id="custom-room-url" name="custom-room-url" onkeydown="onURLChange()">
31
+ <!-- kicks off loading -->
32
+ <button onclick="loadCustomRoom()">load room</button>
33
+ </div>
34
+ <p class="room-url-error"></p>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ <div class="screen room-frame">
39
+ <div class="container">
40
+ <div class="room-content">
41
+ <div class="frame-area">
42
+ <div class="frame-parent">
43
+ <!-- our frame will load here -->
44
+ </div>
45
+ <div class="frame-controls" style="display: none">
46
+ <button onclick="sambaEmbedded.toggleVideo()">toggle video</button>
47
+ <button onclick="sambaEmbedded.toggleAudio()">toggle audio</button>
48
+ <button onclick="sambaEmbedded.toggleToolbar()">toggle toolbar</button>
49
+ </div>
50
+ </div>
51
+ <div class="sidebar"></div>
52
+ </div>
53
+ </div>
54
+
55
+ </div>
56
+
57
+ <script async defer>
58
+ let ROOM_URL = 'https://localhost:3000/Public';
59
+
60
+ var sambaEmbedded;
61
+
62
+ // if room is predefined in search params, skip room URL field;
63
+ checkDynamicRoomURL();
64
+
65
+ function loadCustomRoom() {
66
+ const input = document.querySelector('#custom-room-url');
67
+
68
+ if(input.value) {
69
+ ROOM_URL = input.value;
70
+ loadRoom();
71
+ } else {
72
+ updateError('Please enter room URL')
73
+ }
74
+ }
75
+
76
+ function loadRoom() {
77
+ try {
78
+ const parent = document.querySelector('.frame-parent');
79
+ parent.innerHTML = null;
80
+
81
+ // create pre-configured controller instance using given URL;
82
+ // if no frame specified, this pre-creates a frame but doesn't load it yet;
83
+ // other init strategies are available, along with more detailed customization
84
+ // see https://docs.digitalsamba.com/reference/sdk/digitalsambaembedded-class
85
+ sambaEmbedded = DigitalSambaEmbedded.createControl(
86
+ { url: ROOM_URL, root: parent, roomSettings: {showToolbar: false} },
87
+ {reportErrors: true}
88
+ );
89
+
90
+ // controller instance exposes the frame, so we can customize it a little bit
91
+ sambaEmbedded.frame.width = 1000;
92
+ sambaEmbedded.frame.height = 700;
93
+ sambaEmbedded.frame.style.border = '5px solid #f06859';
94
+ sambaEmbedded.frame.style.borderRadius = '8px';
95
+
96
+ // load samba frame
97
+ sambaEmbedded.load();
98
+
99
+ addJoiningHint(ROOM_URL);
100
+ initializeLogs();
101
+
102
+ // after loading, controller will start emitting events
103
+ // event listeners can be set up prior to loading;
104
+ setupCustomEventListeners();
105
+
106
+ showScreen('.room-frame');
107
+ } catch (e) {
108
+ updateError(e.message)
109
+ }
110
+ }
111
+
112
+ function setupCustomEventListeners() {
113
+ // catch all events. Useful for logging or debugging;
114
+ sambaEmbedded.on('*', (data) => {
115
+ const logList = document.querySelector('.log-list');
116
+
117
+ if(logList) {
118
+ logList.innerHTML += `<div>
119
+ <p>[${(new Date).toLocaleTimeString()}] event: <b>${data?.type}</b></p>
120
+ ${data.data ? `<p>payload: ${JSON.stringify(data.data)}</p>` : ''}
121
+ </div>`;
122
+
123
+ logList.scrollTop = logList.scrollHeight;
124
+ }
125
+ })
126
+
127
+ // `roomJoined` is fired when local user has joined the room
128
+ // this listener is used to display media device controls after joining
129
+ sambaEmbedded.on('roomJoined', () => {
130
+ const controls = document.querySelector('.frame-controls');
131
+
132
+ controls.style.display = 'flex';
133
+ })
134
+ }
135
+ </script>
136
+ </body>
137
+ </html>
@@ -14,7 +14,7 @@ export declare class DigitalSambaEmbedded extends EventEmitter implements Embedd
14
14
  stored: Stored;
15
15
  permissionManager: PermissionManager;
16
16
  constructor(options?: Partial<InitOptions>, instanceProperties?: Partial<InstanceProperties>, loadImmediately?: boolean);
17
- static createControl: (initOptions: InitOptions) => DigitalSambaEmbedded;
17
+ static createControl: (initOptions: Partial<InitOptions>, instanceProperties?: InstanceProperties) => DigitalSambaEmbedded;
18
18
  private mountFrame;
19
19
  load: (instanceProperties?: InstanceProperties) => void;
20
20
  private onMessage;
@@ -66,3 +66,4 @@ export declare class DigitalSambaEmbedded extends EventEmitter implements Embedd
66
66
  enableVirtualBackground: (options: VirtualBackgroundOptions) => void;
67
67
  disableVirtualBackground: () => void;
68
68
  }
69
+ export default DigitalSambaEmbedded;
package/dist/esm/index.js CHANGED
@@ -3,7 +3,7 @@ import EventEmitter from 'events';
3
3
  import { PermissionManager } from './utils/PermissionManager';
4
4
  import { CONNECT_TIMEOUT, defaultStoredState, internalEvents, } from './utils/vars';
5
5
  import { createWatchedProxy } from './utils/proxy';
6
- import { ALLOW_ATTRIBUTE_MISSING, INVALID_CONFIG, INVALID_URL, UNKNOWN_TARGET, } from './utils/errors';
6
+ import { ALLOW_ATTRIBUTE_MISSING, INVALID_CONFIG, INVALID_URL, INSECURE_CONTEXT, UNKNOWN_TARGET, } from './utils/errors';
7
7
  export class DigitalSambaEmbedded extends EventEmitter {
8
8
  constructor(options = {}, instanceProperties = {}, loadImmediately = true) {
9
9
  super();
@@ -31,7 +31,11 @@ export class DigitalSambaEmbedded extends EventEmitter {
31
31
  }
32
32
  if (url || (this.frame.src && this.frame.src !== window.location.href)) {
33
33
  try {
34
- const frameSrc = new URL(url || this.frame.src).toString();
34
+ let origString = url || this.frame.src;
35
+ if (!origString.includes('https://')) {
36
+ origString = 'https://' + origString;
37
+ }
38
+ const frameSrc = new URL(origString).toString();
35
39
  this.frame.src = frameSrc;
36
40
  this.savedIframeSrc = frameSrc;
37
41
  }
@@ -206,7 +210,9 @@ export class DigitalSambaEmbedded extends EventEmitter {
206
210
  this.frame.src = url;
207
211
  }
208
212
  else {
209
- this.logError(INVALID_CONFIG);
213
+ if (!this.initOptions.url) {
214
+ this.logError(INVALID_CONFIG);
215
+ }
210
216
  return;
211
217
  }
212
218
  const allowedURL = new URL(this.frame.src);
@@ -220,6 +226,9 @@ export class DigitalSambaEmbedded extends EventEmitter {
220
226
  if (this.reportErrors) {
221
227
  throw error;
222
228
  }
229
+ else {
230
+ console.error(error);
231
+ }
223
232
  };
224
233
  this.applyFrameProperties = (instanceProperties) => {
225
234
  if (instanceProperties.frameAttributes) {
@@ -344,18 +353,14 @@ export class DigitalSambaEmbedded extends EventEmitter {
344
353
  this.getUser = (userId) => { var _b; return (_b = this.stored.users) === null || _b === void 0 ? void 0 : _b[userId]; };
345
354
  this.showCaptions = () => {
346
355
  this.roomSettings.showCaptions = true;
347
- this.stored.roomState.captionsState.showCaptions = true;
348
356
  this.sendMessage({ type: 'showCaptions' });
349
357
  };
350
358
  this.hideCaptions = () => {
351
359
  this.roomSettings.showCaptions = false;
352
- this.stored.roomState.captionsState.showCaptions = false;
353
360
  this.sendMessage({ type: 'hideCaptions' });
354
361
  };
355
362
  this.toggleCaptions = (show) => {
356
363
  if (typeof show === 'undefined') {
357
- this.stored.roomState.captionsState.showCaptions =
358
- !this.stored.roomState.captionsState.showCaptions;
359
364
  this.sendMessage({ type: 'toggleCaptions' });
360
365
  }
361
366
  else if (show) {
@@ -401,15 +406,16 @@ export class DigitalSambaEmbedded extends EventEmitter {
401
406
  optionsToState.value = options[value];
402
407
  }
403
408
  });
404
- this.stored.roomState.virtualBackground = optionsToState;
405
409
  this.sendMessage({ type: 'configureVirtualBackground', data: options || {} });
406
410
  };
407
411
  this.enableVirtualBackground = (options) => this.configureVirtualBackground(options);
408
412
  this.disableVirtualBackground = () => {
409
413
  this.roomSettings.virtualBackground = undefined;
410
- this.stored.roomState.virtualBackground = { enabled: false };
411
414
  this.sendMessage({ type: 'disableVirtualBackground' });
412
415
  };
416
+ if (!window.isSecureContext) {
417
+ this.logError(INSECURE_CONTEXT);
418
+ }
413
419
  this.initOptions = options;
414
420
  this.roomSettings = options.roomSettings || {};
415
421
  this.reportErrors = instanceProperties.reportErrors || false;
@@ -454,4 +460,5 @@ export class DigitalSambaEmbedded extends EventEmitter {
454
460
  }
455
461
  }
456
462
  _a = DigitalSambaEmbedded;
457
- DigitalSambaEmbedded.createControl = (initOptions) => new _a(initOptions, {}, false);
463
+ DigitalSambaEmbedded.createControl = (initOptions, instanceProperties = {}) => new _a(initOptions, instanceProperties, false);
464
+ export default DigitalSambaEmbedded;