RocketChat / feature-requests

This repository is used to track Rocket.Chat feature requests and discussions. Click here to open a new feature request.
21 stars 9 forks source link

YouTube Livestream & Broadcasting on Rocket.Chat Not Working #649

Open Syirrus opened 5 years ago

Syirrus commented 5 years ago

Description:

Youtube Broadcasting is not working. After entering in: broadcasting_client_id: XXXXX Broadcasting_client_secret: XXXXX broadcasting_api_key: XXXXX broadcasting_media_server_url: wss://a.rtmp.youtube.com/live2

I receive the following error: WebSocket connection to 'wss://a.rtmp.youtube.com/live2/0000-0000-0000-0000' failed: Error in connection establishment: net::ERR_CERT_COMMON_NAME_INVALID.

Where the 0000-0000-0000-0000 is the stream name/key

How can I get this to work? When I try rtmp://a.rtmp.youtube.com/live2/0000-0000-0000-0000 it says that rtmp:// is not allowed.

Steps to reproduce:

  1. Setup Youtube Broadcasting in the admin settings.
  2. Go to any channel and broadcast your camera.

Expected behavior:

To be able to broadcast and stream onto YouTube

Actual behavior:

The camera activated and then I get the follow error written above.

Server Setup Information:

reetp commented 5 years ago

First - please upgrade to the latest version of Rocket.Chat

Your version is seriously out of date, so if there is an issue it will not be fixed in your version.

Current stable is now v1.0.3

Next if you search online for this error "ERR_CERT_COMMON_NAME_INVALID" you will see that it means the certificate does not match the hostname used.

i.e you have asked for "a.rtmp.youtube.com" but the certificate shows "youtube.com"

You can test that simple by pasting https://a.rtmp.youtube.com in a browser.

So that means that most likely the Broadcast URL is incorrect.

How about something like: https://youtube.com/live2

I presume that is the stream you want to actually broadcast too?

Syirrus commented 5 years ago

@reetp thank you for responding. According to commits, this feature was implemented back in early to mid 2018 and was working. The build that I'm using is from late 2018. Nevertheless, I will update as soon as I can for sure.

I tried putting in https://youtube.com/live2 and I get the following error: 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'https' is not allowed.

Is the Broadcast URL the URL of the channel or the URL that you stream to? Based on what your are saying I'm starting to this it could be the channel URL i.e. https://www.youtube.com/channel/UCin9nv7mUjoqrRiwrzS5UVQ

For example the above URL would be the Rocket.Chat youtube channel. Is that correct?

reetp commented 5 years ago

@reetp thank you for responding. According to commits, this feature was implemented back in early to mid 2018 and was working. The build that I'm using is from late 2018. Nevertheless, I will update as soon as I can for sure.

With the pace of development that is a long time ago! You are about 5 versions behind current (0.72,0.73,0.74,1.x) Be careful on upgrading - one version at a time is better, with backups between. And enable mongo replicasets before upgrading to to v1.x

I tried putting in https://youtube.com/live2 and I get the following error: 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. 'https' is not allowed.

OK - I am not familiar with how it works, and the documentation is not clear about it - just trying to eliminate a few things

Is the Broadcast URL the URL of the channel or the URL that you stream to? Based on what your are saying I'm starting to this it could be the channel URL i.e. https://www.youtube.com/channel/UCin9nv7mUjoqrRiwrzS5UVQ

That is kind of what I was thinking. This is using the API to 'login' programatically to allow you to post.

For example the above URL would be the Rocket.Chat youtube channel. Is that correct?

Yes I think so.

What about if you try:

wss://www.youtube.com/live2

or effectively:

wss://www.youtube.com/channel/UCin9nv7mUjoqrRiwrzS5UVQ

Syirrus commented 5 years ago

@reetp Thank you for responding again. I did try the URI wss://www.youtube.com/channel/UCin9nv7mUjoqrRiwrzS5UVQ and it looks promising. Unfortunately I have reached my Google API query limit :( . I will try tomorrow and post a follow up.

Syirrus commented 5 years ago

@reetp Okay, i tried what you suggested using my own channel and I'm getting the following error: Exception while invoking method 'livestreamGet' Error: User requests exceed the rate limit.

My YouTube API v3 quota has been reset for the day, so I'm not sure as to why I'm getting this error. There must be something I'm missing with this YouTube API stuff. The only application that is hitting the YouTube API is Rocket.chat and I'm already up to 1,085 queries. I'm not sure what is happening in the background that rocket.chat is querying the YouTube API that much.

Any ideas?

reetp commented 5 years ago

Personally no I don't, and hope that one of the devs will give some advice on the correct syntax because the docs don't do properly. Some examples would be useful.

