@flashphoner/sfusdk-examples 2.0.56

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.
Files changed (40) hide show
  1. package/README.md +43 -0
  2. package/package.json +32 -0
  3. package/src/client/chat.js +67 -0
  4. package/src/client/config.json +26 -0
  5. package/src/client/controls.js +314 -0
  6. package/src/client/display.js +502 -0
  7. package/src/client/main.css +45 -0
  8. package/src/client/main.html +220 -0
  9. package/src/client/main.js +157 -0
  10. package/src/client/resources/details_close.png +0 -0
  11. package/src/client/resources/details_open.png +0 -0
  12. package/src/client/util.js +67 -0
  13. package/src/commons/js/config.js +81 -0
  14. package/src/commons/js/display.js +484 -0
  15. package/src/commons/js/util.js +202 -0
  16. package/src/commons/media/silence.mp3 +0 -0
  17. package/src/controller/dependencies/sigma/sigma.renderers.edgeLabels.min.js +1 -0
  18. package/src/controller/dependencies/sigma/sigma.renderers.parallelEdges.min.js +1 -0
  19. package/src/controller/dependencies/sigma/sigma.require.js +12076 -0
  20. package/src/controller/graph-view.js +32 -0
  21. package/src/controller/main.css +45 -0
  22. package/src/controller/main.html +79 -0
  23. package/src/controller/main.js +65 -0
  24. package/src/controller/parser.js +202 -0
  25. package/src/controller/resources/details_close.png +0 -0
  26. package/src/controller/resources/details_open.png +0 -0
  27. package/src/controller/rest.js +56 -0
  28. package/src/controller/table-view.js +64 -0
  29. package/src/controller/test-data.js +382 -0
  30. package/src/player/config.json +8 -0
  31. package/src/player/player.css +19 -0
  32. package/src/player/player.html +54 -0
  33. package/src/player/player.js +209 -0
  34. package/src/sfu.ts +28 -0
  35. package/src/two-way-streaming/config.json +34 -0
  36. package/src/two-way-streaming/two-way-streaming.css +26 -0
  37. package/src/two-way-streaming/two-way-streaming.html +72 -0
  38. package/src/two-way-streaming/two-way-streaming.js +375 -0
  39. package/tsconfig.json +15 -0
  40. package/webpack.config.js +40 -0
