Transferring JSON between browsers with WebRTC

前端 未结 7 1572
一向
一向 2020-12-30 04:32

I was excited by the prospect of WebRTC when I heard about it initially. It sounded like websockets but without a server. Unfortunately, all of the tutorials I have been a

相关标签:
7条回答
  • 2020-12-30 04:49

    I believe Matt already know, but for google guests: Yes, you can, useing DataChannels.

    On your side:

    channel = somePeerConnection.createDataChannel("a Label");
    channel.onopen = function() { channel.send("any thing") };
    

    On the other side:

    somePeerConnection.ondatachannel = function (evt) {
       evt.channel.onmessage = function (evt) {
           alert( evt.data );
       };
    };
    

    See this examples:

    • http://www.w3.org/TR/webrtc/#examples
    • https://hacks.mozilla.org/2012/11/progress-update-on-webrtc-for-firefox-on-desktop/#file-datachannels-js-LC12
    0 讨论(0)
  • 2020-12-30 04:56

    http://peerjs.com/ is evolving and gives you a websocket like syntax for p2p Data transfer between browser instances

    0 讨论(0)
  • 2020-12-30 04:59

    As Justin indicated, the protocol and API are still being nailed down; at the latest IETF I submitted a draft for the minor protocol underneath the JS API. The final form will likely be very close to the current proposal in the editor's draft, but you'll likely need to wait on "onopened" from the receiving side as well.

    The API is modeled on the WebSocket api to ease moving code from a WebSocket implementation to DataChannels, though not all items in WebSocket carry over (such as url), and obviously DataChannel adds a number of abilities not in WebSockets having to do with unreliable or partly-reliable data.

    0 讨论(0)
  • 2020-12-30 05:01

    DataChannel has now been implemented in Firefox (18+) and Chrome (25+), though it's still early days.

    For more information see the HTML5 Rocks article Getting Started with WebRTC.

    0 讨论(0)
  • 2020-12-30 05:02

    This functionality is not yet implemented in any shipping WebRTC implementation. As other posters have indicated, there now is a DataChannel API in the latest WebRTC editors' draft, but the protocol for this is still being worked on. Expect to see this API live in Chrome and Firefox later this year.

    0 讨论(0)
  • 2020-12-30 05:07

    This is a stab in the dark, but the latest Web API editors draft has a DataChannel interface as part of the Peer-to-Peer Data API.

    However, the current Working Draft does not have this API, so possibly it is very new and as-yet unimplemented.

    0 讨论(0)
提交回复
热议问题