Merge pull request #10259 from zixia/master

fix #10250 for verifyClient callback in ws definition file
This commit is contained in:
Yui
2016-07-25 20:54:41 -07:00
committed by GitHub
2 changed files with 32 additions and 7 deletions
+25 -2
View File
@@ -1,6 +1,8 @@
/// <reference path="ws.d.ts" />
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)
})
}
Vendored
+7 -5
View File
@@ -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;