Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bidirectional message sending #14

Closed
fuson opened this issue Oct 18, 2013 · 4 comments
Closed

Bidirectional message sending #14

fuson opened this issue Oct 18, 2013 · 4 comments

Comments

@fuson
Copy link

fuson commented Oct 18, 2013

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

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

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

Add some code pls. :)

@modeswitch
Copy link

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

@fuson
Copy link
Author

fuson commented Oct 19, 2013

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.

@fuson
Copy link
Author

fuson commented Oct 19, 2013

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.

@modeswitch
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants