simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.66k stars 1.19k forks source link

Text Chat #674

Open supun19 opened 6 years ago

supun19 commented 6 years ago

I want to use simple text chat with video audio chat

i use this function webrtc.sendToAll('chat', {message: "hello"});

    webrtc.connection.on('message', function(data){
        console.log(data)
        if(data.type === 'chat'){
            console.log('chat received',data);

        }
    });

its not received chat data but other data got

could you suggest how to do it

MatthieuHPP commented 6 years ago

Hello Supun19,

Here is what is working on my side using webrtc channel. I hope this can help.

// to emit the message webrtc.sendDirectlyToAll('channelMessage','chat', data)

// to receive the message

webrtc.on('channelMessage', function (peer, label , data) {
      if(data.type === 'chat'){
         // handle data.payload
      }
}

Matthieu

dcotoz commented 6 years ago

You have to check the 'channelMessage' event

supun19 commented 6 years ago

thanq you response @dcotoz and @MatthieuHPP