Comments (4)
This needs to wait for SCTP data channels because send only works with strings right now (because of #5).
from node-webrtc.
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.
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.
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)
- Nonstandard APIs (RTCAudioSource) : Multiple tracks created from same source, all tracks do not get audio. only latest track gets audio. HOT 1
- Forcing a fixed samplerate when using `nonstandard.RTCAudioSink`
- change video quality HOT 9
- streaming video and audio with dely
- `npm i -S wrtc` —> `node-pre-gyp` error HOT 4
- Does it support v4l2 source? HOT 1
- Is this still maintained? HOT 1
- Is Programmatic Video not the real media stream?
- Error in Build from Source
- electron >= 20 crashes if receiving a buffer with simple-peer
- ncmake build failed for wrtc (darwin arm64) HOT 1
- is TURNS (Turn over TLS) supported? HOT 1
- 'npm install wrtc' always failed with http error 503, but wget the tarball succeeded.
- High CPU usage on raspberry pi HOT 2
- Is this repo stale / abandoned? HOT 3
- Cannot download binaries - Darwin m2 Pro 14.0 HOT 4
- i am unable to install on nodejs windows 10 HOT 2
- Is there an easy way to use it for node 18|20 HOT 1
- The dependency to `msdmo.dll` for Windows is not documented HOT 1
- No longer able to install modul wrtc on Macos (M3 Pro) HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-webrtc.