SimpleWebRTC: usage example of sendDirectlyToAll
2017-02-22 00:00:00
IN1
,
2023-04-10 14:16:29
IN1
How to send text or data to all peers in SimpleWebRTC by using sendDirectlyToAll
method.
Here is my usage example showing how i managed to get it working:
/**
* send directly to all other peers
*/
oSimpleWebRTC.sendDirectlyToAll(
'meta', // sLabel
'info', // sType - will become oData.sType
{"foo": "bar"} // oData - will become oData.payload
);
/**
* Handle incoming dataChannel messages sent by "sendDirectlyToAll"
* @param {object} oPeer The Remote sending Peer Object
* @param {string} sLabel A Label, e.g.: 'meta'
* @param {object} oData Object containing the relevant Data
*/
oSimpleWebRTC.on('channelMessage', function (oPeer, sLabel, oData) {
// e.g. we want label "hark" to be ignored, as it fires continiously.
if ('hark' === sLabel) {
return true;
}
if ('meta' === sLabel) {
if ('info' === oData.type)
{
// do your stuff
console.log(oData.payload.foo);
}
}
}
Links
- SimpleWebRTC Project from andyet, github, 2017-02-22:
https://github.com/andyet/SimpleWebRTC - Above solution posted by me on stackoverflow, stackoverflow, 2017-02-22:
https://stackoverflow.com/a/42394527/2487859 - Answers to question "Is there a usage example of 'sendDirectlyToAll'?"
at the official SimpleWebRTC issues Tracker, github, 2017-02-22:
https://github.com/andyet/SimpleWebRTC/issues/450#issuecomment-281689890