@@ -7,10 +7,11 @@ import {
7
7
DEFAULT_TIMEOUT ,
8
8
SOCKET_STATES ,
9
9
TRANSPORTS ,
10
- VERSION ,
11
10
VSN ,
12
11
WS_CLOSE_NORMAL ,
12
+ LOG_LEVEL ,
13
13
} from './lib/constants'
14
+
14
15
import Serializer from './lib/serializer'
15
16
import Timer from './lib/timer'
16
17
@@ -26,23 +27,7 @@ export type Channel = {
26
27
updated_at : string
27
28
id : number
28
29
}
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
46
31
47
32
export type RealtimeMessage = {
48
33
topic : string
@@ -72,6 +57,25 @@ export interface WebSocketLikeError {
72
57
type : string
73
58
}
74
59
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
+
75
79
const NATIVE_WEBSOCKET_AVAILABLE = typeof WebSocket !== 'undefined'
76
80
const WORKER_SCRIPT = `
77
81
addEventListener("message", (e) => {
@@ -89,12 +93,13 @@ export default class RealtimeClient {
89
93
params ?: { [ key : string ] : string } = { }
90
94
timeout : number = DEFAULT_TIMEOUT
91
95
transport : WebSocketLikeConstructor | null
92
- heartbeatIntervalMs : number = 30000
96
+ heartbeatIntervalMs : number = 25000
93
97
heartbeatTimer : ReturnType < typeof setInterval > | undefined = undefined
94
98
pendingHeartbeatRef : string | null = null
95
99
ref : number = 0
96
100
reconnectTimer : Timer
97
101
logger : Function = noop
102
+ logLevel ?: LogLevel
98
103
encode : Function
99
104
decode : Function
100
105
reconnectAfterMs : Function
@@ -129,6 +134,7 @@ export default class RealtimeClient {
129
134
* @param options.headers The optional headers to pass when connecting.
130
135
* @param options.heartbeatIntervalMs The millisec interval to send a heartbeat message.
131
136
* @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
132
138
* @param options.encode The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))
133
139
* @param options.decode The function to decode incoming messages. Defaults to Serializer's decode.
134
140
* @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 {
147
153
if ( options ?. headers ) this . headers = { ...this . headers , ...options . headers }
148
154
if ( options ?. timeout ) this . timeout = options . timeout
149
155
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
+
150
161
if ( options ?. heartbeatIntervalMs )
151
162
this . heartbeatIntervalMs = options . heartbeatIntervalMs
152
163
0 commit comments