本文整理汇总了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;
})
}
示例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;
})
}