Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thotho19 opened this issue Mar 24, 2020 · 0 comments

Comments

@thotho19
Copy link

thotho19 commented Mar 24, 2020

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant