Project

General

Profile

How to access a stream via JavaScript?

Added by M F over 3 years ago

Hi all,

I am trying to write a HTML/JS-based app to play a channel from TVHeadend via the browser.
After much fiddling I have managed to use digest authentication and I can retrieve the channel list via this TVH api URI:
/api/channel/grid?limit=1000

This returns - among other things - the UUID of each channel.
Now in order to play a channel I wanted to assign the URL http://192.168.0.4:9981/stream/channelid/UUID?profile=htsp as video source in HTML5 where UUID is the actual UUID.
However this will not play. Is this the correct way to accomplish what I am trying to do? I have tried different profile values and skipping the profile parameter altogether - without success.

When I check the TVH admin interface and I click the "play" link of any channel there, I get a link of the following syntax:
http://192.168.0.4:9981/stream/channel/UUID?ticket=SOME_ID

Now I am wondering if I can create the ticket value via the API and then build my link correctly? Is there a way to do this? I have searched the web for literally days but I cannot find an answer.
If not, then what else can I do to get a stream after having authenticated successfully via digest authentication?

Best regards
mf_2

Edit: Just saw the "how to ask a good question" topic, so here we go:

Version of TVHeadend? 4.3~9ed76c0
Running on what OS and version? Synology NAS on DSM Manager 6
Package that came with the OS or something you compiled yourself? Came with the Synology Package Manager
Adapter/tuner chipset or make/model? Triax TSS 400 MKII SAT>IP Converter


Replies (3)

RE: How to access a stream via JavaScript? - Added by Dave Pickles over 3 years ago

Your first example http://192.168.0.4:9981/stream/channelid/UUID?profile=htsp works for me with wget, however I'm using TVH with user authentication effectively turned off (the "*" user can do anything provided he's on the local subnet).

One quirk in the code I've spotted: if the streaming profile specified doesn't exist or is invalid or not allowed, the htsp profile is used instead. Only if htsp can't be used do you get an error.

RE: How to access a stream via JavaScript? - Added by M F over 3 years ago

The channelid URL never starts playing in the JS video element. That's why I was wondering if I can use the stream/channel URL with a ticket parameter instead.
But I am just as happy if I can get the channelid URL to work instead.
Maybe I am wrong about trying to set the channelid URL to a Javascript element. I am not sure if that is possible.
My code is as follows:

function addSourceToVideo(element, src, type) {
    var source = document.createElement('source');

    source.src = src;
    source.type = type;

    element.appendChild(source);
}
addSourceToVideo(document.getElementById('vid'), 'http://192.168.0.4:9981/stream/channelid/UUID?profile=htsp', 'video/webm');

I have checked different values for the type attribute, but no luck.
The "vid" element is a video tag inside my webpage:

<video id="vid">
</video>

The code gets executed without any JS errors (I can check that via the Debug Console), but nothing happens in the video element on the page and I do also not see any traffic about it in the network tab of the Debug Console.

I wonder if this can even work as I am simply using the plain URL without any token from the digest authorization. I more or less expected to get a 401/unauthorized response from TVH but instead I don't see anything.

The video element on the webpage stays dark and nothing happens even if I click the "play" button manually.

RE: How to access a stream via JavaScript? - Added by Dave Pickles over 3 years ago

I've never used HTML5 video so can't help there. However you could narrow down the search for the problem by first copying part of the stream to a local file and then trying to view that through your JS.

    (1-3/3)