本文整理汇总了TypeScript中faye-websocket.on函数的典型用法代码示例。如果您正苦于以下问题:TypeScript on函数的具体用法?TypeScript on怎么用?TypeScript on使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了on函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: startDebug
function startDebug(request: any, socket: any, body: any) {
let ws = new WebSocket(request, socket, body);
let dapjs: any
ws.on('open', () => {
ws.send(JSON.stringify({ id: "ready" }))
})
ws.on('message', function (event: any) {
try {
let msg = JSON.parse(event.data);
if (!dapjs) dapjs = require("dapjs")
console.log("DEBUGMSG", msg)
let toHandle = msg.arg
toHandle.op = msg.op
Promise.resolve()
.then(() => dapjs.handleMessageAsync(toHandle))
.then(resp => {
if (resp == null || typeof resp != "object")
resp = { response: resp }
console.log("DEBUGRESP", resp)
ws.send(JSON.stringify({
op: msg.op,
id: msg.id,
result: resp
}))
}, error => {
console.log("DEBUGERR", error.stack)
ws.send(JSON.stringify({
result: {
errorMessage: error.message || "Error",
errorStackTrace: error.stack,
},
op: msg.op,
id: msg.id
}))
})
} catch (e) {
console.log("ws debug error", e)
}
});
ws.on('close', function (event: any) {
console.log('ws debug connection closed')
ws = null;
});
ws.on('error', function () {
console.log('ws debug connection closed')
ws = null;
})
}
开发者ID:kleopatra999,项目名称:pxt,代码行数:50,代码来源:server.ts
示例2: startSerial
function startSerial(request: any, socket: any, body: any) {
let ws = new WebSocket(request, socket, body);
wsSerialClients.push(ws);
ws.on('message', function (event: any) {
// ignore
});
ws.on('close', function (event: any) {
console.log('ws connection closed')
wsSerialClients.splice(wsSerialClients.indexOf(ws), 1)
ws = null;
});
ws.on('error', function () {
console.log('ws connection closed')
wsSerialClients.splice(wsSerialClients.indexOf(ws), 1)
ws = null;
})
}
开发者ID:kleopatra999,项目名称:pxt,代码行数:17,代码来源:server.ts
注:本文中的faye-websocket.on函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论