control-freak-ide/server/nodejs/_build/wamp/router.js
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

66 lines
2.8 KiB
JavaScript

"use strict";
const handlers_1 = require("./handlers");
const protocols_1 = require("./protocols");
const Debug = require("debug");
const DEBUG = Debug('wamp:router');
/**
*
*
* @export
* @class Router
*/
class Router {
/**
*
*
* @static
* @param {SessionInterface} session
* @param {SocketMessageInterface} message
* @returns {string}
*/
static dispatch(session, message) {
DEBUG('switching: %s, %s', message.type, protocols_1.incomingChannel[message.type]);
if (!session.getRealm() && message.type !== protocols_1.outgoingChannel.HELLO) {
handlers_1.default.abort(session);
return protocols_1.incomingChannel[3];
}
switch (message.type) {
case protocols_1.outgoingChannel.CALL:
handlers_1.default.call(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.ERROR:
handlers_1.default.error(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.GOODBYE:
handlers_1.default.goodbye(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.HELLO:
handlers_1.default.hello(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.PUBLISH:
handlers_1.default.publish(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.REGISTER:
handlers_1.default.register(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.SUBSCRIBE:
handlers_1.default.subscribe(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.UNREGISTER:
handlers_1.default.unregister(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.UNSUBSCRIBE:
handlers_1.default.unsubscribe(session, message);
return protocols_1.incomingChannel[message.type];
case protocols_1.outgoingChannel.YIELD:
handlers_1.default.yield(session, message);
return protocols_1.incomingChannel[message.type];
default:
handlers_1.default.goodbye(session, message);
return protocols_1.incomingChannel[6];
}
}
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Router;
//# sourceMappingURL=router.js.map