question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with session.reject()

See original GitHub issue

Hi,

I’m facing a little issue with the session.reject() method on the prePublish event. If I have any kind of promise before the reject, the server let the user connect and imediatly disconnect it. If there is no promises before the reject, it doesn’t even let the user connect and I receive and error in the OBS. For clarification:

This let the user connect and imediatly disconnect it. Then, OBS reconnect a is disconnected again. It keeps on this loop.

this.nms.on('prePublish', async (id, path, args) => {
      const stream_key = this.getStreamKeyFromStreamPath(path);
      const session = this.nms.getSession(id);

      try {
        const user = await User.findOne({ where: { stream_key } });

        if (!user) {
          console.log(`[REJECT]: Stream Key ${stream_key} not found.`);
          session.reject();
        } else {
          console.log(
            `[SUCCESS]: ${user.username} connected with Stream Key ${stream_key}`
          );
        }
      } catch (error) {        
        console.log(error.message);
      }
    });

If I don’t have any promises on the event listener like this:

this.nms.on('prePublish', async (id, path, args) => {
      const stream_key = this.getStreamKeyFromStreamPath(path);
      const session = this.nms.getSession(id);

      session.reject();
    });

I receive and error on OBS: “Could not access the specified channel or stream key, please double-check your stream key…”

I know it’s probably nothing to do with the package itself, but I couldn’t find a solution to make it rejects correctly and don’t even let the user connect when I’m using promises. So, if someone can point me where I am doing it worng, I would be grateful.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
thotho19commented, Mar 22, 2020

the best solution for this problem is by creating a list outside the nms.on(); the list include all the stream_key for all the users who register to the website for example:-

const NodeMediaServer = require('node-media-server'),
      config          = require('./config/default').rtmp_server,
      User            = require('./database/Schema').User;

nms = new NodeMediaServer(config);
// ywJjVjtcR is the correct stream_key that i used in my obs 
const list = ['IeFDJwvdE', 'IeFDJwvdE', 'IeFDJwvdE', 'IeFDJwvdE',  'IeFDJwvdE', 'IeFDJwvdE', 'ywJjVjtcR' ];
nms.on('prePublish', async (id, StreamPath, args) => {
    let stream_key = getStreamKeyFromStreamPath(StreamPath);
    let count;
    for(let i = 0 ; i<=6; ++i){
        if(stream_key === list[i]){
            count = 1;
            break;
        }
    }
    if(count != 1){
        let session = nms.getSession(id);
        session.reject();
    }
});

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

this code is not best performance but i just want to share to you the idea

1reaction
dev-steverobcommented, Feb 4, 2020

I have same issue and resorted to editing the core functions rather than using the events. I will see if I can do a pull request to include this functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

session.reject with specific error code - Forums - IBM Support
Is there are way to alter the http error code returned after session.reject in gatewayscript? It is not sufficient to always give back...
Read more >
FIX session level reject - Stack Overflow
I am studying fix session layer and having some confusion about session level reject. In case of a garbled or invalid (error in...
Read more >
HTTP Cupertino session Reject - Wowza Community
I have the following issue logged recently on a server. Using Wowza 3.6.2.12 (same problem with Wowza 3.6.2.01).
Read more >
Difference between Session Level Reject and Business ...
Both Session level Reject (FIX MsgType 35=3) and Business Message Reject (FIX MsgType 35=j) is used to reject incoming FIX message. Session level...
Read more >
Player Session Rejected | AWS re:Post
Player Session Rejected. 0. Hello everyone, I have a problem that the function 'AcceptPlayerSession()' throws an error. I have checked this many times....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found