首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >simplewebrtc的"sendDirectlyToAll“用法示例?

simplewebrtc的"sendDirectlyToAll“用法示例?
EN

Stack Overflow用户
提问于 2016-06-17 22:06:03
回答 1查看 456关注 0票数 2

我试图发送文本给我的所有同行,我发现这个函数"sendDirectlyToAll“。

为了方便您,我将函数信息放在这里:

sendDirectlyToAll(channelLabel,messageType,有效载荷)--通过dataChannel向房间里的所有同行广播一条消息。 字符串channelLabel - dataChannel发送的标签。 字符串messageType -发送的消息类型的键。 对象有效负载-要发送到对等点的任意值或对象。

我不明白第二和第三参数的含义。你能给我举一个如何使用这个功能的例子吗?

谢谢德里克

EN

回答 1

Stack Overflow用户

发布于 2017-02-22 14:39:03

下面是我的示例,展示了我是如何使它工作的:

代码语言:javascript
复制
/**
* 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);
        }
    }
}

此外,官方的SimpleWebRTC问题跟踪器:https://github.com/andyet/SimpleWebRTC/issues/450上也有这个问题的答案。

请参阅我在这个示例中的博客文章:https://blog.ueffing.net/post/2017/02/22/simplewebrtc-usage-example-of-senddirectlytoall/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37891029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档