本文整理汇总了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;未经允许,请勿转载。 |
请发表评论