当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript comm_socket.on方法代码示例

本文整理汇总了TypeScript中sockets.comm_socket.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript comm_socket.on方法的具体用法?TypeScript comm_socket.on怎么用?TypeScript comm_socket.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sockets.comm_socket的用法示例。


在下文中一共展示了comm_socket.on方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: EventEmitter

 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import {comm_socket} from "sockets";
import {EventEmitter} from "eventemitter3";

let listeners: {[id: number]: Array<any>} = {};
let state = {};
let event_emitter = new EventEmitter();

comm_socket.on("connect", () => {
    let list = [];
    for (let id in state) {
        list.push(id);
    }
    if (list.length) {
        comm_socket.send("user/monitor", list);
    }
});

comm_socket.on("user/state", (states) => {
    let i;
    for (let id in states) {
        state[id] = states[id];
        for (i = 0; i < listeners[id].length; ++i) {
            listeners[id][i](id, state[id]);
        }
    }
    event_emitter.emit("users-online-updated");
});
开发者ID:PowerOlive,项目名称:online-go.com,代码行数:31,代码来源:online_status.ts

示例2:

 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* Inter tab communications library */
import {comm_socket} from "sockets";

let registrations = {};

comm_socket.on("itc", (obj) => {
    if (obj.event in registrations) {
        for (let i = 0; i < registrations[obj.event].length; ++i) {
            registrations[obj.event][i](obj.data);
        }
    }
});

export default {
    register: (event, cb) => {
        if (!(event in registrations)) {
            registrations[event] = [];
        }
        registrations[event].push(cb);
    },
    send: (event, data) => {
        comm_socket.send("itc", {"event": event, "data": data});
    }
};
开发者ID:PowerOlive,项目名称:online-go.com,代码行数:31,代码来源:ITC.ts


注:本文中的sockets.comm_socket.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。