Rantanen / node-mumble

Mumble client in Node.js
MIT License
155 stars 48 forks source link

Can't run sendMessage function from outside mumble.connect #96

Open sh1omi opened 7 years ago

sh1omi commented 7 years ago

Here is part of my code:

let MumbleClient;
mumble.connect( 'mumble://localhost', options, (error,client) => {
    if( error ) { throw new Error( error ); }
    client.authenticate( 'sh1bot' );

    client.on( 'initialized', () => {
        console.log('Connected to Mumble');
    });

    client.on('message', (message,user,scope) => {
        if(user.name != "sh1bot") MatrixClient.sendTextMessage("!iYtzSBNGLHCIxfsRpO:matrix.org", user.name+": "+message);
    });

    MumbleClient = client;
});

When I trying to do MumbleClient.sendMessage from outside mumble.connect it show this error:

Caught /sync error TypeError: Cannot read property 'sendMessage' of undefined
    at MatrixClient.CreateClient.MatrixClient.on (/home/sh1omi/Desktop/BridgeBot/index.js
:73:21)
sh1omi commented 7 years ago

You can close this issue.

MumbleClient.sendMessage(event.getSender() + ": " + event.getContent().body, {channel_id: [MumbleClient.user.channel.id]});

I think that "{channel_id: [MumbleClient.user.channel.id]}" should be a default for recipients.

Rantanen commented 7 years ago

Quickly thinking that sounds like a good idea. I'll take a look at it some point and make sure there's no compatibility issues, etc. with that.

Will leave this open till I do.