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


TypeScript socket.action函数代码示例

本文整理汇总了TypeScript中@appolo/socket.action函数的典型用法代码示例。如果您正苦于以下问题:TypeScript action函数的具体用法?TypeScript action怎么用?TypeScript action使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _subscribe

    @action("subscribe")
    public async _subscribe(data:{room:string}) {

        this.roomsManager.addClientToRoom(data.room, this);

        // subscribe the client to the room
        this.socket.join(data.room);

        // update all other clients about the online
        this._updatePresence(data.room, 'online');

        // send to the client a list of all subscribed clients in this room
        let clients = [];
        _.forEach(this.roomsManager.getClientsInRoom(data.room),  (client)=> {
            if (client.id != this.id) {
                clients.push(client.clientData)
            }
        });

        this.socket.emit('roomclients', {room: data.room, clients: clients});

        let messages = await this.cacheProvider.getMessagesFromCache(data.room);

        messages.reverse();

        let output = _.map(messages,  (msgData)=> {

            return {client: msgData.clientData, message: msgData.message, room: data.room}
        });

        this.socket.emit('roomChatMessages', output);
    }
开发者ID:shmoop207,项目名称:appolo-chat-example,代码行数:32,代码来源:chatSocketController.ts

示例2: _disconnect

    @action("disconnect")
    private _disconnect() {

        _.forEach(this.roomsManager.getRoomsByClientId(this.id),  (roomName)=> {
            this._unSubscribe({room: roomName});
        });

    }
开发者ID:shmoop207,项目名称:appolo-chat-example,代码行数:8,代码来源:chatSocketController.ts

示例3: _chatMessage

    @action("chatmessage")
    private async _chatMessage(data:IMessage) {
        this.socket.broadcast.to(data.room).emit('chatmessage', {
            client: this._clientData,
            message: data.message,
            room: data.room
        });

        await this.cacheProvider.addMessageToCache(data.room, this._clientData, data.message);
    }
开发者ID:shmoop207,项目名称:appolo-chat-example,代码行数:10,代码来源:chatSocketController.ts

示例4: _onNickname

    @action("nickname")
    private _onNickname(data: { nickname: string }) {

        this._clientData.nickname = data.nickname;

        this.socket.emit('ready', {clientId: this.id});

        this._subscribe({room: 'lobby'});

        this.socket.emit('roomslist', {rooms: this.roomsManager.getRoomsList()});
    }
开发者ID:shmoop207,项目名称:appolo-chat-example,代码行数:11,代码来源:chatSocketController.ts

示例5: _unSubscribe

    @action("unsubscribe")
    public _unSubscribe(data:{room:string}) {
        // update all other clients about the offline
        // presence
        this._updatePresence(data.room, 'offline');

        // remove the client from socket.io room
        this.socket.leave(data.room);

        this.roomsManager.removeClientFromRoom(data.room, this);

    }
开发者ID:shmoop207,项目名称:appolo-chat-example,代码行数:12,代码来源:chatSocketController.ts


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