pipobscure / NodeJS-AsteriskManager

NodeJS Asterisk Manager API
Other
249 stars 103 forks source link

Fail on using asteriskManager with websocket socket.io #69

Closed Ritchelly closed 1 year ago

Ritchelly commented 4 years ago

Hy guys,

I'm tryning to use the asteriskManager with socket.io, but in some blocks I cant't receive the emits. Existis some way of run this lib with socket.io.

When I put io.sockets.emit into managerevent into IF condition or into ami.on('hangup' ...) for exemple, I don't receive the emit in my front end. But, if I put the emit into 'managerevernt' block out of "IF" condition, I received a emit in my frontend.

In all cases, I got the console.log return. Looks like have some incompatibility or interference of asteriskManager with socket.io.


var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

ami = new require('asterisk-manager')('5038','localhost','admin','admin', true);
ami.keepConnected();

ami.on('managerevent', function(evt) {
    io.emit('server', evt); // In this part I receive the socket emit

    if (evt.actionid == 'Ritch') {  //But into this if, I don't receive the emit, only print the console.log
        console.log(evt);
        io.sockets.emit('server', evt); 
    }
});

ami.on('hangup', function(evt) {  //I don't receive the emit, only print the console.log
    io.sockets.emit('server', evt); 
    coinsole.log(evt);
});

ami.action({
    'action':'QueueStatus',
    'Queue':'callcenter',
    'actionid':'Ritch'
  }, function(err, res) {
      console.log(res);
     io.sockets.emit('server', res); 

});

http.listen(3001, function(){
    console.log('listening on *:3001');
});
´´´
bubblegumoff commented 2 years ago

На мой взгляд тут проблема в конфигурации socket.io. Попробуйте вместо io.sockets.emit отправить io.emit. Если сработает, значит проблема в io.socket.emit. Для примера отправьте io.to("ID клиентского сокета").emit