Fix logging in cluster.ts

Fix a bug calling the cluster process in index.ts
Set a default value for rtmp.cluster in config.ts
Update documentation
pull/2/head
knotteye 2020-10-17 21:20:32 -05:00
parent de17128cd2
commit ab082e5f95
7 changed files with 28 additions and 18 deletions

View File

@ -3,7 +3,7 @@ This is not a guide to using the webchat, this a reference point for writing cli
Satyr's webchat is based on [socket.io](https://socket.io/), you can find clients for [Java](https://github.com/socketio/socket.io-client-java), [C++](https://github.com/socketio/socket.io-client-cpp), [Swift](https://github.com/socketio/socket.io-client-swift), [Dart](https://github.com/rikulo/socket.io-client-dart), and probably more.
Socket.IO is loosely reminiscent of IRC in that you will receive events from the server and sent events to it. The following is a list of incoming and outgoing events you will need to handle or send. If you would like to see examples, templates/chat.html is implementation used in the webclient by satyr.
Socket.IO is loosely reminiscent of IRC in that you will receive events from the server and sent events to it. The following is a list of incoming and outgoing events you will need to handle or send. If you would like to see examples, templates/chat.html is the implementation used in the webclient by satyr.
# Incoming Events
These are events you will recieve from the server that need to be handled in some way.
@ -53,12 +53,12 @@ This is a request to set the client's nickname. The data attached to a NICK even
password: "the optional password"
}
```
During the initial connect of the client, the server will check for the "Authorization" cookie. If the cookie is a valid, signed JWT, the client will be assigned the nickname of the user that cookie belongs to. If it doesn't exist or is invalid, the client will be assigned a nickname of the form Guest+some integer.
During the initial connect of the client, the server will check for the "Authorization" cookie. If the cookie is a valid, signed JWT the client will be assigned the nickname of the user that cookie belongs to. If it doesn't exist or is invalid, the client will be assigned a nickname of the form Guest+some integer.
The server will send an alert notifying the client of either the nickname change, or some error.
## MSG
This is a chat message to send to room. It should be a JSON object in the following format:
This is a chat message to send to a room. It should be a JSON object in the following format:
```
{
room: "the room to send the messag to",
@ -117,10 +117,10 @@ A request to unban an IP address. It can only be done by the owner of the room.
# Final Notes
Sending more than 10 messages a second will cause the server to kick your client. If kicked this way 3 times, the client will be banned for 20 minutes.
Sending more than 10 messages per second will cause the server to kick your client. If kicked this way 3 times, the client will be banned for 20 minutes.
Kicked or banned users will not be notified of this through an event.
The server *will* send your own MSG events back to you, you will need to parse them out if you want to append them immediately.
The server *will* send your own MSG events back to you, you will need to parse them out if you want to display them immediately.
Clients who successfully authenticate as a registered user, through either a password or a signed JWT, can ignore nickname collision and have as many connections as they wish.

View File

@ -7,11 +7,23 @@ Some values you might want to change are
satyr:
registration: true
# allow new users to register
port: 8000
# the port to serve http on
http:
hsts: true
# enable strict transport security
rtmp:
port: 1935
# change the port to serve rtmp on
cluster: false
# enable clustering for the RTMP server
# clustering is an attempt to take better advantage of multi threaded systems in spite of node.js being single-threaded
# satyr will spawn one RTMP Worker per CPU core, and round-robin incoming connections between workers
# If you turn this on, satyr will no longer be able to reliably serve RTMP streams to clients
# Your users will have to use DASH instead
media:
record: true
# allow users to record VODs
@ -36,7 +48,7 @@ transcode:
# https://trac.ffmpeg.org/wiki/HWAccelIntro is a good place to start
# having more than 4-5 variants will start giving diminishing returns on stream quality for cpu load
# if you can't afford to generate at least 3 variants, it's reccomended to leave adaptive streaming off
# if you can't afford to generate at least 3 variants, it's recommended to leave adaptive streaming off
crypto:
saltRounds: 12
@ -49,7 +61,6 @@ chat:
# for their chat at /profile/chat
irc:
enabled: true
# enable irc mirroring
server: chat.freenode.net
port: 6697
tls: true
@ -61,7 +72,6 @@ chat:
discord:
enabled: true
# enabled discord integration
token: abcdefghijklmnopqrstuvwxyz
# the access token for the bot
# note that the bot will mirror every channel matching the name the user has chosen
@ -77,10 +87,9 @@ chat:
xmpp:
enabled: true
# enable xmpp
server: '404.city'
server: 'example.com'
port: 5222
jid: 'satyr-dev@404.city'
jid: 'exampleBot@example.com'
password: 'abcde'
# connection settings for the bot
nickname: 'SatyrChat

View File

@ -4,7 +4,7 @@ A more detailed walkthrough.
### System Dependencies
Install ffmpeg(>= 4.2.1) and mysql through your distribution's package manager.
See [this page](https://nodejs.org/en/download/package-manager/) for instructions on installing node v10.
If the version in your distro's package manager is different, you can install 'n' through npm to manage node versions.
If the version in your distro's package manager is different, you can install [n](https://www.npmjs.com/package/n) through npm to manage node versions.
### Installing Satyr
Before starting, you should create a system user to run the satyr service.

View File

@ -1,7 +1,7 @@
## Satyr Usage
### Administration
Satyr needs access to port 1935 for RTMP streams, and will serve HTTP on port 8000. The ports can be changed with follow config lines.
Satyr needs access to port 1935 for RTMP streams, and will serve HTTP on port 8000. See CONFIGURATION.md for details on changing this.
For HTTPS, run a reverse proxy in front of satyr. An example nginx block is shown below.
```

View File

@ -133,14 +133,14 @@ if (cluster.isMaster) {
db.query('update user_meta set live=true where username=\''+results[0].username+'\' limit 1');
db.query('SELECT twitch_key,enabled from twitch_mirror where username='+db.raw.escape(results[0].username)+' limit 1').then(async (tm) => {
if(!tm[0]['enabled'] || !config['twitch_mirror']['enabled'] || !config['twitch_mirror']['ingest']) return;
console.log('[NodeMediaServer] Mirroring to twitch for stream:',id)
console.log(`[RTMP Cluster WORKER ${process.pid}] Mirroring to twitch for stream: ${id}`)
execFile(config['media']['ffmpeg'], ['-loglevel', 'fatal', '-i', 'rtmp://127.0.0.1:'+wPort+'/'+config['media']['privateEndpoint']+'/'+key, '-vcodec', 'copy', '-acodec', 'copy', '-f', 'flv', config['twitch_mirror']['ingest']+tm[0]['twitch_key']], {
detached: true,
stdio : 'inherit',
maxBuffer: Infinity
}).unref();
});
console.log('[NodeMediaServer] Stream key ok for stream:',id);
console.log(`[RTMP Cluster WORKER ${process.pid}] Stream key ok for stream: ${id}`);
console.log(`[RTMP Cluster WORKER ${process.pid}] Stream key ok for stream: ${id}`);
//notify master process that we're handling the stream for this user
process.send({type: 'handle-publish', name:results[0].username});
@ -171,14 +171,14 @@ if (cluster.isMaster) {
let key: string = StreamPath.split("/")[2];
//correctly formatted urls again
if (StreamPath.split("/").length !== 3){
console.log("[NodeMediaServer] Malformed URL, closing connection for stream:",id);
console.log(`[RTMP Cluster WORKER ${process.pid}] Malformed URL, closing connection for stream: ${id}`);
session.reject();
return false;
}
//localhost can play from whatever endpoint
//other clients must use private endpoint
if(app !== config['media']['publicEndpoint'] && !session.isLocal) {
console.log("[NodeMediaServer] Non-local Play from private endpoint, rejecting client:",id);
console.log(`[RTMP Cluster WORKER ${process.pid}] Non-local Play from private endpoint, rejecting client: ${id}`);
session.reject();
return false;
}

View File

@ -30,6 +30,7 @@ const config: Object = {
insecureAuth: false,
debug: false }, localconfig['database']),
rtmp: Object.assign({
cluster: false,
port: 1935,
chunk_size: 6000,
gop_cache: true,

View File

@ -10,7 +10,7 @@ async function run() {
await initDB();
await clean();
await initHTTP();
config['rtmp']['cluster'] ? execFile(process.cwd()+'/node_modules/.bin/ts-node' [process.cwd()+'src/cluster.ts']) : await initRTMP();
config['rtmp']['cluster'] ? execFile(process.cwd()+'/node_modules/.bin/ts-node', [process.cwd()+'/src/cluster.ts']) : await initRTMP();
await initChat();
console.log(`Satyr v${config['satyr']['version']} ready`);
}