First try with WebRTC

pull/1/head
Yann Flory 9 years ago
parent 09a06a8bc5
commit c4f62fb812

@ -254,7 +254,7 @@ return /******/ (function(modules) { // webpackBootstrap
_this.topologyService.broadcast(_this, protocol.message(cs.JOIN_FINISH, id));
_this.onJoining(id);
});
}).then(function (data) {
}, settings).then(function (data) {
return data;
});
}
@ -747,6 +747,7 @@ return /******/ (function(modules) { // webpackBootstrap
return new Promise(function (resolve, reject) {
var connections = [];
console.log(settings);
var socket = new window.WebSocket(settings.signaling);
socket.onopen = function () {
socket.send(JSON.stringify({ key: settings.key }));
@ -804,8 +805,10 @@ return /******/ (function(modules) { // webpackBootstrap
return new Promise(function (resolve, reject) {
var connection = undefined;
var socket = new window.WebSocket(settings.signaling);
console.log('Socket created');
socket.onopen = function () {
connection = new _this2.RTCPeerConnection(settings.webRTCOptions);
console.log('RTC created');
connection.onicecandidate = function (e) {
if (e.candidate !== null) {
var candidate = {
@ -816,6 +819,8 @@ return /******/ (function(modules) { // webpackBootstrap
}
};
var dc = connection.createDataChannel(key);
console.log('data channel created');
console.log(dc);
dc.onopen = function () {
resolve(dc);
};
@ -827,6 +832,8 @@ return /******/ (function(modules) { // webpackBootstrap
};
socket.onmessage = function (e) {
var msg = JSON.parse(e.data);
console.log('message');
console.log(msg);
if (Reflect.has(msg, 'data')) {
if (Reflect.has(msg.data, 'answer')) {
var sd = Object.assign(new _this2.RTCSessionDescription(), msg.data.answer);

@ -113,22 +113,45 @@ define([
};
var options = {
signaling: websocketUrl,
// signaling: 'ws://localhost:9000',
topology: 'StarTopologyService',
protocol: 'WebSocketProtocolService',
connector: 'WebSocketService',
openWebChannel: true
// signaling: websocketUrl,
signaling: 'ws://localhost:8000',
key: channel
// topology: 'StarTopologyService',
// protocol: 'WebSocketProtocolService',
// connector: 'WebSocketService',
// openWebChannel: true
};
console.log(options);
var realtime;
// Add the Facade's peer messages handler
Netflux._onPeerMessage = onPeerMessage;
var webchannel = Netflux.create();
webchannel.openForJoining(options).then(function(data) {
console.log('keys');
console.log(channel);
console.log(data);
webchannel.onmessage = onMessage; // On receiving message
webchannel.onJoining = onJoining; // On user joining the session
webchannel.onLeaving = onLeaving; // On user leaving the session
// console.log('resolved');
onOpen();
}, function(err) {
console.log('rejected');
console.error(err);
});
var onOpen = function() {
// Connect to the WebSocket server
Netflux.join(channel, options).then(function(wc) {
wc.onMessage = onMessage; // On receiving message
wc.onmessage = onMessage; // On receiving message
wc.onJoining = onJoining; // On user joining the session
wc.onLeaving = onLeaving; // On user leaving the session
// Open a Chainpad session
realtime = createRealtime();
@ -152,9 +175,9 @@ define([
});
// Get the channel history
var hc;
wc.peers.forEach(function (p) { if (!hc || p.linkQuality > hc.linkQuality) { hc = p; } });
hc.send(JSON.stringify(['GET_HISTORY', wc.id]));
// var hc;
// wc.peers.forEach(function (p) { if (!hc || p.linkQuality > hc.linkQuality) { hc = p; } });
// hc.send(JSON.stringify(['GET_HISTORY', wc.id]));
// Check the connection to the channel
//checkConnection(wc);
@ -168,6 +191,7 @@ define([
}, function(error) {
warn(error);
});
}
var createRealtime = function() {
return ChainPad.create(userName,
@ -215,11 +239,11 @@ define([
}
var onJoining = function(peer, channel) {
console.log('Someone joined : '+peer)
}
var onLeaving = function(peer, channel) {
console.log('Someone left : '+peer)
}
var checkConnection = function(wc) {

Loading…
Cancel
Save