Skip to content

drop stream (reject) if the obs stream_key != to database client stream_key #17

Description

@thotho19

the problem is :- when the client try to connect to the server with wrong stream_key is obs access to server and share 2 frames or 3 then ==> session.reject() work.
i fixed this issue by creating a list with stream_keys and compare the obs stream_key with the database stream_key my code :-

File Name:- media_server.js

const NodeMediaServer = require('node-media-server'),
      config          = require('./config/default').rtmp_server,
      User            = require('./database/Schema').User;
var keys = [];
User.find({} , (err , result)=>{
    result.forEach((key)=>{
        keys.push(key.stream_key);
    });
});

nms = new NodeMediaServer(config);
nms.on('prePublish', async (id, StreamPath, args) => {
    let stream_key = getStreamKeyFromStreamPath(StreamPath);
    let count;
    for(let i = 0 ; i<=keys.length; ++i){
        if(stream_key === keys[i]){
            count = 1;
            break;
        }else{
            count = 0;
        }
    }
    if(count != 1){
        let session = nms.getSession(id);
        session.reject();
    }
});

const getStreamKeyFromStreamPath = (path) => {
    let parts = path.split('/');
    return parts[parts.length - 1];
};
module.exports = nms;

the final result when the client enter a wrong stream_key obs is going to send alert and client never going to send any frame to the server side
Screenshot from 2020-03-24 08-13-24
*note using forEach will case a bad performance...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions