-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
MMM-RTSPStream.js
720 lines (655 loc) · 27 KB
/
MMM-RTSPStream.js
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
718
719
720
/* global Module */
/* Magic Mirror
* Module: MMM-RTSPStream
*
* By shbatm
* MIT Licensed.
*/
/* jshint esversion: 6*/
var global = this;
Module.register("MMM-RTSPStream", {
defaults: {
initialSetup: false,
debug: false,
autoStart: true,
rotateStreams: false,
rotateStreamTimeout: 10, // Seconds
showSnapWhenPaused: true,
localPlayer: "vlc", // "omxplayer" or "ffmpeg", or "vlc"
remotePlayer: "none", // "ffmpeg" or "none"
remoteSnaps: true, // Show remote snapshots
moduleWidth: 384, // Width = (Stream Width + 30px margin + 2px border) * # of Streams Wide
moduleHeight: 272, // Height = (Stream Height + 30px margin + 2px border) * # of Streams Tall
moduleOffset: 0, // Offset to align OMX player windows
shutdownDelay: 11, // Seconds
animationSpeed: 1500,
stream1: {
name: 'BigBuckBunny Test',
url: 'rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov',
snapshotType: 'url', // 'url' or 'file'
snapshotUrl: '',
snapshotRefresh: 10, // Seconds
protocol: "tcp", // 'tcp' or 'udp'
frameRate: "30",
ffmpegPort: 9999,
width: 320,
height: 240,
omxRestart: 24, // Hours
muted: false
},
// MMM-KeyBindings Settings
keyBindings: {
enabled: true
},
},
keyBindings: {
enabled: false,
mode: "DEFAULT",
map: {
Play: "MediaPlayPause",
Previous: "MediaPreviousTrack",
Next: "MediaNextTrack",
Select: "Enter"
},
multiInstance: true,
takeFocus: "Menu"
},
requiresVersion: "2.4.0", // Required version of MagicMirror
playing: false,
currentIndex: -1,
currentStream: '',
streams: {},
// Allow for control on muliple instances
instance: (global.location && ["localhost", "127.0.0.1", "::1", "::ffff:127.0.0.1", undefined, "0.0.0.0"].indexOf(global.location.hostname) > -1) ? "SERVER" : "LOCAL",
start: function() {
var self = this;
//Flag for check if module is loaded
this.loaded = false;
if (!this.config.initialSetup) {
this.sendSocketNotification('CONFIG', this.config);
Object.keys(this.config).filter(key => key.startsWith("stream")).forEach((key) => {
self.streams[key] = { playing: false };
});
}
},
setupStreamRotation: function() {
this.playing = this.config.autoStart;
// Reference to function for manual transitions (TODO: FUTURE)
this.manualTransition = this.rotateStream.bind(this);
// Call the first stream
this.manualTransition();
this.restartTimer();
},
rotateStream: function(goToStream = undefined, goDirection = 0) {
var k = Object.keys(this.streams);
var ps = [];
var resetCurrentIndex = k.length;
var lastStream = this.currentStream;
// Update the current index
if (goToStream && goToStream in this.streams) {
this.currentStream = goToStream; // Go to a specific slide if in range
} else {
if (goDirection === 0) {
this.currentIndex += 1; // Normal Transition, Increment by 1
} else {
this.currentIndex += goDirection; // Told to go a specific direction
}
if (this.currentIndex >= resetCurrentIndex) { // Wrap-around back to beginning
this.currentIndex = 0;
} else if (this.currentIndex < 0) {
this.currentIndex = resetCurrentIndex - 1; // Went too far backwards, wrap-around to end
}
this.currentStream = k[this.currentIndex];
}
if (this.playing) {
if (lastStream) { this.stopStream(lastStream); }
ps = this.playStream(this.currentStream);
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
} else {
if (lastStream) { this.sendSocketNotification("SNAPSHOT_STOP", lastStream); }
this.playSnapshots(this.currentStream);
}
},
restartTimer: function() {
if (this.config.rotateStreams && Object.keys(this.streams).length > 1 && this.config.rotateStreamTimeout > 0) {
// Restart the timer
if (this.transitionTimer) { clearInterval(this.transitionTimer); }
this.transitionTimer = setInterval(this.manualTransition, this.config.rotateStreamTimeout * 1000);
}
},
/* suspend()
* This method is called when a module is hidden.
*/
suspend: function() {
console.log(`${this.name} is suspended...`);
this.suspended = true;
this.stopAllStreams(false);
if (this.selectedStream) { this.selectStream(undefined, true); }
},
/* resume()
* This method is called when a module is shown.
*/
resume: function() {
},
resumed: function(callback) {
console.log(`${this.name} has resumed... rotateStreams: ${this.config.rotateStreams}, autoStart: ${this.config.autoStart}`);
this.suspended = false;
if (this.loaded) {
if (this.config.rotateStreams) {
this.setupStreamRotation();
} else if (this.config.autoStart) {
this.playAll();
} else {
console.log("Playing all snapshots");
Object.keys(this.streams).forEach(s => this.playSnapshots(s));
}
}
if (typeof callback === "function") { callback(); }
},
// Overwrite the module show method to force a callback.
show: function(speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function() {};
}
newCallback = () => { this.resumed(callback); };
options = options || {};
MM.showModule(this, speed, newCallback, options);
},
playBtnCallback: function(s) {
var ps = [];
if (this.config.rotateStreams) {
if (this.playing) {
this.stopStream(this.currentStream);
this.playSnapshots(this.currentStream);
} else {
this.sendSocketNotification("SNAPSHOT_STOP", this.currentStream);
ps = this.playStream(this.currentStream);
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
}
} else {
if (this.streams[s].playing) {
this.stopStream(s);
this.playSnapshots(s);
} else {
this.sendSocketNotification("SNAPSHOT_STOP", s);
ps = this.playStream(s);
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
}
}
},
playBtnDblClickCB: function(s) {
if (this.instance === "SERVER" && !this.streams[s].playing) {
var ps = this.playStream(s, true);
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
} else {
this.playBtnCallback(s);
}
},
getDom: function() {
var self = this;
// create element wrapper for show into the module
var wrapper = document.createElement("div");
if (this.config.initialSetup) {
wrapper.innerHTML = `Use config wizard at http://${global.location.hostname}:${global.location.port}/${this.name}/config.html<br>to generate a configuration for this moudle.`;
return wrapper;
}
if (!this.loaded) {
wrapper.innerHTML = "Loading " + this.name + "...";
wrapper.className = "dimmed light small";
return wrapper;
}
if (this.error) {
wrapper.innerHTML = "Error loading data...";
return wrapper;
}
if (this.loaded) {
wrapper.style.cssText = `width: ${this.config.moduleWidth}px; height:${this.config.moduleHeight}px`;
wrapper.className = "MMM-RTSPStream wrapper";
if (this.config.rotateStreams) {
iw = this.getInnerWrapper('');
iw.appendChild(this.getCanvas(''));
iw.appendChild(this.getPlayPauseBtn(''));
wrapper.appendChild(iw);
} else {
Object.keys(this.streams).forEach(stream => {
iw = this.getInnerWrapper(stream);
iw.appendChild(this.getCanvas(stream));
iw.appendChild(this.getPlayPauseBtn(stream));
wrapper.appendChild(iw);
});
}
wrapper.appendChild(document.createElement("br"));
}
return wrapper;
},
getCanvasSize: function(streamConfig) {
var s = '';
if (typeof streamConfig.width !== "undefined") { s += "width: " + streamConfig.width + "px; "; }
if (typeof streamConfig.height !== "undefined") { s += "height: " + streamConfig.height + "px; line-height: " + streamConfig.height + ";"; }
return s;
},
getCanvas: function(stream) {
var canvas = document.createElement("canvas");
canvas.id = "canvas_" + stream;
canvas.className = "MMM-RTSPStream canvas";
// if (stream) { canvas.cssText = this.getCanvasSize(this.config[stream]); }
return canvas;
},
getInnerWrapper: function(stream) {
var innerWrapper = document.createElement("div");
innerWrapper.className = "MMM-RTSPStream innerWrapper";
if (!stream) { stream = "stream1" };
innerWrapper.style.cssText = this.getCanvasSize(this.config[stream]);
innerWrapper.id = "iw_" + stream;
return innerWrapper;
},
getPlayPauseBtn: function(stream, force_visible = false) {
var self = this;
function makeOnClickHandler(s) {
return function() {
self.playBtnCallback(s);
};
}
function makeOnDblClickHandler(s) {
return function() {
self.playBtnDblClickCB(s);
};
}
var playBtnWrapper = document.createElement("div");
playBtnWrapper.className = "control";
playBtnWrapper.onclick = makeOnClickHandler(stream);
playBtnWrapper.oncontextmenu = makeOnDblClickHandler(stream);
playBtnWrapper.id = "playBtnWrapper_" + stream;
var playBtnLabel = document.createElement("label");
playBtnLabel.id = "playBtnLabel_" + stream;
playBtnLabel.innerHTML = '<i class="fa fa-play-circle"></i>';
playBtnWrapper.appendChild(playBtnLabel);
return playBtnWrapper;
},
updatePlayPauseBtn(stream, force_visible = false) {
var buttonId = (this.config.rotateStreams) ? "playBtnLabel_" : "playBtnLabel_" + stream;
var button = document.getElementById(buttonId);
if (!button) {
// If not ready yet, retry in 1 second.
setTimeout(() => this.updatePlayPauseBtn(stream, force_visible), 1000);
return;
}
if (stream !== '' && this.streams[stream].playing) {
button.innerHTML = '<i class="fa fa-pause-circle"></i>';
} else {
button.innerHTML = '<i class="fa fa-play-circle"></i>';
}
if (force_visible) {
button.style.cssText = "opacity: 0.6;";
button.parentElement.style.cssText = "opacity: 1;";
} else {
button.style.cssText = '';
button.parentElement.style.cssText = '';
}
},
playStream: function(stream, fullscreen = false, absPosition = undefined) {
var canvasId = (this.config.rotateStreams) ? "canvas_" : "canvas_" + stream;
var canvas = document.getElementById(canvasId);
var omxPayload = [];
if (this.streams[stream].playing) {
this.stopStream(stream);
}
if (this.instance === "SERVER" && ["omxplayer", "vlc"].indexOf(this.config.localPlayer) !== -1) {
var rect = canvas.getBoundingClientRect();
var offset = {};
var payload = { name: stream };
if (typeof this.config.moduleOffset === "object") {
offset.left = ("left" in this.config.moduleOffset) ? this.config.moduleOffset.left : 0;
offset.top = ("top" in this.config.moduleOffset) ? this.config.moduleOffset.top : 0;
} else {
offset.left = this.config.moduleOffset;
offset.top = this.config.moduleOffset;
}
var box = {};
if ("absPosition" in this.config[stream]) {
box = this.config[stream].absPosition;
} else if (typeof absPosition !== "undefined") {
box = absPosition;
} else if (fullscreen) {
payload.fullscreen = true;
} else {
box = {
top: Math.round(rect.top + offset.top), // Compensate for Margins
right: Math.round(rect.right + offset.left), // Compensate for Margins
bottom: Math.round(rect.bottom + offset.top), // Compensate for Margins
left: Math.round(rect.left + offset.left) // Compensate for Margins
};
}
payload.box = box;
omxPayload.push(payload);
} else {
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
var sUrl = `ws://${document.location.hostname}:${this.config[stream].ffmpegPort}`;
var player = new JSMpeg.Player(sUrl, { canvas: canvas, disableGl: true, audio: false });
this.streams[stream].player = player;
}
this.streams[stream].playing = true;
this.playing = true;
this.updatePlayPauseBtn(stream);
return omxPayload;
},
playSnapshots: function(stream) {
// Show the snapshot instead of the stream
var snapUrl = this.config[stream].snapshotUrl;
var canvasId = (this.config.rotateStreams) ? "canvas_" : "canvas_" + stream;
var canvas = document.getElementById(canvasId);
var ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (snapUrl && this.config.showSnapWhenPaused) {
this.sendSocketNotification("SNAPSHOT_START", stream);
this.updatePlayPauseBtn(stream);
} else {
this.updatePlayPauseBtn(stream, true);
ctx.font = "16px Roboto Condensed";
ctx.fillStyle = "white";
ctx.fillText(this.config[stream].name, 10, 25);
}
},
playAll: function() {
var ps = [];
Object.keys(this.streams).forEach(s => {
if (this.instance === "SERVER" || (this.instance === "LOCAL" && this.config.remotePlayer === "ffmpeg")) {
var res = this.playStream(s);
if (res.length > 0) {
ps = ps.concat(res);
}
if (!(this.instance === "SERVER" && this.config.remoteSnaps)) {
this.sendSocketNotification("SNAPSHOT_STOP", s);
}
}
});
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
},
stopStream: function(stream, omxStopAll = false) {
if (this.streams[stream].playing) {
if (this.instance === "SERVER" && this.config.localPlayer === "omxplayer" && !omxStopAll) {
this.sendSocketNotification("STOP_OMXSTREAM", stream);
} else if (this.instance === "SERVER" && this.config.localPlayer === "vlc" && !omxStopAll) {
this.sendSocketNotification("STOP_VLCSTREAM", { name: stream, delay: this.config.shutdownDelay });
} else if ("player" in this.streams[stream]) {
this.streams[stream].player.destroy();
delete this.streams[stream].player;
}
this.streams[stream].playing = false;
}
if (Object.keys(this.streams).filter(s => { return s.playing; }).length === 0) {
this.playing = false;
}
},
stopAllStreams: function(startSnapshots = true) {
var omxStopAll = false;
if (this.instance === "SERVER" && this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("STOP_ALL_OMXSTREAMS", "");
omxStopAll = true;
}
if (this.instance === "SERVER" && this.config.localPlayer === "vlc") {
this.sendSocketNotification("STOP_ALL_VLCSTREAMS", this.config.shutdownDelay);
omxStopAll = true;
}
Object.keys(this.streams).forEach(s => {
this.stopStream(s, omxStopAll);
if (startSnapshots) {
if (!this.config.rotateStreams) { this.playSnapshots(s); }
} else {
this.sendSocketNotification("SNAPSHOT_STOP", s);
}
this.updatePlayPauseBtn(s);
});
if (startSnapshots && this.config.rotateStreams) {
this.manualTransition();
this.restartTimer();
}
},
toggleStreams: function(payload) {
var ps = [];
if (this.config.rotateStreams) {
if (this.playing) {
this.stopStream(this.currentStream);
this.playSnapshots(this.currentStream);
} else {
if ((this.instance === "SERVER" && !this.config.remoteSnaps) ||
(this.instance === "LOCAL" && this.config.remotePlayer === "ffmpeg")) {
this.sendSocketNotification("SNAPSHOT_STOP", this.currentStream);
}
if (this.instance === "SERVER" || (this.instance === "LOCAL" && this.config.remotePlayer === "ffmpeg")) {
ps = this.playStream(this.currentStream);
}
}
} else if (!this.selectedStream) {
if (this.playing) { this.stopAllStreams(); } else { this.playAll(); }
} else {
if (this.streams[this.selectedStream].playing) {
this.stopStream(this.selectedStream);
this.playSnapshots(this.selectedStream);
} else {
if ((this.instance === "SERVER" && !this.config.remoteSnaps) ||
(this.instance === "LOCAL" && this.config.remotePlayer === "ffmpeg")) {
this.sendSocketNotification("SNAPSHOT_STOP", this.selectedStream);
}
if (this.instance === "SERVER" && payload.KeyState === "KEY_LONGPRESSED") {
ps = this.playStream(this.selectedStream, true);
} else if (this.instance === "SERVER" || (this.instance === "LOCAL" && this.config.remotePlayer === "ffmpeg")) {
ps = this.playStream(this.selectedStream);
}
}
}
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
},
getScripts: function() {
return [this.file('scripts/jsmpeg.min.js')];
},
getStyles: function() {
return [`${this.name}.css`, 'font-awesome.css'];
},
notificationReceived: function(notification, payload, sender) {
var ps = [];
if (notification === "DOM_OBJECTS_CREATED") {
// Register Key Handler
if (this.config.keyBindings.enabled &&
MM.getModules().filter(kb => kb.name === "MMM-KeyBindings").length > 0) {
this.keyBindings = Object.assign({}, this.keyBindings, this.config.keyBindings);
KeyHandler.register(this.name, {
sendNotification: (n, p) => { this.sendNotification(n, p); },
validKeyPress: (kp) => { this.validKeyPress(kp); },
});
this.keyHandler = KeyHandler.create(this.name, this.keyBindings);
}
let api = {
module: this.name,
path: "stream",
actions: {
play: {
notification: "RTSP-PLAY",
prettyName: "Play Stream(s)"
},
stop: {
notification: "RTSP-STOP",
prettyName: "Stop Stream(s)"
},
fullscreen: {
notification: "RTSP-PLAY-FULLSCREEN",
prettyName: "Play Fullscreen"
},
window: {
notification: "RSTP-PLAY-WINDOW",
prettyName: "Play in Window"
},
}
};
this.sendNotification("REGISTER_API", api);
}
if (this.keyHandler && this.keyHandler.validate(notification, payload)) { return; }
// Handle USER_PRESENCE events from the MMM-PIR-sensor Module
if (notification === "USER_PRESENCE") {
if (payload) {
if (this.suspended && this.suspendedForUserPresence) {
this.resumed();
}
this.suspendedForUserPresence = false;
} else {
this.suspend();
this.suspendedForUserPresence = true;
}
}
if (notification === 'RTSP-PLAY' && this.instance === "SERVER") {
if (!payload || payload === {} || payload === 'all') {
if (this.config.rotateStreams) {
this.playing = true;
this.manualTransition(undefined, 1);
this.restartTimer();
} else {
this.playAll();
}
} else {
if (this.config.rotateStreams) {
this.playing = true;
this.manualTransition(payload);
this.restartTimer();
} else {
ps = this.playStream(payload);
}
}
}
if (notification === 'RTSP-PLAY-FULLSCREEN' && this.instance === "SERVER") {
ps = this.playStream(payload, true);
}
if (notification === 'RSTP-PLAY-WINDOW' && this.instance === "SERVER") {
ps = this.playStream(payload.name, false, payload.box);
}
if (notification === 'RTSP-STOP' && this.instance === "SERVER") {
if (!payload || payload === {} || payload === 'all') {
this.stopAllStreams();
} else {
this.stopStream(payload);
}
}
if (ps.length > 0) {
if (this.config.localPlayer === "omxplayer") {
this.sendSocketNotification("PLAY_OMXSTREAM", ps);
} else if (this.config.localPlayer === "vlc") {
this.sendSocketNotification("PLAY_VLCSTREAM", ps);
}
}
},
validKeyPress: function(kp) {
// Example for responding to "Left" and "Right" arrow
console.log(kp);
if (kp.keyName === this.keyHandler.config.map.Play) {
this.toggleStreams(kp);
}
if (kp.keyName === this.keyHandler.config.map.Next) {
if (this.config.rotateStreams) {
this.manualTransition(undefined, 1);
this.restartTimer();
} else {
this.selectStream(1);
}
} else if (kp.keyName === this.keyHandler.config.map.Previous) {
if (this.config.rotateStreams) {
this.manualTransition(undefined, -1);
this.restartTimer();
} else {
this.selectStream(-1);
}
}
},
selectedStream: '',
selectStream: function(direction = 1, clear = false) {
var k = Object.keys(this.streams);
if (!clear) {
if (!this.selectedStream) {
this.selectedStream = k[0];
} else {
var i = k.indexOf(this.selectedStream);
var newI = i + direction;
if (newI >= k.length) {
newI = 0;
} else if (newI < 0) {
newI = k.length - 1;
}
this.selectedStream = k[newI];
}
} else {
this.selectedStream = '';
}
k.forEach(s => {
if (s !== this.selectedStream) {
var iw = document.getElementById("iw_" + s);
iw.style.cssText = iw.style.cssText.replace("border-color: red;", "");
} else {
document.getElementById("iw_" + s).style.cssText += "border-color: red;";
}
});
},
// socketNotificationReceived from helper
socketNotificationReceived: function(notification, payload) {
if (notification === "STARTED") {
if (!this.loaded) {
this.loaded = true;
this.updateDom(this.config.animationSpeed);
if (!this.suspended) {
setTimeout(() => this.resumed(), this.config.animationSpeed + 500);
}
}
}
if (notification === "SNAPSHOT") {
if (payload.image) {
var img = document.getElementById("img_" + payload.name)
if (img === null) {
iw = document.getElementById("iw_" + payload.name)
img = document.createElement("img");
img.style.width = "100%";
img.style.height = "100%";
img.id = "img_" + payload.name;
console.log(iw, img)
img.className = "MMM-RTSPStream snapshot"
iw.appendChild(img)
}
img.src = payload.buffer;
}
}
},
});