Socket SDK Constructor

import { QPub } from "@qpub/sdk";

const socket = new QPub.Socket({
  apiKey: process.env.QPUB_API_KEY,
});

Options

Pass a partial options object. Important fields:

OptionDefaultDescription
apiKeyAPI key publicId:secret
authUrlPOST URL that returns { token } or { tokenRequest }
authOptions{ headers?, body? } for authUrl
tokenRequestPre-signed token request; fetches JWT on init
aliasClient alias
httpHostrest.qpub.ioHost for token/HTTP auth helpers
httpPortnullOptional port
wsHostsocket.qpub.ioWebSocket host
wsPortnullOptional port
isSecuretruewss/https vs ws/http
autoConnecttrueConnect on construct
autoReconnecttrueReconnect with backoff
autoResubscribetrueResubscribe after reconnect
autoAuthenticatetrueAuthenticate before connect
connectTimeoutMs10000Connect timeout
maxReconnectAttempts10Reconnect limit
initialReconnectDelayMs1000Backoff start
maxReconnectDelayMs30000Backoff cap
reconnectBackoffMultiplier1.5Backoff factor
authenticateRetries3Auth retry count
authenticateRetryIntervalMs1000Auth retry delay
pingTimeoutMs10000Ping timeout
debugfalseDebug logging
logLevel"error"error | warn | info | debug | trace
loggerCustom logger function

resubscribeIntervalMs exists on the options type but is not used yet.

Provide one of apiKey, authUrl, or tokenRequest (depending on your auth flow).

Instance

Property / methodDescription
socket.connectionConnection API and events — Connection
socket.channelsChannel manager — Channels
socket.authAuth manager (authenticate, tokens)
socket.optionManagerRuntime options
socket.reset()Reset instance state
socket.getInstanceId()Instance id string
socket.getAbortSignal()AbortSignal for in-flight work

Auth helpers (on socket.auth)

MethodTypical use
authenticate()Run configured auth flow
requestToken(tokenRequest)Exchange signed request for JWT
generateToken(opts?)Local JWT (server / trusted)
issueToken(opts?)Platform-issued JWT
createTokenRequest(opts?)Signed token request for clients
clearToken()Drop active token
getAuthHeaders()Header map for HTTP

Also see @qpub/sdk/react for SocketProvider, useConnection, useChannel, useAuth.