當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript sockets.comm_socket類代碼示例

本文整理匯總了TypeScript中sockets.comm_socket的典型用法代碼示例。如果您正苦於以下問題:TypeScript comm_socket類的具體用法?TypeScript comm_socket怎麽用?TypeScript comm_socket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了comm_socket類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

comm_socket.on("connect", () => {
    let list = [];
    for (let id in state) {
        list.push(id);
    }
    if (list.length) {
        comm_socket.send("user/monitor", list);
    }
});
開發者ID:PowerOlive,項目名稱:online-go.com,代碼行數:9,代碼來源:online_status.ts

示例2: setTimeout

 setTimeout(() => {
     comm_socket.send("user/monitor", subscribe_queue);
     subscribe_queue = null;
 }, 1);
開發者ID:PowerOlive,項目名稱:online-go.com,代碼行數:4,代碼來源:online_status.ts

示例3:

 send: (event, data) => {
     comm_socket.send("itc", {"event": event, "data": data});
 }
開發者ID:PowerOlive,項目名稱:online-go.com,代碼行數:3,代碼來源:ITC.ts

示例4: 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


注:本文中的sockets.comm_socket類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。