GithubHelp home page GithubHelp logo

Comments (4)

modeswitch avatar modeswitch commented on May 11, 2024

This needs to wait for SCTP data channels because send only works with strings right now (because of #5).

from node-webrtc.

fuson avatar fuson commented on May 11, 2024

Um... I don't understand. There is no problem if RTP Data Channels don't support duplex channels, i'll open 2 channels, this is not an issue. If content may be only strings its not a issue too, base64 save me.

Just wrap DataChannel::Send(const DataBuffer& buffer) call (set up buffer.data from const Arguments& args) into your binding and i hope i'll can make bidirectional data transfer.

from node-webrtc.

fuson avatar fuson commented on May 11, 2024

Ok, this is my quick fix before you guys make it normally.
*** src/datachannel.cc: replace stub DataChannel::Send to this one.

Handle DataChannel::Send( const Arguments& args ) {
TRACE_CALL;
HandleScope scope;

DataChannel* self = ObjectWrap::Unwrap( args.This() );

if(args.Length() == 0)
return ThrowException(Exception::Error(String::New("Not enough arguments")));

v8::Localv8::String payload = v8::Localv8::String::Cast(args[0]);

std::string message = (std::string) v8::String::AsciiValue(payload);
const webrtc::DataBuffer
buffer = new webrtc::DataBuffer(message.c_str());

self->_internalDataChannel->Send(*buffer);

TRACE_END;
return scope.Close(Undefined());
}

*** src/peerconnection.js: replace stup DataChannel.prototype.send to this one.

DataChannel.prototype.send = function send(data) {
this._getDC().send(data)
};

And for tests:

*** test/bridge.js replace doComplete()

function doComplete()
{
console.log('complete');
dataChannels['reliable'].send("fedcba"); // THIS IS SENDING TO BROWSER FROM NODE.JS !!!
}

*** test/peer.js replace doCreateDataChannels()

function doCreateDataChannels()
{
var labels = Object.keys(dataChannelSettings);
labels.forEach(function(label) {
var channelOptions = dataChannelSettings[label];
var channel = pendingDataChannels[label] = pc.createDataChannel(label, channelOptions);
channel.binaryType = 'arraybuffer';
channel.onopen = function() {
console.info('onopen');
dataChannels[label] = channel;
delete pendingDataChannels[label];
if(Object.keys(dataChannels).length === labels.length) {
doComplete();
}
};
// WE HAVE TO WAIT A MESSAGE FROM DATA CHANNEL (FROM NODE.JS IN OUR EXAMPLE) NOW!
channel.onmessage = function(message) {
console.info('onmessage', message);
}
channel.onclose = function(event) {
console.info('onclose');
}
channel.onerror = doHandleError;
});
doCreateOffer();
}

And here is the result, let's look and browser log:

signaling state change: have-local-offer peer.js:82
signaling state change: stable peer.js:82
awaiting data channels peer.js:67
ice connection state change: checking peer.js:86
ice connection state change: connected peer.js:86
onopen peer.js:119
complete peer.js:61
onmessage
MessageEvent {ports: Array[0], data: "fedcba", source: null, lastEventId: "", origin: ""…}

Thats all we need to make real WebRTC peer-to-peer between browser and node.js.

from node-webrtc.

modeswitch avatar modeswitch commented on May 11, 2024

OK, I did a quick implementation for you to play with, however it will be deprecated for SCTP data channels, which will accept arraybuffers instead.

from node-webrtc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.