forked from steveseguin/vdo.ninja
-
Notifications
You must be signed in to change notification settings - Fork 0
/
teststreams.html
717 lines (582 loc) · 29.2 KB
/
teststreams.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
<html>
<head>
<title>IFRAME Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<style>
body{
padding:0;
margin:0;
background-color: rgb(68 72 74);
}
iframe {
border:0;
margin:0;
padding:0;
display:none;
}
#viewlink {
width:400px;
}
#container {
display:block;
padding:0px;
}
input{
padding:5px;
margin:5px;
}
button{
padding:5px;
margin:5px;
}
video{
max-width:300px;
max-height:100px;
}
</style>
<script>
function loadIframe(){ // this is pretty important if you want to avoid camera permission popup problems. You can also call it automatically via: <body onload=>loadIframe();"> , but don't call it before the page loads.
var iframe = document.createElement("iframe");
var iframeContainer = document.createElement("div");
var iframesrc = document.getElementById("viewlink").value;
iframe.allow = "document-domain;encrypted-media;sync-xhr;usb;web-share;cross-origin-isolated;accelerometer;midi;geolocation;autoplay;camera;microphone;fullscreen;picture-in-picture;display-capture;";
if (iframesrc==""){
iframesrc="./";
}
<!-- if (document.getElementById("clean").checked){ -->
<!-- if (iframesrc.includes("?")){ -->
<!-- iframesrc+='&'; -->
<!-- } else { -->
<!-- iframesrc+='?'; -->
<!-- } -->
<!-- iframesrc+="cleanoutput"; -->
<!-- } -->
<!-- if (document.getElementById("transparent").checked){ -->
<!-- if (iframesrc.includes("?")){ -->
<!-- iframesrc+='&'; -->
<!-- } else { -->
<!-- iframesrc+='?'; -->
<!-- } -->
<!-- iframesrc+="transparent"; -->
<!-- } -->
<!-- if (document.getElementById("hidemenu").checked){ -->
<!-- if (iframesrc.includes("?")){ -->
<!-- iframesrc+='&'; -->
<!-- } else { -->
<!-- iframesrc+='?'; -->
<!-- } -->
<!-- iframesrc+="hidemenu"; -->
<!-- } -->
iframe.src = iframesrc;
iframeContainer.appendChild(iframe);
var editURL = document.createElement("input");
editURL.type = "text";
editURL.value = iframesrc;
iframeContainer.appendChild(editURL);
var button = document.createElement("button");
button.innerHTML = "Update URL and reload";
// button.onclick = function(){}; // "speaker" also works in the same way.
iframeContainer.appendChild(button);
document.getElementById("container").appendChild(iframeContainer);
<!-- var h3 = document.createElement("h3"); -->
<!-- h3.innerText = "The following commands are exclusive to the IFRAME API."; -->
<!-- iframeContainer.appendChild(h3); -->
var button = document.createElement("button");
button.innerHTML = "Mute Speaker";
button.onclick = function(){iframe.contentWindow.postMessage({"mute":true}, '*');}; // "speaker" also works in the same way.
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Un-Mute Speaker";
button.onclick = function(){iframe.contentWindow.postMessage({"mute":false}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Toggle Speaker";
button.onclick = function(){iframe.contentWindow.postMessage({"mute":"toggle"}, '*');}; // open to a better suggestion here.
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Mute Mic";
button.onclick = function(){iframe.contentWindow.postMessage({"mic":false}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Un-Mute Mic";
button.onclick = function(){iframe.contentWindow.postMessage({"mic":true}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Toggle Mic";
button.onclick = function(){iframe.contentWindow.postMessage({"mic":"toggle"}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Mute Camera";
button.onclick = function(){iframe.contentWindow.postMessage({"camera":false}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Unmute Camera";
button.onclick = function(){iframe.contentWindow.postMessage({"camera":true}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Toggle Camera";
button.onclick = function(){iframe.contentWindow.postMessage({"camera":"toggle"}, '*');};
iframeContainer.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "Disconnect";
button.onclick = function(){iframe.contentWindow.postMessage({"close":true}, '*');};
iframeContainer.appendChild(button);
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "0 Bitrate"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":0, "target": "*"}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Low Bitrate"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":30, "target": "*"}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "High Bitrate"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":5000, "target": "*"}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Default Bitrate"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"bitrate":-1, "target": "*"}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
var button = document.createElement("button");
button.innerHTML = "Reload";
button.onclick = function(){iframe.contentWindow.postMessage({"reload":true}, '*');};
iframeContainer.appendChild(button);
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "50% Volume"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"volume":0.5}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "100% Volume"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"volume":1.0}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Pan Left"; -->
<!-- button.title = "Requires &panning to be added to the view link"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"panning":0}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Pan right"; -->
<!-- button.title = "Requires &panning to be added to the view link"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"panning":180}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Pan Center"; -->
<!-- button.title = "Requires &panning to be added to the view link"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"panning":90}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Request Loudness Levels"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"getLoudness":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Stop Sending Loudness Levels"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"getLoudness":false}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Get detailed state (if Director)"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"getDetailedState":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Start Recording"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"record":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Stop Recording"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"record":false}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Say Hello"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"sendChat":"Hello!"}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Send Keyframe"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"keyframe":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Insert Style Sheet"; -->
<!-- var stylesheet = "#main { zoom: 0.5;} video {float: left; margin: 0; padding: 0; } #info {display:none;}"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"style":stylesheet}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "get StreamIDs and labels"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"getStreamIDs":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "get media device list"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"getDeviceList":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Start AutoMixer"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"automixer":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Stop AutoMixer"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"automixer":false}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "ENABLE TALLY LIGHT"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"sceneState":true}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "STOP TALLY LIGHT"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"sceneState":false}, '*');}; -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Add Target Video"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"target":"*", "add":true, "settings": {"style": "width:640px;height:360px;float:left;border:10px solid red;display:block;"}}, '*');}; // target can be a stream ID or * for all. -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Remove Target Video"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"target":"*", "remove": true}, '*');}; // target can be a stream ID or * for all. -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "previewWebcam()"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"function":"previewWebcam"}, '*');}; // publishScreen -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Change to Camera #2"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"changeVideoDevice":2}, '*');}; // change text of add camera button -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Change to Microphone #4"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"changeAudioDevice":4}, '*');}; // change text of add camera button -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "eval('alert(\"DANGERUS\")'"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"function":"eval", "value":'alert(\"DANGERUS\")'}, '*');}; // publishScreen -->
<!-- iframeContainer.appendChild(button); -->
<!-- var button = document.createElement("button"); -->
<!-- button.innerHTML = "Change Add Camera text"; -->
<!-- button.onclick = function(){iframe.contentWindow.postMessage({"function":"changeHTML", "target":"add_camera", "value":"NEW CAMERA TEXT"}, '*');}; // change text of add camera button -->
<!-- iframeContainer.appendChild(button); -->
var button = document.createElement("button");
button.innerHTML = "CLOSE IFRAME";
button.onclick = function(){iframeContainer.parentNode.removeChild(iframeContainer);};
iframeContainer.appendChild(button);
//////////// LISTEN FOR EVENTS
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod === "attachEvent" ? "onmessage" : "message";
var media = {};
media.tracks = {};
media.streams = {};
window.addEventListener('messageerror', e => {
console.error(e);
});
eventer(messageEvent, function (e) {
if (e.source != iframe.contentWindow){return} // reject messages send from other iframes
if (e.data.frame){ // add `&sendframes` to the view link to trigger this event; it lets you capture video/audio from the parent window
if (!media.tracks[e.data.trackID]){
media.tracks[e.data.trackID] = {};
media.tracks[e.data.trackID].generator = new MediaStreamTrackGenerator({kind:e.data.kind});
media.tracks[e.data.trackID].stream = new MediaStream([media.tracks[e.data.trackID].generator]);
media.tracks[e.data.trackID].frameWriter = media.tracks[e.data.trackID].generator.writable.getWriter();
media.tracks[e.data.trackID].frameWriter.write(e.data.frame);
if (!media.streams[e.data.streamID]){
media.streams[e.data.streamID] = document.createElement("video");
media.streams[e.data.streamID].id = "video_"+e.data.streamID;
media.streams[e.data.streamID].autoplay = true;
// media.streams[e.data.streamID].controls = true;
media.streams[e.data.streamID].srcObject = media.tracks[e.data.trackID].stream;
iframeContainer.appendChild(media.streams[e.data.streamID]);
} else {
if (e.data.kind=="video"){
media.streams[e.data.streamID].srcObject.getVideoTracks().forEach(trk=>{
media.streams[e.data.streamID].srcObject.removeTrack(trk);
});
} else if (e.data.kind=="audio"){
media.streams[e.data.streamID].srcObject.getAudioTracks().forEach(trk=>{
media.streams[e.data.streamID].srcObject.removeTrack(trk);
});
}
media.tracks[e.data.trackID].stream.getTracks().forEach(trk=>{
media.streams[e.data.streamID].srcObject.addTrack(trk);
});
}
} else {
media.tracks[e.data.trackID].frameWriter.write(e.data.frame);
}
return;
} // end of video/audio capture
if ("stats" in e.data){
var outputWindow = document.createElement("div");
console.log(e.data.stats);
var out = "<br />total_inbound_connections:"+e.data.stats.total_inbound_connections;
out += "<br />total_outbound_connections:"+e.data.stats.total_outbound_connections;
for (var streamID in e.data.stats.inbound){
out += "<br /><br /><b>streamID:</b> "+streamID+"<br />";
out += printValues(e.data.stats.inbound[streamID]);
}
outputWindow.innerHTML = out;
iframeContainer.appendChild(outputWindow);
}
if ("gotChat" in e.data){
var outputWindow = document.createElement("div");
outputWindow.innerHTML = e.data.gotChat.msg;
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
}
if ("action" in e.data){
var outputWindow = document.createElement("div");
outputWindow.innerHTML = "child-page-action: "+e.data.action+"<br />";
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
}
if ("streamIDs" in e.data){
var outputWindow = document.createElement("div");
outputWindow.innerHTML = "child-page-action: streamIDs<br />";
for (var key in e.data.streamIDs) {
outputWindow.innerHTML += "streamID: " + key + ", label:"+e.data.streamIDs[key] + "\n";
}
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
}
if ("deviceList" in e.data){
var outputWindow = document.createElement("div");
outputWindow.innerHTML = "child-page-action: deviceList<br />";
for (var i = 0;i<e.data.deviceList.length;i++){
outputWindow.innerHTML += e.data.deviceList[i].label + "<br />";
}
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
}
if ("loudness" in e.data){
console.log(e.data);
if (document.getElementById("loudness")){
outputWindow = document.getElementById("loudness");
} else {
var outputWindow = document.createElement("div");
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
outputWindow.id = "loudness";
}
outputWindow.innerHTML = "child-page-action: loudness<br />";
for (var key in e.data.loudness) {
outputWindow.innerHTML += key + " Loudness: " + e.data.loudness[key] + "\n";
}
outputWindow.style.border="1px black";
}
if ("detailedState" in e.data){
var outputWindow = document.createElement("div");
outputWindow.innerHTML = "child-page-action: detailedState<br />"+JSON.stringify(e.data.detailedState)+"<br />";
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
}
if ("sensors" in e.data){
console.log(e.data);
if (document.getElementById("sensors")){
outputWindow = document.getElementById("sensors");
} else {
var outputWindow = document.createElement("div");
outputWindow.style.border="1px dotted black";
iframeContainer.appendChild(outputWindow);
outputWindow.id = "sensors";
}
outputWindow.innerHTML = "child-page-action: sensors<br /><br />";
for (var key in e.data.sensors.lin) {
outputWindow.innerHTML += key + " linear: " + e.data.sensors.lin[key] + "<br />";
}
for (var key in e.data.sensors.acc) {
outputWindow.innerHTML += key + " acceleration: " + e.data.sensors.acc[key] + "<br />";
}
for (var key in e.data.sensors.gyro) {
outputWindow.innerHTML += key + " gyro: " + e.data.sensors.gyro[key] + "<br />";
}
for (var key in e.data.sensors.mag) {
outputWindow.innerHTML += key + " magnet: " + e.data.sensors.mag[key] + "<br />";
}
outputWindow.style.border="1px black";
}
});
function loadSelfCommands(){
var commands = {}
commands.speaker = function(value){sendSelfCommand("speaker",value)}; // "speaker" also works in the same way
commands.mic = function(value){sendSelfCommand("mic",value)};
commands.camera = function(value){sendSelfCommand("camera",value)};
commands.bitrate = function(value){sendSelfCommand("bitrate",value)};
commands.volume = function(value){sendSelfCommand("volume",value)};
commands.record = function(value){sendSelfCommand("record",value)};
commands.sayHello = function(value){sendSelfCommand("sendChat","Hello")};
var target_self = document.body;
var hr = document.createElement("hr");
target_self.appendChild(hr);
var h3 = document.createElement("h3");
h3.innerText = "The following commands re-use the Companion.Ninja HTTP/WSS API, except you can send them via this Iframe interface.";
target_self.appendChild(h3);
var a = document.createElement("a");
a.innerText = "More details of the below IFRAME API details are here: https://github.com/steveseguin/Companion-Ninja#api-commands";
a.href = "https://github.com/steveseguin/Companion-Ninja#api-commands";
a.target = "_blank";
target_self.appendChild(a);
var hr = document.createElement("hr");
target_self.appendChild(hr);
for (var k in commands) {
var button = document.createElement("button");
button.innerHTML = k + ":<br />TRUE";
button.dataset.command = k;
button.onclick = function(){commands[this.dataset.command](true);}
target_self.appendChild(button);
var button = document.createElement("button");
button.innerHTML = k + ":<br />FALSE";
button.dataset.command = k;
button.onclick = function(){commands[this.dataset.command](false);}
target_self.appendChild(button);
if (k=="mic" || k=="camera" || k=="record" || k=="speaker"){
var button = document.createElement("button");
button.innerHTML = k + ":<br />TOGGLE";
button.dataset.command = k;
button.onclick = function(){commands[this.dataset.command]("toggle");}
target_self.appendChild(button);
}
} // list available commands to console
commands.reload = function(){sendSelfCommand("reload",true);};
commands.hangup = function(){sendSelfCommand("hangup",true);};
var button = document.createElement("button");
button.innerHTML = k + ":<br />TRUE";
button.onclick = function(){commands["reload"](true);}
target_self.appendChild(button);
var button = document.createElement("button");
button.innerHTML = k + ":<br />TRUE";
button.onclick = function(){commands["hangup"](true);}
target_self.appendChild(button);
return commands;
}
function loadGuestCommands(guestid, streamID=false){ // this is the same as the Companion API, but can be issued to the IFRAME API
var container = document.createElement("div");
container.id = "guest_"+guestid+"_container";
document.body.appendChild(container);
var hr = document.createElement("hr");
container.appendChild(hr);
var h3 = document.createElement("h3");
if (streamID){
h3.innerHTML = "These target guest with the streamID: <i>"+guestid+ "</i> (if a director)";
} else {
h3.innerText = "These target the guest in slot "+guestid+ " (if you are director)";
}
container.appendChild(h3);
var button = document.createElement("button");
button.innerHTML = "transfer popup";
button.onclick = function(){sendGuestCommand(guestid, "forward");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "transfer to 'room321'";
button.onclick = function(){sendGuestCommand(guestid, "forward", 'room321');};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 1";
button.onclick = function(){sendGuestCommand(guestid, "addScene");}; /// SCENE 1 or specify a custom scene name as a value
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "mute in scene";
button.onclick = function(){sendGuestCommand(guestid, "muteScene");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "mute everywhere";
button.onclick = function(){sendGuestCommand(guestid, "mic");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "hang up";
button.onclick = function(){sendGuestCommand(guestid, "hangup");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "solo chat";
button.onclick = function(){sendGuestCommand(guestid, "soloChat");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "remote speaker";
button.onclick = function(){sendGuestCommand(guestid, "speaker");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "remote display";
button.onclick = function(){sendGuestCommand(guestid, "display");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "rainbow puke fix";
button.onclick = function(){sendGuestCommand(guestid, "forceKeyframe");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "highlight";
button.onclick = function(){sendGuestCommand(guestid, "soloVideo");};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 2";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 2);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 3";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 3);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 4";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 4);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 5";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 5);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 6";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 6);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = " scene 7";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 7);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 8";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 8);};
container.appendChild(button);
var button = document.createElement("button");
button.innerHTML = "scene 'test'";
button.onclick = function(){sendGuestCommand(guestid, "addScene", 'test');}; // specifying a custom scene; it needs to be active for this to work..
container.appendChild(button);
var input = document.createElement("label");
input.innerHTML = "mic volume:";
container.appendChild(input);
var input = document.createElement("input");
input.type = "range";
input.title = "volume";
input.min = 0;
input.max = 200;
input.value = 100;
input.onchange = function(){sendGuestCommand(guestid, "volume", this.value);};
container.appendChild(input);
}
function sendGuestCommand(target, action, value=null){ //
iframe.contentWindow.postMessage({"target":target, "action":action, "value":value}, '*'); //
//sendMessage(JSON.stringify({"target":target, "action":action, "value":value})); // if using the Companion API..
}
function sendSelfCommand(action, value=null){
iframe.contentWindow.postMessage({"target":null, "action":action, "value":value}, '*');
//sendMessage(JSON.stringify({"target":target, "action":action, "value":value})); // if using the Companion API..
}
//loadSelfCommands();
//loadGuestCommands(1);
//loadGuestCommands(2);
//loadGuestCommands(3);
//var randomGuest = Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 10);
//loadGuestCommands(randomGuest, true);
}
function printValues( obj) {
var out = "";
for (var key in obj) {
if (typeof obj[key] === "object") {
out +="<br />";
out += printValues(obj[key]);
} else {
out +="<b>"+key+"</b>: "+obj[key]+"<br />";
}
}
return out;
}
</script>
</head>
<body>
<h1>Test Stream Manager</h1>
<div id="container">
</div>
<input placeholder="Enter an VDO.Ninja View URL here" id="viewlink" />
<button onclick="loadIframe();">ADD</button>
</body>
</html>