The node is unaware of what is happening on the client side. It simply receives the playlist and sends it to the client side where there is an attempt to play it.
If you wanted to handle the client side event on the video element, you can add the event listener to detect ended
and send a message back using scope.send. If you added this little piece of code on the controls, you could detect the event and send a message and somehow load the next video from your list. Of course, this would make it change for all viewers since the dashboard is designed to be single user.
const video = document.getElementById(msg.videoId);
if (video) {
video.addEventListener('ended', () => {
scope.send('it ended');
});
This successfully sent a message to my debug panel.
It would need more work so that to only detects the ended event when you want it to, maybe with some checkbox control. Just a proof of concept at this point...
1 Like
Works great, really useful. Understood, it is events from the HTMLMediaElement you have to watch. Many useful and interesting:
1 Like
In this situation, it might be better to set the onended
property with the callback function vs adding the event listener. This will help to ensure that you have only added the callback a single time. And instead of removing the event listener, you can just delete the onended property (or maybe set to null or call removeAttribute, can't remember right now at the top of my head).
Well, both works fine, why is one better than the other?
Best regards, Walter
if (video) {
video.onended = function() {myEnd()};
function myEnd() {
scope.send('the end');
}
video.addEventListener('ended', () => {
scope.send('it ended');
});
video.addEventListener('playing', () => {
scope.send('it plays');
});
video.addEventListener('pause', () => {
scope.send('it paused');
});
Assigning it as a property only allows 1 handler, whereas adding the event listener will allow more than 1 handler. If you are only need a single callback, which is most likely the case for this particular situation, then using the property might be simpler and you won't accidentally add too many event listeners. Other than that, I don't know if one is better or just a matter of preference.
1 Like
Is anybody here using nginx along with the cctv stuff? I have been deep diving nginx over the last month and found some interesting techniques to offload some burden from the node-red instance, in particular when playing back recordings and using nginx's slice module. Hopefully I can get a small change to node-red core to allow this to work. If anybody is interested in nginx integration with the cctv things, then maybe we can start a new thread for that. Let me know.
1 Like
If you found something interesting, please yes explain it a new thread 
1 Like