Skip to content

Latest commit

 

History

History
91 lines (57 loc) · 2.68 KB

README.md

File metadata and controls

91 lines (57 loc) · 2.68 KB

rtmp-interceptor

A simple TCP server that intercepts RTMP packets in order to get the tcURL and API key, and proxify (or reject) the packets to your remote server (nginx-rtmp-module for example). It allows you to easily authentify your RTMP stream with your API to accept or reject incoming stream.

Installation:

npm i rtmp-interceptor

Usage

Intercept tcUrl and streamKey

Intercept tcurl, streamkey, then forward the data to the specified rtmp server (localhost:1935).

const RTMPInterceptor = require('rtmp-interceptor')

const params = {
  listenPort: '1936'
}

RTMPInterceptor.listen(params, (client, tcUrl, SKey) => {
  console.log('tcUrl: '+tcUrl)      /* Do something with the data ... */
  console.log('StreamKey: '+SKey)

  return {                          /* Return false to block client and close stream */
    host: 'localhost',
    port: '1935'
  }
})

Open OBS, and start streaming on 'rtmp://localhost:1936/live'

Output:

tcUrl: rtmp://localhost:1936/live StreamKey: specified stream key

Authentify client

You can choose to proxify or reject the client, based on the streamkey or tcurl for example. See this example

Hook streamKey

Hooking the rtmp streamkey could be used when a client hasn't the stream key input (GoPRO for example) It allows you to pass the stream key in the tcurl for example, and hook it into the RTMP packet.

const RTMPInterceptor = require('rtmp-interceptor')

const params = {
  listenPort: '1936'
}

RTMPInterceptor.listen(params, async (client, tcUrl, SKey) => {
  console.log('tcUrl: '+tcUrl)      /* Do something with the data ... */
  console.log('StreamKey: '+SKey)

  return {                          /* Return false to block client and close stream */
    host: 'localhost',
    port: '1935',
    skChunks: ['\u0004\u0000\u0000\u0000\u0000\u0000)\u0014\u0001\u0000\u0000\u0000\u0002\u0000\u0007publish\u0000@\u0014\u0000\u0000\u0000\u0000\u0000\u0000\u0005\u0002\u0000\u000bMyHookedKey\u0002\u0000\u0004live']
  }
})



Server will see stream key as: MyHookedKey

Note: This method does not build the chunk: you have to build it yourself and pass the full chunk.

Result with OBS

example/interceptUrl.js

See examples

Features:

  • Intercept RTMP tcUrl
  • Intercept RTMP API KEY
  • Hook stream key
  • Build stream key chunk (PR is welcomed)