diff --git a/ws/ws-tests.ts b/ws/ws-tests.ts index ec2bc431e0..a8afa8cb99 100644 --- a/ws/ws-tests.ts +++ b/ws/ws-tests.ts @@ -1,6 +1,8 @@ /// -import WebSocket = require('ws'); +import * as WebSocket from 'ws'; +import * as http from'http'; + var WebSocketServer = WebSocket.Server; { @@ -29,7 +31,7 @@ var WebSocketServer = WebSocket.Server; { var wss = new WebSocketServer({port: 8080}); - function broadcast(data: any) { + const broadcast = function(data: any) { for(var i in wss.clients) wss.clients[i].send(data); }; @@ -51,3 +53,24 @@ var WebSocketServer = WebSocket.Server; }, 500); }); } + +{ + const verifyClient = function( + info: { + origin: string + secure: boolean + req: http.ServerRequest + } + , callback: (res: boolean) => void + ): void { + callback(true) + } + + var wsv = new WebSocketServer({ + verifyClient + }) + + wsv.on('connection', function connection(ws) { + console.log(ws.protocol) + }) +} \ No newline at end of file diff --git a/ws/ws.d.ts b/ws/ws.d.ts index d9a1338d21..6b94bee19d 100644 --- a/ws/ws.d.ts +++ b/ws/ws.d.ts @@ -22,6 +22,7 @@ declare module "ws" { url: string; supports: any; upgradeReq: http.ServerRequest; + protocol: string; CONNECTING: number; OPEN: number; @@ -87,15 +88,16 @@ declare module "ws" { } namespace WebSocket { + + type VerifyClientCallbackSync = (info: {origin: string; secure: boolean; req: http.ServerRequest}) => boolean; + type VerifyClientCallbackAsync = (info: {origin: string; secure: boolean; req: http.ServerRequest} + , callback: (res: boolean) => void) => void; + export interface IServerOptions { host?: string; port?: number; server?: http.Server; - verifyClient?: { - (info: {origin: string; secure: boolean; req: http.ServerRequest}): boolean; - (info: {origin: string; secure: boolean; req: http.ServerRequest}, - callback: (res: boolean) => void): void; - }; + verifyClient?: VerifyClientCallbackAsync | VerifyClientCallbackSync; handleProtocols?: any; path?: string; noServer?: boolean;