File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " tgrid" ,
3- "version" : " 1.0.2 " ,
3+ "version" : " 1.0.3 " ,
44 "main" : " lib/index.js" ,
55 "typings" : " lib/index.d.ts" ,
66 "exports" : {
Original file line number Diff line number Diff line change 11import type http from "http" ;
2+ import { sleep_for } from "tstl" ;
23import type WebSocket from "ws" ;
34
45import { Invoke } from "../../components/Invoke" ;
@@ -240,6 +241,33 @@ export class WebSocketAcceptor<
240241 /* ----------------------------------------------------------------
241242 COMMUNICATOR
242243 ---------------------------------------------------------------- */
244+ /**
245+ * Ping to the remote client.
246+ *
247+ * Send a ping message to the remote client repeatedly.
248+ *
249+ * The ping message would be sent every internal milliseconds, until the
250+ * connection be disconnectedd. The remote client will reply with a pong
251+ * message, so that the connection would be alive until be explicitly
252+ * disconnected.
253+ *
254+ * @param ms Interval milliseconds
255+ * @throws Error when the connection is not accepted.
256+ */
257+ public ping ( ms : number ) : void {
258+ // TEST CONDITION
259+ const error : Error | null = this . inspectReady ( "close" ) ;
260+ if ( error ) throw error ;
261+ ( async ( ) : Promise < void > => {
262+ while ( this . state_ === WebSocketAcceptor . State . OPEN ) {
263+ await sleep_for ( ms ) ;
264+ try {
265+ this . socket_ . ping ( ) ;
266+ } catch { }
267+ }
268+ } ) ( ) . catch ( ( ) => { } ) ;
269+ }
270+
243271 /**
244272 * @hidden
245273 */
You can’t perform that action at this time.
0 commit comments