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 useWhere to run
authenticate()Run configured auth flowClient
requestToken(tokenRequest)Exchange signed request for JWTClient
generateToken(opts?)Sign a JWT locally with the API key secretServer / trusted
issueToken(opts?)Request a platform-issued JWTServer / trusted
createTokenRequest(opts?)Create a signed token request for client-side exchangeServer / trusted
clearToken()Drop active tokenClient
getAuthHeaders()Header map for HTTPClient

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