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


TypeScript websocket.client類代碼示例

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


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

示例1: if

	let promise = new Promise<void>((resolve, reject) => {
		
		var wsClient = new WebSocket.client();

		wsClient.on('connect', function(connection) {
			
			connection.on('error', function(error) {
				console.log("Connection Error: " + error.toString());
				reject(error);
			});
			
			connection.on('close', function() {
				console.log('echo-protocol Connection Closed');
			});
			
			connection.on('message', function(message) {
				if (message.type === 'utf8') {
					
					let json = JSON.parse(message.utf8Data);
					
					if(json.type === "snapshot:init") {
						let data : INSocket.IStatusInit = json;
						nobilApp.parseDataFromInitialStatusNobilWebSocket(data).then(() => {
							console.log("Initial data parsed!");
							resolve(null);
						});
					}
					
					else if(json.type === "status:update") {
						let data : INSocket.IStatusUpdate = json;
						nobilApp.updateChargingStationWithLiveUpdate(data);
					}
					
					else if(json.type === "status:raw") {
						// Do nothing for now
						// let data: INSocket.IStatusRaw = json;
					}
					
					
				}
			});
		});
		
		wsClient.connect('ws://realtime.nobil.no/api/v1/stream?apikey=' + Secrets.apiKey);
	});
開發者ID:Dzeneralen,項目名稱:sockets,代碼行數:45,代碼來源:server.ts

示例2: Promise

const connector = (endpoint: string): Promise<WebSocket.connection> => new Promise((resolve, reject) => {
	const client = new WebSocket.client();
	client.on('connectFailed', (error) => reject(error));
	client.on('connect', (connection) => resolve(connection));
	client.connect(endpoint);
});
開發者ID:sagume,項目名稱:Misskey-Web,代碼行數:6,代碼來源:index.ts

示例3: require

    });

    wsRouter.mount(/^route\/[a-zA-Z]+$/, (request) => {

    });

    wsRouter.unmount('*');
    wsRouter.unmount('*', 'protocol');

    wsRouter.unmount(/^route\/[a-zA-Z]+$/);
    wsRouter.unmount(/^route\/[a-zA-Z]+$/, 'protocol');
}

{
    var WebSocketClient = require('websocket').client;
    var client = new WebSocketClient();

    client.on('connectFailed', (error: Error) => {
        console.log('Connect Error: ' + error.toString());
    });

    client.on('connect', (connection: websocket.connection) => {
        console.log('WebSocket client connected');
        connection.on('error', (error: Error) => {
            console.log("Connection Error: " + error.toString());
        });

        connection.on('close', () => {
            console.log('echo-protocol Connection Closed');
        });
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:websocket-tests.ts

示例4: connect

function connect(address: string, retry: boolean) {
    if (retry) {
        info('retrying...')
    }

    const ws = new WebSocketClient()

    ws.on('connectFailed', function (err) {
        error('Could not connect to server ' + Config.server + ': ' + err.stack)
        info('retrying in one minute')

        setTimeout(function () {
            connect(address, true)
        }, 60000)
    })

    ws.on('connect', function (con) {
        Connection = con
        ok('connected to server ' + Config.server)

        con.on('error', function (err) {
            error('connection error: ' + err.stack)
        })

        con.on('close', function (code, reason) {
            // Is this always error or can this be intended...?
            error('connection closed: ' + reason + ' (' + code + ')')
            info('retrying in one minute')

            for (const i in users) {
                delete users[i]
            }
            rooms.clear()
            setTimeout(function () {
                connect(address, true)
            }, 60000)
        })

        con.on('message', function (response) {
            if (response.type !== 'utf8') return false
            const message = response.utf8Data
            recv(message)
            parseData(message)
        })
    })

    info('connecting to ' + address + ' - secondary protocols: ' + (Config.secprotocols.join(', ') || 'none'))
    ws.connect(address, Config.secprotocols)
}
開發者ID:KewlStatics,項目名稱:SocialMedia-bot,代碼行數:49,代碼來源:main.ts

示例5: initialize

    initialize() {
        let retries : number = 0;
        let max_retries : number = process.env.NODE_ENV === 'production' ? 5 : 1;

        this.logger = SystemLogger.get();

        // Create the web socket
        this.socket = new Client();

        this.socket.on('connectFailed', (error: Error) => {
            console.log("Platform is not available yet. Retrying in 2 seconds");
            retries++;

            if(retries <= max_retries) {
                setTimeout(() => {
                    // Establish connection to the platform
                    this.socket.connect('ws://'+this.host+":"+this.port, "v1");

                }, 2000);
            }
            else {
                this.connRejecter(error);
            }
        });

        this.socket.on('connect', (conn: any) => {
            console.log("Connected to stream");
            conn.on('error', this.handleConnectionError.bind(this));

            conn.on('close', function() {
                console.log('v1 Connection Closed');
            });

            this.connResolver(conn);
        });

        // Establish connection to the platform
        this.socket.connect('ws://'+this.host+":"+this.port, "v1");
    }
開發者ID:Covistra,項目名稱:cmbf2,代碼行數:39,代碼來源:stream-platform-client.ts

示例6: setTimeout

                setTimeout(() => {
                    // Establish connection to the platform
                    this.socket.connect('ws://'+this.host+":"+this.port, "v1");

                }, 2000);
開發者ID:Covistra,項目名稱:cmbf2,代碼行數:5,代碼來源:stream-platform-client.ts


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