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


TypeScript connection.on方法代碼示例

本文整理匯總了TypeScript中websocket.connection.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript connection.on方法的具體用法?TypeScript connection.on怎麽用?TypeScript connection.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在websocket.connection的用法示例。


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

示例1: constructor

	constructor(connection: WebSocketConnection) {
		this.connection_ = connection;
		this.onMessage_ = new Subject<SocketMessage>();
		this.onClose_ = new Subject<void>();
		this.onError_ = new Subject<Error>();

		connection.on("message", (message: WebSocketMessage) => {
			if (message.type == "utf8") {
				this.onMessage_.onNext({ string: message.utf8Data });
			} else if (message.type == "binary") {
				this.onMessage_.onNext({ data: bufferToData(message.binaryData) });
			} else {
				throw new Error(`invalid message ${message.type}`);
			}
		});
		connection.on("close", (code: number, desc: string) => {
			this.onClose_.onNext(null);
		});
		connection.on("error", (error: Error) => {
			this.handleError(error);
		});
	}
開發者ID:omochi,項目名稱:national-economy,代碼行數:22,代碼來源:SocketImpl.ts

示例2: resolve

        let responsePromise: P<ServiceResponse> = new P<ServiceResponse>((resolve) => {

            var h = (msg) => {
                console.log("Receive message", msg.type);

                // Disconnect our listener
                this.conn.removeListener('message', h);

                if(msg.type === 'binary') {
                    console.log("Received binary message of len = ", msg.binaryData.length);
                    var response = this.protocolHandler.decode(msg.binaryData);
                    resolve(new BaseServiceResponse(response));
                }

            };

            this.conn.on('message', h);
        });
開發者ID:Covistra,項目名稱:cmbf2,代碼行數:18,代碼來源:response-handler.ts


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