|
|
@ -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) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wc.onMessage = onMessage; // On receiving message
|
|
|
|
var webchannel = Netflux.create();
|
|
|
|
wc.onJoining = onJoining; // On user joining the session
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
// Open a Chainpad session
|
|
|
|
// console.log('resolved');
|
|
|
|
realtime = createRealtime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// we're fully synced
|
|
|
|
onOpen();
|
|
|
|
initializing = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// execute an onReady callback if one was supplied
|
|
|
|
}, function(err) {
|
|
|
|
if (config.onReady) {
|
|
|
|
console.log('rejected');
|
|
|
|
config.onReady();
|
|
|
|
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.onJoining = onJoining; // On user joining the session
|
|
|
|
|
|
|
|
wc.onLeaving = onLeaving; // On user leaving the session
|
|
|
|
|
|
|
|
|
|
|
|
// On sending message
|
|
|
|
// Open a Chainpad session
|
|
|
|
realtime.onMessage(function(message) {
|
|
|
|
realtime = createRealtime();
|
|
|
|
// Do not send authentication messages since it is handled by Netflux
|
|
|
|
|
|
|
|
var parsed = parseMessage(message);
|
|
|
|
// we're fully synced
|
|
|
|
if (parsed.content[0] !== 0) {
|
|
|
|
initializing = false;
|
|
|
|
message = Crypto.encrypt(message, cryptKey);
|
|
|
|
|
|
|
|
wc.send(message);
|
|
|
|
// execute an onReady callback if one was supplied
|
|
|
|
|
|
|
|
if (config.onReady) {
|
|
|
|
|
|
|
|
config.onReady();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the channel history
|
|
|
|
// On sending message
|
|
|
|
var hc;
|
|
|
|
realtime.onMessage(function(message) {
|
|
|
|
wc.peers.forEach(function (p) { if (!hc || p.linkQuality > hc.linkQuality) { hc = p; } });
|
|
|
|
// Do not send authentication messages since it is handled by Netflux
|
|
|
|
hc.send(JSON.stringify(['GET_HISTORY', wc.id]));
|
|
|
|
var parsed = parseMessage(message);
|
|
|
|
|
|
|
|
if (parsed.content[0] !== 0) {
|
|
|
|
|
|
|
|
message = Crypto.encrypt(message, cryptKey);
|
|
|
|
|
|
|
|
wc.send(message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Check the connection to the channel
|
|
|
|
// Get the channel history
|
|
|
|
//checkConnection(wc);
|
|
|
|
// var hc;
|
|
|
|
|
|
|
|
// wc.peers.forEach(function (p) { if (!hc || p.linkQuality > hc.linkQuality) { hc = p; } });
|
|
|
|
|
|
|
|
// hc.send(JSON.stringify(['GET_HISTORY', wc.id]));
|
|
|
|
|
|
|
|
|
|
|
|
bindAllEvents(textarea, doc, onEvent, false);
|
|
|
|
// Check the connection to the channel
|
|
|
|
|
|
|
|
//checkConnection(wc);
|
|
|
|
|
|
|
|
|
|
|
|
sharejs.attach(textarea, realtime);
|
|
|
|
bindAllEvents(textarea, doc, onEvent, false);
|
|
|
|
bump = realtime.bumpSharejs;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realtime.start();
|
|
|
|
sharejs.attach(textarea, realtime);
|
|
|
|
}, function(error) {
|
|
|
|
bump = realtime.bumpSharejs;
|
|
|
|
warn(error);
|
|
|
|
|
|
|
|
});
|
|
|
|
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) {
|
|
|
|