@@ -30,6 +30,7 @@ public actor RealtimeChannelV2 {
3030
3131 let topic : String
3232 let config : RealtimeChannelConfig
33+ let logger : SupabaseLogger ?
3334
3435 private let callbackManager = CallbackManager ( )
3536 let statusStreamManager = AsyncStreamManager < Status > ( )
@@ -45,11 +46,13 @@ public actor RealtimeChannelV2 {
4546 init (
4647 topic: String ,
4748 config: RealtimeChannelConfig ,
48- socket: RealtimeClientV2
49+ socket: RealtimeClientV2 ,
50+ logger: SupabaseLogger ?
4951 ) {
5052 self . socket = socket
5153 self . topic = topic
5254 self . config = config
55+ self . logger = logger
5356 }
5457
5558 deinit {
@@ -72,7 +75,7 @@ public actor RealtimeChannelV2 {
7275 await socket? . addChannel ( self )
7376
7477 statusStreamManager. yield ( . subscribing)
75- debug ( " subscribing to channel \( topic) " )
78+ logger ? . debug ( " subscribing to channel \( topic) " )
7679
7780 let accessToken = await socket? . accessToken
7881
@@ -87,7 +90,7 @@ public actor RealtimeChannelV2 {
8790
8891 joinRef = await socket? . makeRef ( ) . description
8992
90- debug ( " subscribing to channel with body: \( joinConfig) " )
93+ logger ? . debug ( " subscribing to channel with body: \( joinConfig) " )
9194
9295 await push (
9396 RealtimeMessageV2 (
@@ -106,7 +109,7 @@ public actor RealtimeChannelV2 {
106109
107110 public func unsubscribe( ) async {
108111 statusStreamManager. yield ( . unsubscribing)
109- debug ( " unsubscribing from channel \( topic) " )
112+ logger ? . debug ( " unsubscribing from channel \( topic) " )
110113
111114 await push (
112115 RealtimeMessageV2 (
@@ -120,7 +123,7 @@ public actor RealtimeChannelV2 {
120123 }
121124
122125 public func updateAuth( jwt: String ) async {
123- debug ( " Updating auth token for channel \( topic) " )
126+ logger ? . debug ( " Updating auth token for channel \( topic) " )
124127 await push (
125128 RealtimeMessageV2 (
126129 joinRef: joinRef,
@@ -196,18 +199,18 @@ public actor RealtimeChannelV2 {
196199 func onMessage( _ message: RealtimeMessageV2 ) {
197200 do {
198201 guard let eventType = message. eventType else {
199- debug ( " Received message without event type: \( message) " )
202+ logger ? . debug ( " Received message without event type: \( message) " )
200203 return
201204 }
202205
203206 switch eventType {
204207 case . tokenExpired:
205- debug (
208+ logger ? . debug (
206209 " Received token expired event. This should not happen, please report this warning. "
207210 )
208211
209212 case . system:
210- debug ( " Subscribed to channel \( message. topic) " )
213+ logger ? . debug ( " Subscribed to channel \( message. topic) " )
211214 statusStreamManager. yield ( . subscribed)
212215
213216 case . reply:
@@ -231,13 +234,13 @@ public actor RealtimeChannelV2 {
231234
232235 if statusStreamManager. value != . subscribed {
233236 statusStreamManager. yield ( . subscribed)
234- debug ( " Subscribed to channel \( message. topic) " )
237+ logger ? . debug ( " Subscribed to channel \( message. topic) " )
235238 }
236239 }
237240
238241 case . postgresChanges:
239242 guard let data = message. payload [ " data " ] else {
240- debug ( " Expected \" data \" key in message payload. " )
243+ logger ? . debug ( " Expected \" data \" key in message payload. " )
241244 return
242245 }
243246
@@ -307,11 +310,11 @@ public actor RealtimeChannelV2 {
307310 guard let self else { return }
308311
309312 await socket? . removeChannel ( self )
310- debug ( " Unsubscribed from channel \( message. topic) " )
313+ logger ? . debug ( " Unsubscribed from channel \( message. topic) " )
311314 }
312315
313316 case . error:
314- debug (
317+ logger ? . debug (
315318 " Received an error in channel \( message. topic) . That could be as a result of an invalid access token "
316319 )
317320
@@ -325,7 +328,7 @@ public actor RealtimeChannelV2 {
325328 callbackManager. triggerPresenceDiffs ( joins: joins, leaves: [ : ] , rawMessage: message)
326329 }
327330 } catch {
328- debug ( " Failed: \( error) " )
331+ logger ? . debug ( " Failed: \( error) " )
329332 }
330333 }
331334
@@ -337,8 +340,10 @@ public actor RealtimeChannelV2 {
337340 continuation. yield ( $0)
338341 }
339342
343+ let logger = logger
344+
340345 continuation. onTermination = { [ weak callbackManager] _ in
341- debug ( " Removing presence callback with id: \( id) " )
346+ logger ? . debug ( " Removing presence callback with id: \( id) " )
342347 callbackManager? . removeCallback ( id: id)
343348 }
344349
@@ -429,8 +434,10 @@ public actor RealtimeChannelV2 {
429434 continuation. yield ( action)
430435 }
431436
437+ let logger = logger
438+
432439 continuation. onTermination = { [ weak callbackManager] _ in
433- debug ( " Removing postgres callback with id: \( id) " )
440+ logger ? . debug ( " Removing postgres callback with id: \( id) " )
434441 callbackManager? . removeCallback ( id: id)
435442 }
436443
@@ -446,8 +453,10 @@ public actor RealtimeChannelV2 {
446453 continuation. yield ( $0)
447454 }
448455
456+ let logger = logger
457+
449458 continuation. onTermination = { [ weak callbackManager] _ in
450- debug ( " Removing broadcast callback with id: \( id) " )
459+ logger ? . debug ( " Removing broadcast callback with id: \( id) " )
451460 callbackManager? . removeCallback ( id: id)
452461 }
453462
0 commit comments