Reference / @getenginex/sdk / WebSocketLike
WebSocketLike
WebSocketLike = (
url) =>WebSocketLikeInstance
Constructor compatible with the browser WebSocket, for the client's webSocket option (tests, Node, custom implementations). Realtime only calls new webSocket(url).
Outside the browser, passing Node's WebSocket or the one from the ws package directly is not enough: the gateway resolves the tenant from the Origin header, which only the browser sends by itself. Pass a constructor that adds the Origin of the operator's site, as in the example.
Parameters
url
string
Returns
Examples
ts
// Node 22+: the global WebSocket accepts `{ headers }` as the second argument.
type NodeWebSocket = new (url: string, init: { headers: Record<string, string> }) => WebSocket
class OriginWebSocket extends (globalThis.WebSocket as unknown as NodeWebSocket) {
constructor(url: string) {
super(url, { headers: { Origin: 'https://casino.operador.com' } })
}
}
const enginex = createEnginexClient({ baseUrl: 'https://gateway.operador.com', webSocket: OriginWebSocket })ts
// `ws` package: `Origin` goes in the constructor options.
import WebSocket from 'ws'
class OriginWebSocket extends WebSocket {
constructor(url: string) {
super(url, { origin: 'https://casino.operador.com' })
}
}
const enginex = createEnginexClient({ baseUrl: 'https://gateway.operador.com', webSocket: OriginWebSocket })