latest api changes to match the netflux-server refactor

pull/1/head
ansuz 5 years ago
parent b922860339
commit 06c29ef1d1

@ -1,7 +1,7 @@
/* jshint esversion: 6 */
const nThen = require("nthen");
const WebSocketServer = require('ws').Server;
const NetfluxSrv = require('chainpad-server/NetfluxWebsocketSrv');
const NetfluxSrv = require('chainpad-server');
module.exports.create = function (config) {
var rpc;
@ -48,10 +48,19 @@ module.exports.create = function (config) {
store: config.store,
log: log,
};
// XXX historyKeeper exports a `setConfig` method
var wsSrv = new WebSocketServer(wsConfig);
var historyKeeper = HK.create(hkConfig);
NetfluxSrv.run(wsSrv, config, historyKeeper);
NetfluxSrv.create(new WebSocketServer(wsConfig))
.on('channelClose', historyKeeper.channelClose)
.on('channelMessage', historyKeeper.channelMessage)
.on('channelOpen', historyKeeper.channelOpen)
.on('sessionClose', function (userId, reason) {
reason = reason; // XXX
})
.on('error', function (error, label, info) {
info = info; // XXX
})
.register(historyKeeper.id, historyKeeper.directMessage);
});
};

@ -976,25 +976,24 @@ module.exports.create = function (cfg) {
command(ctx, seq, user, parsed);
};
// XXX every one of these values is exported because
// netfluxWebsocketServer needs them to do some magic historyKeeper things
// we could have netflux emit events and let historyKeeper handle them instead
return {
id: HISTORY_KEEPER_ID,
// XXX dropChannel allows netflux to clear historyKeeper's cache
// maybe it should emit a 'channel_dropped' event instead
// and let historyKeeper decide what to do
dropChannel: dropChannel,
// XXX we don't need to export checkExpired if netflux allows it to be HK's responsibility
checkExpired: checkExpired,
// XXX again, if netflux emitted events then historyKeeper could handle them itself
// and netflux wouldn't need to have historyKeeper-specific code
onDirectMessage: onDirectMessage,
// XXX same
onChannelMessage: onChannelMessage,
channelMessage: function (ctx, channel, msgStruct) {
onChannelMessage(ctx, channel, msgStruct);
},
channelClose: function (channelName) {
dropChannel(channelName);
},
channelOpen: function (ctx, channelName, user) {
ctx.sendMsg(ctx, user, [
0,
HISTORY_KEEPER_ID, // ctx.historyKeeper.id
'JOIN',
channelName
]);
},
directMessage: function (ctx, seq, user, json) {
onDirectMessage(ctx, seq, user, json);
},
};
};

Loading…
Cancel
Save