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


TypeScript ws.close函數代碼示例

本文整理匯總了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();
   }
 };
開發者ID:calebmer,項目名稱:postgraphql,代碼行數:15,代碼來源:subscriptions.ts

示例2:

 ws1.on('open', () => {
   ws1.send(JSON.stringify({
     "ev": "CREATE_MESSAGE",
     "value": "sample message"
   }))
   ws1.close()
 })
開發者ID:HaiTo,項目名稱:respass,代碼行數:7,代碼來源:test_wsserver.ts

示例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();
 });
開發者ID:AugurProject,項目名稱:augur_node,代碼行數:8,代碼來源:utils.ts

示例4: setTimeout

 setTimeout(() => {
   if(ping_available === false) {
     console.error("ping is not available")
     ws.close()
     clearInterval(ping_interval)
     return
   }
 } ,4000)
開發者ID:sketchglass,項目名稱:respass,代碼行數:8,代碼來源:wsserver.ts

示例5: reject

	function reject(mes: string): void {
		sendEvent({
			type: 'error',
			value: {
				message: mes
			}
		});
		ws.close();
	}
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:9,代碼來源:group-talk.ts

示例6:

	const reject = (mes: string = 'authentication failed') => {
		const res = {
			type: 'error',
			value: {
				message: mes
			}
		};
		ws.send(JSON.stringify(res));
		ws.close();
	};
開發者ID:Tosuke,項目名稱:Misskey-API,代碼行數:10,代碼來源:stream-handler.ts

示例7: onNvimNotify

function onNvimNotify(method: string) {
  switch (method) {
    case WS_STOP_COMMAND: {
      ws.close();
    }
    case DUMP_COMMAND: {
      scripts.dump();
    }
  }
}
開發者ID:duskpoet,項目名稱:chrome-debugger-vim,代碼行數:10,代碼來源:inspect-site.ts

示例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);
   }
 });
開發者ID:SkygearIO,項目名稱:skycli,代碼行數:12,代碼來源:logs.ts


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