for WebSocket communications, server implementation based on ws
server
import { MuWebSocketServer } from 'mudb/socket/web/server'
import { MuServer } from 'mudb/server'
import http = require('http')
const httpServer = http.createServer()
const socketServer = new MuWebSocketServer({
server: httpServer,
})
const server = new MuServer(socketServer)client
import { MuWebSocket } from 'mudb/socket/web/client'
import { MuClient } from 'mudb/client'
const socket = new MuWebSocket({
sessionId: Math.random().toString(36).substring(2),
url: 'ws://127.0.0.1:9966',
})
const client = new MuClient(socket)implements MuSocketServer
import { MuWebSocketServer } from 'mudb/socket/web/server'
new MuWebSocketServer(spec:{
server:http.Server|https.Server,
bufferLimit:number=1024,
pingInterval:number=0,
backlog?:number,
maxPayload?:number,
path?:string,
handleProtocols?:(protocols:any[], request:http.IncomingMessage) => any,
perMessageDeflate:boolean|object=false,
scheduler?:MuScheduler,
logger?:MuLogger;
})serveran HTTP/S serverbufferLimitthe hard limit on the byte size of buffered data per connection, exceeding which will cause unreliable messages to be droppedpingIntervalif >0, server will send a ping frame to an idle connection everypingIntervalmsbacklogthe hard limit on the number of pending connectionsmaxPayloadthe maximum byte size of each messagepathif specified, only connections matchingpathwill be acceptedhandleProtocols(protocols, request)a function used to handle the WebSocket subprotocolsprotocolsa list of subprotocols indicated by the client in theSec-WebSocket-Protocolheaderrequestan HTTP GET request
perMessageDeflatecontrolling the behavior of permessage-deflate extension, disabled by default, can be a table of extension parameters:serverNoContextTakeover:booleanwhether to include theserver_no_context_takeoverparameter in the corresponding negotiation responseclientNoContextTakeover:booleanwhether to include theclient_no_context_takeoverparameter in the corresponding negotiation responseserverMaxWindowBits:numberthe value ofwindowBitsclientMaxWindowBits:numberrequest a custom client window sizethreshold:number=1024payloads smaller than this will not be compressedzlibDeflateOptions:objectoptions to pass to zlib on deflatezlibInflateOptions:objectoptions to pass to zlib on inflate
schedulercan be set to aMuMockSchedulerfor testing
implements MuSocket
import { MuWebSocket } from 'mudb/socket/web/client'
new MuWebSocket(spec:{
sessionId:string,
url:string,
maxSockets:number=5,
bufferLimit:number=1024,
logger?:MuLogger,
})sessionIdthe token used to identify the clienturlthe server URLmaxSocketsthe number of WebSocket connections to be openedbufferLimitthe hard limit on the byte size of buffered data, exceeding which will cause unreliable messages to be dropped