@@ -0,0 +1,382 @@
1
+ 'use strict'
2
+
3
+ const testStats = {
4
+ "participants": [
5
+ {
6
+ "nickName": "Alice",
7
+ "outgoingTracks": [
8
+ {
9
+ "id": "60bbba84-6b95-4d7f-a8b9-5d38bf972605",
10
+ "composite": true,
11
+ "tracks": {
12
+ "h send": {
13
+ "id": "60bbba84-6b95-4d7f-a8b9-5d38bf972605",
14
+ "codec": "VP8",
15
+ "width": 960,
16
+ "height": 540,
17
+ "fps": 12,
18
+ "bitrate": 544816,
19
+ "alive": true,
20
+ "type": "VIDEO"
21
+ },
22
+ "m send": {
23
+ "id": "60bbba84-6b95-4d7f-a8b9-5d38bf972605",
24
+ "codec": "VP8",
25
+ "width": 480,
26
+ "height": 270,
27
+ "fps": 13,
28
+ "bitrate": 275872,
29
+ "alive": true,
30
+ "type": "VIDEO"
31
+ },
32
+ "l send": {
33
+ "id": "60bbba84-6b95-4d7f-a8b9-5d38bf972605",
34
+ "codec": "VP8",
35
+ "width": 240,
36
+ "height": 135,
37
+ "fps": 13,
38
+ "bitrate": 89896,
39
+ "alive": true,
40
+ "type": "VIDEO"
41
+ }
42
+ }
43
+ },
44
+ {
45
+ "id": "b770d6fd-75e5-42df-8be0-2a025a75d56d",
46
+ "codec": "opus",
47
+ "bitrate": 0,
48
+ "sampleRate": 48000,
49
+ "channels": 2,
50
+ "alive": true,
51
+ "type": "AUDIO"
52
+ }
53
+ ],
54
+ "incomingTracks": {
55
+ "88b683fc-b972-436f-9a25-b1cba4af61b1": "m send",
56
+ "a112614e-3af1-430e-b364-5b6d75ce3059": null,
57
+ "4d1ece4d-5b75-4816-afd4-dd66a733c091": null,
58
+ "f5dc9935-3944-407f-83ec-10ab74559c07": "m send",
59
+ "319b4b8a-e963-474c-b93e-9d7f06af996e": null,
60
+ "84d158e7-5870-4f62-8f82-a0a77a351a8e": null,
61
+ "1bd17c9a-7b6f-4733-9d07-9d54375854cb": "l send",
62
+ "47997f18-ab1e-414a-b792-095d6d52a407": null,
63
+ "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2": "l send",
64
+ "924a313f-c8b2-4340-8976-c695d00ab0db": "h send"
65
+ }
66
+ },
67
+ {
68
+ "nickName": "Bob",
69
+ "outgoingTracks": [
70
+ {
71
+ "id": "924a313f-c8b2-4340-8976-c695d00ab0db",
72
+ "composite": true,
73
+ "tracks": {
74
+ "h send": {
75
+ "id": "924a313f-c8b2-4340-8976-c695d00ab0db",
76
+ "codec": "VP8",
77
+ "width": 1280,
78
+ "height": 720,
79
+ "fps": 9,
80
+ "bitrate": 502344,
81
+ "alive": true,
82
+ "type": "VIDEO"
83
+ },
84
+ "m send": {
85
+ "id": "924a313f-c8b2-4340-8976-c695d00ab0db",
86
+ "codec": "VP8",
87
+ "width": 640,
88
+ "height": 360,
89
+ "fps": 10,
90
+ "bitrate": 246360,
91
+ "alive": true,
92
+ "type": "VIDEO"
93
+ },
94
+ "l send": {
95
+ "id": "924a313f-c8b2-4340-8976-c695d00ab0db",
96
+ "codec": "VP8",
97
+ "width": 320,
98
+ "height": 180,
99
+ "fps": 10,
100
+ "bitrate": 83008,
101
+ "alive": true,
102
+ "type": "VIDEO"
103
+ }
104
+ }
105
+ },
106
+ {
107
+ "id": "a112614e-3af1-430e-b364-5b6d75ce3059",
108
+ "codec": "opus",
109
+ "bitrate": 0,
110
+ "sampleRate": 48000,
111
+ "channels": 2,
112
+ "alive": true,
113
+ "type": "AUDIO"
114
+ }
115
+ ],
116
+ "incomingTracks": {
117
+ "88b683fc-b972-436f-9a25-b1cba4af61b1": "m send",
118
+ "4d1ece4d-5b75-4816-afd4-dd66a733c091": null,
119
+ "f5dc9935-3944-407f-83ec-10ab74559c07": "m send",
120
+ "319b4b8a-e963-474c-b93e-9d7f06af996e": null,
121
+ "84d158e7-5870-4f62-8f82-a0a77a351a8e": null,
122
+ "b770d6fd-75e5-42df-8be0-2a025a75d56d": null,
123
+ "60bbba84-6b95-4d7f-a8b9-5d38bf972605": "l send",
124
+ "1bd17c9a-7b6f-4733-9d07-9d54375854cb": "l send",
125
+ "47997f18-ab1e-414a-b792-095d6d52a407": null,
126
+ "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2": "l send"
127
+ }
128
+ },
129
+ {
130
+ "nickName": "Alex",
131
+ "outgoingTracks": [
132
+ {
133
+ "id": "319b4b8a-e963-474c-b93e-9d7f06af996e",
134
+ "codec": "opus",
135
+ "bitrate": 0,
136
+ "sampleRate": 48000,
137
+ "channels": 2,
138
+ "alive": true,
139
+ "type": "AUDIO"
140
+ },
141
+ {
142
+ "id": "f5dc9935-3944-407f-83ec-10ab74559c07",
143
+ "composite": true,
144
+ "tracks": {
145
+ "h send": {
146
+ "id": "f5dc9935-3944-407f-83ec-10ab74559c07",
147
+ "codec": "VP8",
148
+ "width": 960,
149
+ "height": 540,
150
+ "fps": 12,
151
+ "bitrate": 566264,
152
+ "alive": true,
153
+ "type": "VIDEO"
154
+ },
155
+ "m send": {
156
+ "id": "f5dc9935-3944-407f-83ec-10ab74559c07",
157
+ "codec": "VP8",
158
+ "width": 480,
159
+ "height": 270,
160
+ "fps": 13,
161
+ "bitrate": 283312,
162
+ "alive": true,
163
+ "type": "VIDEO"
164
+ },
165
+ "l send": {
166
+ "id": "f5dc9935-3944-407f-83ec-10ab74559c07",
167
+ "codec": "VP8",
168
+ "width": 240,
169
+ "height": 135,
170
+ "fps": 12,
171
+ "bitrate": 79000,
172
+ "alive": true,
173
+ "type": "VIDEO"
174
+ }
175
+ }
176
+ }
177
+ ],
178
+ "incomingTracks": {
179
+ "88b683fc-b972-436f-9a25-b1cba4af61b1": "h send",
180
+ "4d1ece4d-5b75-4816-afd4-dd66a733c091": null,
181
+ "a112614e-3af1-430e-b364-5b6d75ce3059": null,
182
+ "84d158e7-5870-4f62-8f82-a0a77a351a8e": null,
183
+ "b770d6fd-75e5-42df-8be0-2a025a75d56d": null,
184
+ "60bbba84-6b95-4d7f-a8b9-5d38bf972605": "h send",
185
+ "1bd17c9a-7b6f-4733-9d07-9d54375854cb": "l send",
186
+ "47997f18-ab1e-414a-b792-095d6d52a407": null,
187
+ "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2": "h send",
188
+ "924a313f-c8b2-4340-8976-c695d00ab0db": "h send"
189
+ }
190
+ },
191
+ {
192
+ "nickName": "Kiri",
193
+ "outgoingTracks": [
194
+ {
195
+ "id": "1bd17c9a-7b6f-4733-9d07-9d54375854cb",
196
+ "composite": true,
197
+ "tracks": {
198
+ "h send": {
199
+ "id": "1bd17c9a-7b6f-4733-9d07-9d54375854cb",
200
+ "codec": "VP8",
201
+ "width": 0,
202
+ "height": 0,
203
+ "fps": 0,
204
+ "bitrate": 0,
205
+ "alive": false,
206
+ "type": "VIDEO"
207
+ },
208
+ "m send": {
209
+ "id": "1bd17c9a-7b6f-4733-9d07-9d54375854cb",
210
+ "codec": "VP8",
211
+ "width": 640,
212
+ "height": 360,
213
+ "fps": 15,
214
+ "bitrate": 287936,
215
+ "alive": true,
216
+ "type": "VIDEO"
217
+ },
218
+ "l send": {
219
+ "id": "1bd17c9a-7b6f-4733-9d07-9d54375854cb",
220
+ "codec": "VP8",
221
+ "width": 320,
222
+ "height": 180,
223
+ "fps": 15,
224
+ "bitrate": 107712,
225
+ "alive": true,
226
+ "type": "VIDEO"
227
+ }
228
+ }
229
+ },
230
+ {
231
+ "id": "84d158e7-5870-4f62-8f82-a0a77a351a8e",
232
+ "codec": "opus",
233
+ "bitrate": 0,
234
+ "sampleRate": 48000,
235
+ "channels": 2,
236
+ "alive": true,
237
+ "type": "AUDIO"
238
+ }
239
+ ],
240
+ "incomingTracks": {
241
+ "88b683fc-b972-436f-9a25-b1cba4af61b1": "h send",
242
+ "4d1ece4d-5b75-4816-afd4-dd66a733c091": null,
243
+ "a112614e-3af1-430e-b364-5b6d75ce3059": null,
244
+ "f5dc9935-3944-407f-83ec-10ab74559c07": "h send",
245
+ "319b4b8a-e963-474c-b93e-9d7f06af996e": null,
246
+ "b770d6fd-75e5-42df-8be0-2a025a75d56d": null,
247
+ "60bbba84-6b95-4d7f-a8b9-5d38bf972605": "h send",
248
+ "47997f18-ab1e-414a-b792-095d6d52a407": null,
249
+ "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2": "h send",
250
+ "924a313f-c8b2-4340-8976-c695d00ab0db": "h send"
251
+ }
252
+ },
253
+ {
254
+ "nickName": "Margaret",
255
+ "outgoingTracks": [
256
+ {
257
+ "id": "47997f18-ab1e-414a-b792-095d6d52a407",
258
+ "codec": "opus",
259
+ "bitrate": 0,
260
+ "sampleRate": 48000,
261
+ "channels": 2,
262
+ "alive": true,
263
+ "type": "AUDIO"
264
+ },
265
+ {
266
+ "id": "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2",
267
+ "composite": true,
268
+ "tracks": {
269
+ "h send": {
270
+ "id": "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2",
271
+ "codec": "VP8",
272
+ "width": 1280,
273
+ "height": 720,
274
+ "fps": 11,
275
+ "bitrate": 511408,
276
+ "alive": true,
277
+ "type": "VIDEO"
278
+ },
279
+ "m send": {
280
+ "id": "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2",
281
+ "codec": "VP8",
282
+ "width": 640,
283
+ "height": 360,
284
+ "fps": 11,
285
+ "bitrate": 243616,
286
+ "alive": true,
287
+ "type": "VIDEO"
288
+ },
289
+ "l send": {
290
+ "id": "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2",
291
+ "codec": "VP8",
292
+ "width": 320,
293
+ "height": 180,
294
+ "fps": 11,
295
+ "bitrate": 79840,
296
+ "alive": true,
297
+ "type": "VIDEO"
298
+ }
299
+ }
300
+ }
301
+ ],
302
+ "incomingTracks": {
303
+ "88b683fc-b972-436f-9a25-b1cba4af61b1": "h send",
304
+ "4d1ece4d-5b75-4816-afd4-dd66a733c091": null,
305
+ "a112614e-3af1-430e-b364-5b6d75ce3059": null,
306
+ "f5dc9935-3944-407f-83ec-10ab74559c07": "m send",
307
+ "319b4b8a-e963-474c-b93e-9d7f06af996e": null,
308
+ "84d158e7-5870-4f62-8f82-a0a77a351a8e": null,
309
+ "b770d6fd-75e5-42df-8be0-2a025a75d56d": null,
310
+ "60bbba84-6b95-4d7f-a8b9-5d38bf972605": "h send",
311
+ "1bd17c9a-7b6f-4733-9d07-9d54375854cb": "l send",
312
+ "924a313f-c8b2-4340-8976-c695d00ab0db": "h send"
313
+ }
314
+ },
315
+ {
316
+ "nickName": "John",
317
+ "outgoingTracks": [
318
+ {
319
+ "id": "88b683fc-b972-436f-9a25-b1cba4af61b1",
320
+ "composite": true,
321
+ "tracks": {
322
+ "h send": {
323
+ "id": "88b683fc-b972-436f-9a25-b1cba4af61b1",
324
+ "codec": "VP8",
325
+ "width": 960,
326
+ "height": 540,
327
+ "fps": 10,
328
+ "bitrate": 489040,
329
+ "alive": true,
330
+ "type": "VIDEO"
331
+ },
332
+ "m send": {
333
+ "id": "88b683fc-b972-436f-9a25-b1cba4af61b1",
334
+ "codec": "VP8",
335
+ "width": 480,
336
+ "height": 270,
337
+ "fps": 12,
338
+ "bitrate": 277760,
339
+ "alive": true,
340
+ "type": "VIDEO"
341
+ },
342
+ "l send": {
343
+ "id": "88b683fc-b972-436f-9a25-b1cba4af61b1",
344
+ "codec": "VP8",
345
+ "width": 240,
346
+ "height": 135,
347
+ "fps": 12,
348
+ "bitrate": 90880,
349
+ "alive": true,
350
+ "type": "VIDEO"
351
+ }
352
+ }
353
+ },
354
+ {
355
+ "id": "4d1ece4d-5b75-4816-afd4-dd66a733c091",
356
+ "codec": "opus",
357
+ "bitrate": 0,
358
+ "sampleRate": 48000,
359
+ "channels": 2,
360
+ "alive": true,
361
+ "type": "AUDIO"
362
+ }
363
+ ],
364
+ "incomingTracks": {
365
+ "a112614e-3af1-430e-b364-5b6d75ce3059": null,
366
+ "f5dc9935-3944-407f-83ec-10ab74559c07": "m send",
367
+ "319b4b8a-e963-474c-b93e-9d7f06af996e": null,
368
+ "84d158e7-5870-4f62-8f82-a0a77a351a8e": null,
369
+ "b770d6fd-75e5-42df-8be0-2a025a75d56d": null,
370
+ "60bbba84-6b95-4d7f-a8b9-5d38bf972605": "h send",
371
+ "1bd17c9a-7b6f-4733-9d07-9d54375854cb": "l send",
372
+ "47997f18-ab1e-414a-b792-095d6d52a407": null,
373
+ "923bdbcc-8b3e-42f1-9d25-561c3c3b0bf2": "l send",
374
+ "924a313f-c8b2-4340-8976-c695d00ab0db": "h send"
375
+ }
376
+ }
377
+ ]
378
+ }
379
+
380
+ module.exports = {
381
+ testStats: testStats
382
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "room": {
3
+ "url": "ws://127.0.0.1:8080",
4
+ "name": "ROOM1",
5
+ "pin": "1234",
6
+ "nickName": "User1"
7
+ }
8
+ }
@@ -0,0 +1,19 @@
1
+ video, object {
2
+ width: 100%;
3
+ height: 100%;
4
+ }
5
+
6
+ .display {
7
+ width: 100%;
8
+ height: 100%;
9
+ display: inline-block;
10
+ }
11
+
12
+ .display > video, object {
13
+ width: 100%;
14
+ height: 100%;
15
+ }
16
+
17
+ video:-webkit-full-screen {
18
+ border-radius: 1px;
19
+ }
@@ -0,0 +1,54 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>SFU Player</title>
7
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"
8
+ integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
9
+ <!-- JavaScript Bundle with Popper -->
10
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"
11
+ integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
12
+ crossorigin="anonymous"></script>
13
+ <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
14
+ <link rel="stylesheet" href="player.css">
15
+ <script type="text/javascript" src="../sfu.js"></script>
16
+ <script type="text/javascript" src="../commons/js/util.js"></script>
17
+ <script type="text/javascript" src="../commons/js/config.js"></script>
18
+ <script type="text/javascript" src="../commons/js/display.js"></script>
19
+ <script type="text/javascript" src="player.js"></script>
20
+ </head>
21
+ <body onload="init()">
22
+ <div class="container" id="main">
23
+ <div class="col-sm-12">
24
+ <h2 class="text-center">SFU Player</h2>
25
+
26
+ <div class="row col-sm-12 justify-content-center">
27
+ <div id="connectionForm" class="col-sm-6 text-center">
28
+ <label for="url" class="control-label">Server url</label>
29
+ <input class="form-control" id="url" type="text">
30
+ <label for="roomName" class="control-label">Room name</label>
31
+ <input class="form-control" id="roomName" type="text">
32
+ </div>
33
+ </div>
34
+ <div class="row col-sm-12 justify-content-center" style="margin-top: 10px;">
35
+ <div class="col-sm-6 text-center">
36
+ <div class="text-center text-muted">Player</div>
37
+ <div id="playForm" class="input-group col-sm-5" style="margin-top: 10px;">
38
+ <input class="form-control" id="playName" type="text" style="height: 30px;" placeholder="Player name">
39
+ <div class="input-group-btn">
40
+ <button id="playBtn" type="button" style="height: 30px;; width: auto;">Play</button>
41
+ </div>
42
+ </div>
43
+ <div class="text-center" style="margin-top: 20px">
44
+ <div id="playStatus"></div>
45
+ <div id="playErrorInfo"></div>
46
+ </div>
47
+ </div>
48
+ </div>
49
+ <div class="row col-sm-12 justify-content-center" style="margin-top: 10px">
50
+ <div id="remoteVideo" class="col-sm-6 justify-content-center"></div>
51
+ </div>
52
+ </div>
53
+ </body>
54
+ </html>
@@ -0,0 +1,209 @@
1
+ const constants = SFU.constants;
2
+ const sfu = SFU;
3
+ let mainConfig;
4
+ let remoteDisplay;
5
+ let playState;
6
+ const PLAY = "play";
7
+ const STOP = "stop";
8
+ const PRELOADER_URL="../commons/media/silence.mp3"
9
+
10
+ /**
11
+ * Default publishing config
12
+ */
13
+ const defaultConfig = {
14
+ room: {
15
+ url: "ws://127.0.0.1:8080",
16
+ name: "ROOM1",
17
+ pin: "1234",
18
+ nickName: "User1"
19
+ }
20
+ };
21
+
22
+ /**
23
+ * Current state object
24
+ */
25
+ const CurrentState = function(prefix) {
26
+ let state = {
27
+ prefix: prefix,
28
+ pc: null,
29
+ session: null,
30
+ room: null,
31
+ set: function(pc, session, room) {
32
+ state.pc = pc;
33
+ state.session = session;
34
+ state.room = room;
35
+ },
36
+ clear: function() {
37
+ state.room = null;
38
+ state.session = null;
39
+ state.pc = null;
40
+ },
41
+ buttonId: function() {
42
+ return state.prefix + "Btn";
43
+ },
44
+ buttonText: function() {
45
+ return (state.prefix.charAt(0).toUpperCase() + state.prefix.slice(1));
46
+ },
47
+ inputId: function() {
48
+ return state.prefix + "Name";
49
+ },
50
+ statusId: function() {
51
+ return state.prefix + "Status";
52
+ },
53
+ formId: function() {
54
+ return state.prefix + "Form";
55
+ },
56
+ errInfoId: function() {
57
+ return state.prefix + "ErrorInfo";
58
+ },
59
+ is: function(value) {
60
+ return (prefix === value);
61
+ }
62
+ };
63
+ return state;
64
+ }
65
+
66
+ /**
67
+ * load config and set default values
68
+ */
69
+ const init = function() {
70
+ let configName = getUrlParam("config") || "./config.json";
71
+ $("#playBtn").prop('disabled', true);
72
+ $("#url").prop('disabled', true);
73
+ $("#roomName").prop('disabled', true);
74
+ $("#playName").prop('disabled', true);
75
+ playState = CurrentState(PLAY);
76
+ $.getJSON(configName, function(cfg){
77
+ mainConfig = cfg;
78
+ onDisconnected(playState);
79
+ }).fail(function(e){
80
+ //use default config
81
+ console.error("Error reading configuration file " + configName + ": " + e.status + " " + e.statusText)
82
+ console.log("Default config will be used");
83
+ mainConfig = defaultConfig;
84
+ onDisconnected(playState);
85
+ });
86
+ $("#url").val(setURL());
87
+ $("#roomName").val("ROOM1-"+createUUID(4));
88
+ $("#playName").val("Player1-"+createUUID(4));
89
+ }
90
+
91
+ /**
92
+ * connect to server
93
+ */
94
+ const connect = function(state) {
95
+ //create peer connection
96
+ pc = new RTCPeerConnection();
97
+ //get config object for room creation
98
+ const roomConfig = getRoomConfig(mainConfig);
99
+ roomConfig.pc = pc;
100
+ roomConfig.url = $("#url").val();
101
+ roomConfig.roomName = $("#roomName").val();
102
+ roomConfig.nickname = $("#" + state.inputId()).val();
103
+ // clean state display items
104
+ setStatus(state.statusId(), "");
105
+ setStatus(state.errInfoId(), "");
106
+ // connect to server and create a room if not
107
+ const session = sfu.createRoom(roomConfig);
108
+ session.on(constants.SFU_EVENT.CONNECTED, function() {
109
+ state.set(pc, session, session.room());
110
+ onConnected(state);
111
+ setStatus(state.statusId(), "ESTABLISHED", "green");
112
+ }).on(constants.SFU_EVENT.DISCONNECTED, function() {
113
+ state.clear();
114
+ onDisconnected(state);
115
+ setStatus(state.statusId(), "DISCONNECTED", "green");
116
+ }).on(constants.SFU_EVENT.FAILED, function(e) {
117
+ state.clear();
118
+ onDisconnected(state);
119
+ setStatus(state.statusId(), "FAILED", "red");
120
+ setStatus(state.errInfoId(), e.status + " " + e.statusText, "red");
121
+ });
122
+ }
123
+
124
+ const onConnected = function(state) {
125
+ $("#" + state.buttonId()).text("Stop").off('click').click(function () {
126
+ onStopClick(state);
127
+ }).prop('disabled', false);
128
+ $('#url').prop('disabled', true);
129
+ $("#roomName").prop('disabled', true);
130
+ $("#" + state.inputId()).prop('disabled', true);
131
+ // Add errors displaying
132
+ state.room.on(constants.SFU_ROOM_EVENT.FAILED, function(e) {
133
+ setStatus(state.errInfoId(), e, "red");
134
+ }).on(constants.SFU_ROOM_EVENT.OPERATION_FAILED, function (e) {
135
+ setStatus(state.errInfoId(), e.operation + " failed: " + e.error, "red");
136
+ });
137
+ playStreams(state);
138
+ }
139
+
140
+ const onDisconnected = function(state) {
141
+ $("#" + state.buttonId()).text(state.buttonText()).off('click').click(function () {
142
+ onStartClick(state);
143
+ }).prop('disabled', false);
144
+ $('#url').prop('disabled', false);
145
+ $("#roomName").prop('disabled', false);
146
+ $("#" + state.inputId()).prop('disabled', false);
147
+ }
148
+
149
+ const onStartClick = function(state) {
150
+ if (validateForm("connectionForm") && validateForm(state.formId())) {
151
+ $("#" + state.buttonId()).prop('disabled', true);
152
+ if (state.is(PLAY) && Browser().isSafariWebRTC()) {
153
+ playFirstSound(document.getElementById("main"), PRELOADER_URL).then(function () {
154
+ connect(state);
155
+ });
156
+ } else {
157
+ connect(state);
158
+ }
159
+ }
160
+ }
161
+
162
+ const onStopClick = function(state) {
163
+ $("#" + state.buttonId()).prop('disabled', true);
164
+ stopStreams(state);
165
+ state.session.disconnect();
166
+ }
167
+
168
+ const playStreams = function(state) {
169
+ //create remote display item to show remote streams
170
+ remoteDisplay = initRemoteDisplay(document.getElementById("remoteVideo"), state.room, state.pc);
171
+ state.room.join();
172
+ }
173
+
174
+ const stopStreams = function(state) {
175
+ if (remoteDisplay) {
176
+ remoteDisplay.stop();
177
+ }
178
+ }
179
+
180
+ const setStatus = function (status, text, color) {
181
+ const errField = document.getElementById(status);
182
+ errField.style.color = color;
183
+ errField.innerText = text;
184
+ }
185
+
186
+ const validateForm = function (formId) {
187
+ var valid = true;
188
+ $('#' + formId + ' :text').each(function () {
189
+ if (!$(this).val()) {
190
+ highlightInput($(this));
191
+ valid = false;
192
+ } else {
193
+ removeHighlight($(this));
194
+ }
195
+ });
196
+ return valid;
197
+
198
+ function highlightInput(input) {
199
+ input.closest('.input-group').addClass("has-error");
200
+ }
201
+
202
+ function removeHighlight(input) {
203
+ input.closest('.input-group').removeClass("has-error");
204
+ }
205
+ }
206
+
207
+ const buttonText = function (string) {
208
+ return string.charAt(0).toUpperCase() + string.slice(1);
209
+ }