@@ -4,6 +4,7 @@ import 'dart:core';
44
55import 'package:collection/collection.dart' ;
66import 'package:http/http.dart' ;
7+ import 'package:logging/logging.dart' ;
78import 'package:meta/meta.dart' ;
89import 'package:realtime_client/realtime_client.dart' ;
910import 'package:realtime_client/src/constants.dart' ;
@@ -62,6 +63,7 @@ class RealtimeClient {
6263 final Duration timeout;
6364 final WebSocketTransport transport;
6465 final Client ? httpClient;
66+ final _log = Logger ('supabase.realtime' );
6567 int heartbeatIntervalMs = 30000 ;
6668 Timer ? heartbeatTimer;
6769
@@ -90,18 +92,29 @@ class RealtimeClient {
9092
9193 /// Initializes the Socket
9294 ///
93- /// `endPoint` The string WebSocket endpoint, ie, "ws://example.com/socket", "wss://example.com", "/socket" (inherited host & protocol)
94- /// `httpEndpoint` The string HTTP endpoint, ie, "https://example.com", "/" (inherited host & protocol)
95- /// `transport` The Websocket Transport, for example WebSocket.
96- /// `timeout` The default timeout in milliseconds to trigger push timeouts.
97- /// `params` The optional params to pass when connecting.
98- /// `headers` The optional headers to pass when connecting.
99- /// `heartbeatIntervalMs` The millisec interval to send a heartbeat message.
100- /// `logger` The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(`$kind: $msg` , data) }
101- /// `encode` The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))
102- /// `decode` The function to decode incoming messages. Defaults to JSON: (payload, callback) => callback(JSON.parse(payload))
103- /// `longpollerTimeout` The maximum timeout of a long poll AJAX request. Defaults to 20s (double the server long poll timer).
104- /// `reconnectAfterMs` The optional function that returns the millsec reconnect interval. Defaults to stepped backoff off.
95+ /// [endPoint] The string WebSocket endpoint, ie, "ws://example.com/socket", "wss://example.com", "/socket" (inherited host & protocol
96+ ///
97+ /// [transport] The Websocket Transport, for example WebSocket.
98+ ///
99+ /// [timeout] The default timeout in milliseconds to trigger push timeouts.
100+ ///
101+ /// [params] The optional params to pass when connecting.
102+ ///
103+ /// [headers] The optional headers to pass when connecting.
104+ ///
105+ /// [heartbeatIntervalMs] The millisec interval to send a heartbeat message.
106+ ///
107+ /// [logger] The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(`$kind: $msg` , data) }
108+ ///
109+ /// [encode] The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))
110+ ///
111+ /// [decode] The function to decode incoming messages. Defaults to JSON: (payload, callback) => callback(JSON.parse(payload))
112+ ///
113+ /// [longpollerTimeout] The maximum timeout of a long poll AJAX request. Defaults to 20s (double the server long poll timer).
114+ ///
115+ /// [reconnectAfterMs] The optional function that returns the millsec reconnect interval. Defaults to stepped backoff off.
116+ ///
117+ /// [logLevel] Specifies the log level for the connection on the server.
105118 RealtimeClient (
106119 String endPoint, {
107120 WebSocketTransport ? transport,
@@ -155,6 +168,7 @@ class RealtimeClient {
155168 }
156169
157170 try {
171+ log ('transport' , 'connecting to $endPointURL ' );
158172 connState = SocketStates .connecting;
159173 conn = transport (endPointURL, headers);
160174
@@ -202,6 +216,7 @@ class RealtimeClient {
202216 if (conn != null ) {
203217 final oldState = connState;
204218 connState = SocketStates .disconnecting;
219+ log ('transport' , 'disconnecting' , {'code' : code, 'reason' : reason});
205220
206221 // Connection cannot be closed while it's still connecting. Wait for connection to
207222 // be ready and then close it.
@@ -218,6 +233,7 @@ class RealtimeClient {
218233 }
219234 connState = SocketStates .disconnected;
220235 reconnectTimer.reset ();
236+ log ('transport' , 'disconnected' );
221237 }
222238 this .conn = null ;
223239
@@ -247,6 +263,7 @@ class RealtimeClient {
247263
248264 /// Logs the message. Override `this.logger` for specialized logging.
249265 void log ([String ? kind, String ? msg, dynamic data]) {
266+ _log.finer ('$kind : $msg ' , data);
250267 logger? .call (kind, msg, data);
251268 }
252269
0 commit comments