geekgonecrazy commented 5 years ago

I don't know that this feature was designed to stream directly to youtube. I think there is meant to be a component in the middle that transcodes and sends off to youtube.

I seem to remember a nodejs / ffmpeg setup needed that this hit and relayed off to youtube.

@RocketChat/core can anyone confirm this?

ggazzo commented 5 years ago

@geekgonecrazy you are right, there two ways to use the livestream feature,

1th get a youtube livestream url( you can handle your stream as you are) and paste on the form 2th make stream inside of rocketchat, actually the name is Broadcasting.

but you need an "encoder server", something like that should work: ( you can use even a localhost process)

const { Server } = require('ws');
const ffmpeg = require('fluent-ffmpeg')
const wsStream = require('websocket-stream')

const server = new Server({port: process.env.PORT || 8000, perMessageDeflate: false});

server.on('connection', function(websocket, req) {
    const name = req.url.replace('/', '');
    console.log(`New connection with ${name}`);
    if (!name) {
        return websocket.terminate();
    }
    const stream = wsStream(websocket);
    const encoder = ffmpeg()
        .input(stream)
        .videoCodec('libx264')
        .audioCodec('libmp3lame')
        .outputFPS(24)
        .addOption('-preset:v', 'ultrafast')
        .videoBitrate('500k')
        .audioBitrate('128k')
        .size('?x480')
        .addOption('-f', 'flv')
        .on('error', function(err) {
            console.log(`Error: ${ err.message }`);
        })
        .save(`rtmp://a.rtmp.youtube.com/live2/${ name }`, function(stdout) {
            console.log(`Convert complete${ stdout }`);
        });

    websocket.on('error', (err) => {
        console.log('error', err)
    });

    websocket.on('close', () => {
        console.log(name, 'close')
    });
});

console.log(`Listening on port ${process.env.PORT || 8000}`);

@geekgonecrazy this code solves the issue? :x

Syirrus commented 5 years ago

@geekgonecrazy @ggazzo So in essentially you need something like the NODE code above or OBS to encode the stream to YouTube. Once you have the server setup then you input that into the "Broadcasting_media_server_url" URL?

The post says nothing about that, but it makes sense.

https://github.com/RocketChat/Rocket.Chat/pull/10127

reetp commented 5 years ago

A bit of follow up, and this needs documenting really.

Install node.

npm install ws fluent-ffmpeg websocket-stream
mkdir ~/utoob
cd ~/utoob
nano encode.js
Now run it with `node encode.js` [root@test utoob]# node encode.js Listening on port 8000
digitalsleuth commented 3 years ago

Getting the same original issue, docker for Rocket.Chat 3.4.2 and 3.5.1 (upgraded to see if the issue would resolve). Google API's all set up, getting 200's across the board, not hitting any quota. Getting ERR_CERT_COMMON_NAME_INVALID for the wss://a.rtmp.youtube.com/live2/ (I know what the ERR_CERT_COMMON_NAME message means).

These errors come when I click 'Broadcast my Camera' under 'Livestream'. The camera turns on for a second, get the error, turns off. The only way I've managed to actually see these errors is by using the Developer Console in the browser, as for some reason there are no logs available in the Rocket.Chat Docker? Unless I can't find them..

My questions: 1) What URL actually goes in the Broadcast Media Server URL field? 2) If it's supposed to go through YouTube, and YouTube uses rtmp://, why does this require WSS? 3) Do I require any additional software/hardware to complete this? 4) Can someone from the Rocket.Chat team update the documentation for detailed usage of the Livestream/Broadcast functions, more than just the 'more details available at the Google Developers page'? 5) Rocket.Chat/YouTube does not seem to enable the embedding of an actual 'Live Stream'. Only videos which can be streamed from YouTube, but not an actual Live Stream. Is there some way to fix this?

ANY help would be appreciated.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

gitthedonkey commented 3 years ago

Any progress on setting this up in RChat under Administrator Settings? Do I need "encoder server" snipit posted above?

I have obs streaming to Youtube studio. Have the stream key. I also registered youtube api and have client ID, secret, and api key.

Tried variety of settings in Administrator-->Livestreaming/Broadcast.

I cannot broadcast stream.

When I select broadcast in web rchat, a popup window appears, but with 404 error code.

Are there firewall ports that need opening? 8000/tcp ?

I'm running Centos 8 RC v3.7.1 Apps Eng: 1.18 Node version: 12.19.0 Mongo Version: 4.0.20 with mmapv1 engine

jlfguthrie commented 3 years ago

The documentation really needs to be more specific in order to configure correctly.

Has anybody managed to figure out how to get this up and running and willing to share their config example?