mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 04:49:15 +08:00
add protocol, fix verifyClient callback defination
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
/// <reference path="ws.d.ts" />
|
||||
|
||||
import WebSocket = require('ws');
|
||||
import http = require('http');
|
||||
// import * as http from 'http'
|
||||
|
||||
var WebSocketServer = WebSocket.Server;
|
||||
|
||||
{
|
||||
@@ -29,7 +32,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 +54,25 @@ 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)
|
||||
})
|
||||
}
|
||||
12
ws/ws.d.ts
vendored
12
ws/ws.d.ts
vendored
@@ -22,6 +22,7 @@ declare module "ws" {
|
||||
url: string;
|
||||
supports: any;
|
||||
upgradeReq: http.ServerRequest;
|
||||
protocol: string;
|
||||
|
||||
CONNECTING: number;
|
||||
OPEN: number;
|
||||
@@ -91,11 +92,12 @@ declare module "ws" {
|
||||
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?: (
|
||||
((info: {origin: string; secure: boolean; req: http.ServerRequest}) => boolean)
|
||||
|
|
||||
((info: {origin: string; secure: boolean; req: http.ServerRequest},
|
||||
callback: (res: boolean) => void) => void)
|
||||
);
|
||||
handleProtocols?: any;
|
||||
path?: string;
|
||||
noServer?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user