本文整理汇总了TypeScript中ws.close函数的典型用法代码示例。如果您正苦于以下问题:TypeScript close函数的具体用法?TypeScript close怎么用?TypeScript close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了close函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: if
dummyRes.writeHead = (statusCode: number, _statusMessage: never, headers: never) => {
if (statusCode && statusCode > 200) {
// tslint:disable-next-line no-console
console.error(
`Something used 'writeHead' to write a '${statusCode}' error for websockets - check the middleware you're passing!`,
);
socket.close();
} else if (headers) {
// tslint:disable-next-line no-console
console.error(
"Passing headers to 'writeHead' is not supported with websockets currently - check the middleware you're passing",
);
socket.close();
}
};
示例2:
ws1.on('open', () => {
ws1.send(JSON.stringify({
"ev": "CREATE_MESSAGE",
"value": "sample message"
}))
ws1.close()
})
示例3: reject
ws.on("message", (response) => {
const responseParsed = JSON.parse(response.toString());
if (responseParsed.id !== jsonId) {
return reject("Bad ID");
}
resolve(responseParsed.result);
ws.close();
});
示例4: setTimeout
setTimeout(() => {
if(ping_available === false) {
console.error("ping is not available")
ws.close()
clearInterval(ping_interval)
return
}
} ,4000)
示例5: reject
function reject(mes: string): void {
sendEvent({
type: 'error',
value: {
message: mes
}
});
ws.close();
}
示例6:
const reject = (mes: string = 'authentication failed') => {
const res = {
type: 'error',
value: {
message: mes
}
};
ws.send(JSON.stringify(res));
ws.close();
};
示例7: onNvimNotify
function onNvimNotify(method: string) {
switch (method) {
case WS_STOP_COMMAND: {
ws.close();
}
case DUMP_COMMAND: {
scripts.dump();
}
}
}
示例8: logHandleFunc
ws.on('message', (data) => {
// Handle received message which contains log data in stringified JSON.
if (argv.debug) {
console.error(`Received message: ${data}`);
}
try {
logHandleFunc(parseLogStream(data as string));
} catch (e) {
ws.close();
reject(e);
}
});