First try with WebRTC
This commit is contained in:
@@ -254,7 +254,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
_this.topologyService.broadcast(_this, protocol.message(cs.JOIN_FINISH, id));
|
_this.topologyService.broadcast(_this, protocol.message(cs.JOIN_FINISH, id));
|
||||||
_this.onJoining(id);
|
_this.onJoining(id);
|
||||||
});
|
});
|
||||||
}).then(function (data) {
|
}, settings).then(function (data) {
|
||||||
return data;
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -747,6 +747,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
|
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var connections = [];
|
var connections = [];
|
||||||
|
console.log(settings);
|
||||||
var socket = new window.WebSocket(settings.signaling);
|
var socket = new window.WebSocket(settings.signaling);
|
||||||
socket.onopen = function () {
|
socket.onopen = function () {
|
||||||
socket.send(JSON.stringify({ key: settings.key }));
|
socket.send(JSON.stringify({ key: settings.key }));
|
||||||
@@ -804,8 +805,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var connection = undefined;
|
var connection = undefined;
|
||||||
var socket = new window.WebSocket(settings.signaling);
|
var socket = new window.WebSocket(settings.signaling);
|
||||||
|
console.log('Socket created');
|
||||||
socket.onopen = function () {
|
socket.onopen = function () {
|
||||||
connection = new _this2.RTCPeerConnection(settings.webRTCOptions);
|
connection = new _this2.RTCPeerConnection(settings.webRTCOptions);
|
||||||
|
console.log('RTC created');
|
||||||
connection.onicecandidate = function (e) {
|
connection.onicecandidate = function (e) {
|
||||||
if (e.candidate !== null) {
|
if (e.candidate !== null) {
|
||||||
var candidate = {
|
var candidate = {
|
||||||
@@ -816,6 +819,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var dc = connection.createDataChannel(key);
|
var dc = connection.createDataChannel(key);
|
||||||
|
console.log('data channel created');
|
||||||
|
console.log(dc);
|
||||||
dc.onopen = function () {
|
dc.onopen = function () {
|
||||||
resolve(dc);
|
resolve(dc);
|
||||||
};
|
};
|
||||||
@@ -827,6 +832,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||||||
};
|
};
|
||||||
socket.onmessage = function (e) {
|
socket.onmessage = function (e) {
|
||||||
var msg = JSON.parse(e.data);
|
var msg = JSON.parse(e.data);
|
||||||
|
console.log('message');
|
||||||
|
console.log(msg);
|
||||||
if (Reflect.has(msg, 'data')) {
|
if (Reflect.has(msg, 'data')) {
|
||||||
if (Reflect.has(msg.data, 'answer')) {
|
if (Reflect.has(msg.data, 'answer')) {
|
||||||
var sd = Object.assign(new _this2.RTCSessionDescription(), msg.data.answer);
|
var sd = Object.assign(new _this2.RTCSessionDescription(), msg.data.answer);
|
||||||
|
|||||||
@@ -113,61 +113,85 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
signaling: websocketUrl,
|
// signaling: websocketUrl,
|
||||||
// signaling: 'ws://localhost:9000',
|
signaling: 'ws://localhost:8000',
|
||||||
topology: 'StarTopologyService',
|
key: channel
|
||||||
protocol: 'WebSocketProtocolService',
|
// topology: 'StarTopologyService',
|
||||||
connector: 'WebSocketService',
|
// protocol: 'WebSocketProtocolService',
|
||||||
openWebChannel: true
|
// connector: 'WebSocketService',
|
||||||
|
// openWebChannel: true
|
||||||
};
|
};
|
||||||
|
console.log(options);
|
||||||
var realtime;
|
var realtime;
|
||||||
|
|
||||||
// Add the Facade's peer messages handler
|
// Add the Facade's peer messages handler
|
||||||
Netflux._onPeerMessage = onPeerMessage;
|
Netflux._onPeerMessage = onPeerMessage;
|
||||||
// Connect to the WebSocket server
|
|
||||||
Netflux.join(channel, options).then(function(wc) {
|
var webchannel = Netflux.create();
|
||||||
|
webchannel.openForJoining(options).then(function(data) {
|
||||||
wc.onMessage = onMessage; // On receiving message
|
console.log('keys');
|
||||||
wc.onJoining = onJoining; // On user joining the session
|
console.log(channel);
|
||||||
|
console.log(data);
|
||||||
// Open a Chainpad session
|
webchannel.onmessage = onMessage; // On receiving message
|
||||||
realtime = createRealtime();
|
webchannel.onJoining = onJoining; // On user joining the session
|
||||||
|
webchannel.onLeaving = onLeaving; // On user leaving the session
|
||||||
// we're fully synced
|
|
||||||
initializing = false;
|
// console.log('resolved');
|
||||||
|
|
||||||
// execute an onReady callback if one was supplied
|
onOpen();
|
||||||
if (config.onReady) {
|
|
||||||
config.onReady();
|
}, function(err) {
|
||||||
}
|
console.log('rejected');
|
||||||
|
console.error(err);
|
||||||
// On sending message
|
|
||||||
realtime.onMessage(function(message) {
|
|
||||||
// Do not send authentication messages since it is handled by Netflux
|
|
||||||
var parsed = parseMessage(message);
|
|
||||||
if (parsed.content[0] !== 0) {
|
|
||||||
message = Crypto.encrypt(message, cryptKey);
|
|
||||||
wc.send(message);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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]));
|
|
||||||
|
|
||||||
// Check the connection to the channel
|
|
||||||
//checkConnection(wc);
|
|
||||||
|
|
||||||
bindAllEvents(textarea, doc, onEvent, false);
|
|
||||||
|
|
||||||
sharejs.attach(textarea, realtime);
|
|
||||||
bump = realtime.bumpSharejs;
|
|
||||||
|
|
||||||
realtime.start();
|
|
||||||
}, function(error) {
|
|
||||||
warn(error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var onOpen = function() {
|
||||||
|
// Connect to the WebSocket server
|
||||||
|
Netflux.join(channel, options).then(function(wc) {
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
// we're fully synced
|
||||||
|
initializing = false;
|
||||||
|
|
||||||
|
// execute an onReady callback if one was supplied
|
||||||
|
if (config.onReady) {
|
||||||
|
config.onReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
// On sending message
|
||||||
|
realtime.onMessage(function(message) {
|
||||||
|
// Do not send authentication messages since it is handled by Netflux
|
||||||
|
var parsed = parseMessage(message);
|
||||||
|
if (parsed.content[0] !== 0) {
|
||||||
|
message = Crypto.encrypt(message, cryptKey);
|
||||||
|
wc.send(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 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]));
|
||||||
|
|
||||||
|
// Check the connection to the channel
|
||||||
|
//checkConnection(wc);
|
||||||
|
|
||||||
|
bindAllEvents(textarea, doc, onEvent, false);
|
||||||
|
|
||||||
|
sharejs.attach(textarea, realtime);
|
||||||
|
bump = realtime.bumpSharejs;
|
||||||
|
|
||||||
|
realtime.start();
|
||||||
|
}, function(error) {
|
||||||
|
warn(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var createRealtime = function() {
|
var createRealtime = function() {
|
||||||
return ChainPad.create(userName,
|
return ChainPad.create(userName,
|
||||||
@@ -215,11 +239,11 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
var onJoining = function(peer, channel) {
|
var onJoining = function(peer, channel) {
|
||||||
|
console.log('Someone joined : '+peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
var onLeaving = function(peer, channel) {
|
var onLeaving = function(peer, channel) {
|
||||||
|
console.log('Someone left : '+peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
var checkConnection = function(wc) {
|
var checkConnection = function(wc) {
|
||||||
|
|||||||
Reference in New Issue
Block a user