support reusing the netflux network
export more internals from realtime input
This commit is contained in:
parent
ba3e120fbf
commit
dbf1e2b870
@ -59,6 +59,7 @@ define([
|
|||||||
var messagesHistory = [];
|
var messagesHistory = [];
|
||||||
var chainpadAdapter = {};
|
var chainpadAdapter = {};
|
||||||
var realtime;
|
var realtime;
|
||||||
|
var network;
|
||||||
|
|
||||||
var parseMessage = function (msg) {
|
var parseMessage = function (msg) {
|
||||||
return unBencode(msg);//.slice(msg.indexOf(':[') + 1);
|
return unBencode(msg);//.slice(msg.indexOf(':[') + 1);
|
||||||
@ -188,7 +189,7 @@ define([
|
|||||||
wc.on('leave', onLeaving);
|
wc.on('leave', onLeaving);
|
||||||
|
|
||||||
// Open a Chainpad session
|
// Open a Chainpad session
|
||||||
realtime = createRealtime();
|
toReturn.realtime = realtime = createRealtime();
|
||||||
|
|
||||||
if(config.onInit) {
|
if(config.onInit) {
|
||||||
config.onInit({
|
config.onInit({
|
||||||
@ -255,10 +256,29 @@ define([
|
|||||||
return webChannel;
|
return webChannel;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connect to the WebSocket channel
|
var joinSession = function (endPoint, cb) {
|
||||||
Netflux.connect(websocketUrl).then(function(network) {
|
// a websocket URL has been provided
|
||||||
|
// connect to it with Netflux.
|
||||||
|
if (typeof(endPoint) === 'string') {
|
||||||
|
Netflux.connect(endPoint).then(cb);
|
||||||
|
} else if (typeof(endPoint.then) ==- 'function') {
|
||||||
|
// a netflux network promise was provided
|
||||||
|
// connect to it and use a channel
|
||||||
|
endPoint.then(cb);
|
||||||
|
} else {
|
||||||
|
// assume it's a network and try to connect.
|
||||||
|
cb(network);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Connect to the Netflux network, or fall back to a WebSocket
|
||||||
|
in theory this lets us connect to more netflux channels using only
|
||||||
|
one network. */
|
||||||
|
joinSession(network || websocketUrl, function (network) {
|
||||||
// pass messages that come out of netflux into our local handler
|
// pass messages that come out of netflux into our local handler
|
||||||
|
|
||||||
|
toReturn.network = network;
|
||||||
|
|
||||||
network.on('disconnect', function (reason) {
|
network.on('disconnect', function (reason) {
|
||||||
if (config.onAbort) {
|
if (config.onAbort) {
|
||||||
config.onAbort({
|
config.onAbort({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user