本文整理汇总了TypeScript中ws.terminate函数的典型用法代码示例。如果您正苦于以下问题:TypeScript terminate函数的具体用法?TypeScript terminate怎么用?TypeScript terminate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了terminate函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: onWsConnection
/**
* Called whenever a new client connection is made to the WS server
*/
async onWsConnection( ws: ws ): Promise<void> {
let headers = ws.upgradeReq.headers;
if ( this._cfg.debug )
info( `Websocket client connected: ${headers.origin}` )
let clientApproved = false;
for ( let domain of this._cfg.websocket.approvedSocketDomains ) {
// Check if the connecting client is an authorized third party (more privileges)
let authorizedThirdParty = false;
if ( headers[ 'users-api-key' ] && this._hashedApiKey ) {
info( 'Checking socket API key' );
authorizedThirdParty = await this.checkApiKey( headers[ 'users-api-key' ] );
}
if ( authorizedThirdParty || ( headers.origin && headers.origin.match( new RegExp( domain ) ) ) ) {
let clientConnection = new ClientConnection( ws, headers.origin || 'AUTHORIZED-ACCESS', this, authorizedThirdParty );
// Remove the client when its disconnected
clientConnection.onDisconnected = ( connection: ClientConnection ) => {
this._connections.splice( this._connections.indexOf( connection ), 1 );
}
this._connections.push( clientConnection );
clientApproved = true;
break;
}
}
// The client was not approved - so kill the connection
if ( !clientApproved ) {
logError( `A connection was made by ${headers.origin} but it is not on the approved domain list. Make sure the host is on the approvedSocketDomains parameter in the config file.` );
ws.terminate();
ws.close();
}
}
开发者ID:Webinate,项目名称:modepress,代码行数:39,代码来源:comms-controller.ts
示例2: connectClient
function connectClient(
socket: ws, server: InternalServer, originalRequest: OriginalRequest, errorHandler: ErrorHandler, log: Logger
) {
const query = getQuery(originalRequest.url);
const t = query.t || '';
const token = server.connectionTokens ? getToken(server, t) || getTokenFromClient(server, t) : undefined;
if (server.connectionTokens && !token) {
errorHandler.handleError({ originalRequest } as any, new Error(`Invalid token: ${t}`));
socket.terminate();
return;
}
const rates = server.serverMethods.map(createRateLimit);
const { executeForClients, handleResult } = server;
let bytesReset = Date.now();
let bytesReceived = 0;
let transferLimitExceeded = false;
let isConnected = true;
let serverActions: SocketServer | undefined = undefined;
const obj: ClientState = {
lastMessageTime: Date.now(),
lastMessageId: 0,
supportsBinary: !!server.forceBinary || !!(query && query.bin === 'true'),
token,
ping() {
socket.send('');
},
client: {
__internalHooks: {
executeForClients,
sendPacket,
},
id: server.currentClientId++,
tokenId: token ? token.id : undefined,
tokenData: token ? token.data : undefined,
originalRequest: server.keepOriginalRequest ? originalRequest : undefined,
get isConnected() {
return isConnected;
},
disconnect(force = false, invalidateToken = false) {
if (invalidateToken) {
obj.token = undefined;
}
if (force) {
socket.terminate();
} else {
socket.close();
}
},
},
};
function send(data: string | ArrayBuffer) {
if (typeof data !== 'string') {
socket.send(new Buffer(data));
} else {
socket.send(data);
}
}
function sendPacket(packet: Packet) {
server.packetHandler.sendPacket(send, packet, obj.supportsBinary);
}
function handleConnected(serverActions: SocketServer) {
if (serverActions.connected) {
callWithErrorHandling(() => serverActions.connected!(), () => { }, e => {
errorHandler.handleError(obj.client, e);
obj.client.disconnect();
});
}
}
function handleDisconnected(serverActions: SocketServer) {
if (serverActions.disconnected) {
callWithErrorHandling(() => serverActions.disconnected!(), () => { }, e => errorHandler.handleError(obj.client, e));
}
}
function serverActionsCreated(serverActions: SocketServer) {
socket.on('message', (message: string | Buffer | ArrayBuffer, flags?: { binary: boolean; }) => {
try {
if (transferLimitExceeded || !isConnected)
return;
const messageLength = getLength(message);
bytesReceived += messageLength;
let data: string | Uint8Array;
if (message instanceof Buffer) {
data = new Uint8Array(message.buffer, message.byteOffset, message.byteLength);
} else if (message instanceof ArrayBuffer) {
data = new Uint8Array(message);
} else {
data = message;
//.........这里部分代码省略.........
开发者ID:Agamnentzar,项目名称:ag-sockets,代码行数:101,代码来源:serverSocket.ts
示例3:
.catch(e => {
socket.terminate();
errorHandler.handleError(obj.client, e);
});
开发者ID:Agamnentzar,项目名称:ag-sockets,代码行数:4,代码来源:serverSocket.ts
示例4: destroy
destroy() {
this.websocket.terminate()
}
开发者ID:hedefalk,项目名称:ensime-node,代码行数:3,代码来源:NetworkClient.ts
注:本文中的ws.terminate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论