@@ -7,10 +7,11 @@ import {
77 DEFAULT_TIMEOUT ,
88 SOCKET_STATES ,
99 TRANSPORTS ,
10- VERSION ,
1110 VSN ,
1211 WS_CLOSE_NORMAL ,
12+ LOG_LEVEL ,
1313} from './lib/constants'
14+
1415import Serializer from './lib/serializer'
1516import Timer from './lib/timer'
1617
@@ -26,23 +27,7 @@ export type Channel = {
2627 updated_at : string
2728 id : number
2829}
29-
30- export type RealtimeClientOptions = {
31- transport ?: WebSocketLikeConstructor
32- timeout ?: number
33- heartbeatIntervalMs ?: number
34- logger ?: Function
35- encode ?: Function
36- decode ?: Function
37- reconnectAfterMs ?: Function
38- headers ?: { [ key : string ] : string }
39- params ?: { [ key : string ] : any }
40- log_level ?: 'info' | 'debug' | 'warn' | 'error'
41- fetch ?: Fetch
42- worker ?: boolean
43- workerUrl ?: string
44- accessToken ?: ( ) => Promise < string | null >
45- }
30+ export type LogLevel = LOG_LEVEL
4631
4732export type RealtimeMessage = {
4833 topic : string
@@ -72,6 +57,25 @@ export interface WebSocketLikeError {
7257 type : string
7358}
7459
60+ export type RealtimeClientOptions = {
61+ transport ?: WebSocketLikeConstructor
62+ timeout ?: number
63+ heartbeatIntervalMs ?: number
64+ logger ?: Function
65+ encode ?: Function
66+ decode ?: Function
67+ reconnectAfterMs ?: Function
68+ headers ?: { [ key : string ] : string }
69+ params ?: { [ key : string ] : any }
70+ //Deprecated: Use it in favour of correct casing `logLevel`
71+ log_level ?: LogLevel
72+ logLevel ?: LogLevel
73+ fetch ?: Fetch
74+ worker ?: boolean
75+ workerUrl ?: string
76+ accessToken ?: ( ) => Promise < string | null >
77+ }
78+
7579const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'
7680const WORKER_SCRIPT = `
7781 addEventListener("message", (e) => {
@@ -89,12 +93,13 @@ export default class RealtimeClient {
8993 params ?: { [ key : string ] : string } = { }
9094 timeout : number = DEFAULT_TIMEOUT
9195 transport : WebSocketLikeConstructor | null
92- heartbeatIntervalMs : number = 30000
96+ heartbeatIntervalMs : number = 25000
9397 heartbeatTimer : ReturnType < typeof setInterval > | undefined = undefined
9498 pendingHeartbeatRef : string | null = null
9599 ref : number = 0
96100 reconnectTimer : Timer
97101 logger : Function = noop
102+ logLevel ?: LogLevel
98103 encode : Function
99104 decode : Function
100105 reconnectAfterMs : Function
@@ -129,6 +134,7 @@ export default class RealtimeClient {
129134 * @param options.headers The optional headers to pass when connecting.
130135 * @param options.heartbeatIntervalMs The millisec interval to send a heartbeat message.
131136 * @param options.logger The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(`${kind}: ${msg}`, data) }
137+ * @param options.logLevel Sets the log level for Realtime
132138 * @param options.encode The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))
133139 * @param options.decode The function to decode incoming messages. Defaults to Serializer's decode.
134140 * @param options.reconnectAfterMs he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off.
@@ -147,6 +153,11 @@ export default class RealtimeClient {
147153 if ( options ?. headers ) this . headers = { ...this . headers , ...options . headers }
148154 if ( options ?. timeout ) this . timeout = options . timeout
149155 if ( options ?. logger ) this . logger = options . logger
156+ if ( options ?. logLevel || options ?. log_level ) {
157+ this . logLevel = options . logLevel || options . log_level
158+ this . params = { ...this . params , log_level : this . logLevel as string }
159+ }
160+
150161 if ( options ?. heartbeatIntervalMs )
151162 this . heartbeatIntervalMs = options . heartbeatIntervalMs
152163
0 commit comments