當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。