UNPKG

nxkit

Version:

This is a collection of tools, independent of any other libraries

119 lines (118 loc) 4.39 kB
"use strict"; /* ***** BEGIN LICENSE BLOCK ***** * Distributed under the BSD license: * * Copyright (c) 2015, xuewen.chu * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of xuewen.chu nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL xuewen.chu BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * ***** END LICENSE BLOCK ***** */ Object.defineProperty(exports, "__esModule", { value: true }); const _center = require("./_center"); const event_1 = require("../event"); // Fast Message Transfer Center, 快速消息传输中心 /** * @class FastMessageTransferCenterDelegate */ class FastMessageTransferCenterDelegate { constructor(host) { this.m_host = host; host.m_delegate = this; // TODO private visit this.m_impl = host.m_impl; // TODO private visit } get host() { return this.m_host; } exec(id, args = [], method) { return this.m_impl.exec(id, args, method); } /** * @func auth() auth client, return client user info */ auth(fmtService) { return { /* user info */}; } /** * @func authFnode() auth fnode */ authFnode(fnodeRemoteService) { return !!fnodeRemoteService.headers.certificate; } /** * @func getCertificate() get current center certificate */ getCertificate() { return 'Certificate'; } triggerTo(id, event, data, sender) { return this.exec(id, [event, data, sender], 'triggerTo'); } callTo(id, method, data, timeout, sender) { return this.exec(id, [method, data, timeout, sender], 'callTo'); } sendTo(id, method, data, sender) { return this.exec(id, [method, data, sender], 'sendTo'); } } exports.FastMessageTransferCenterDelegate = FastMessageTransferCenterDelegate; /** * @class FastMessageTransferCenter */ class FastMessageTransferCenter extends event_1.Notification { constructor(server, fnodes = [ /* 'fnode://127.0.0.1:9081/' */], publish) { super(); this.onAddNode = new event_1.EventNoticer('AddNode', this); this.onDeleteNode = new event_1.EventNoticer('DeleteNode', this); this.onLogin = new event_1.EventNoticer('Login', this); this.onLogout = new event_1.EventNoticer('Logout', this); this.m_impl = new _center.FastMessageTransferCenter_IMPL(this, server, fnodes, publish); this.m_delegate = new FastMessageTransferCenterDelegate(this); } get id() { return this.m_impl.id; } get publishURL() { return this.m_impl.publishURL; } get routeTable() { return this.m_impl.routeTable; } client(id) { return this.m_impl.client(id); } hasOnline(id) { return this.m_impl.hasOnline(id); } user(id) { return this.m_impl.user(id); } trigger(event, data) { this.publish(event, data); return 0; } publish(event, data) { return this.m_impl.publish(event, data); } } exports.FastMessageTransferCenter = FastMessageTransferCenter;