mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #10259 from zixia/master
fix #10250 for verifyClient callback in ws definition file
This commit is contained in:
+25
-2
@@ -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
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user