@@ -155,13 +155,9 @@ public final class RealtimeChannelV2: Sendable {
155155 logger? . debug ( " Subscribing to channel with body: \( joinConfig) " )
156156
157157 await push (
158- RealtimeMessageV2 (
159- joinRef: joinRef,
160- ref: joinRef,
161- topic: topic,
162- event: ChannelEvent . join,
163- payload: try ! JSONObject ( payload)
164- )
158+ ChannelEvent . join,
159+ ref: joinRef,
160+ payload: try ! JSONObject ( payload)
165161 )
166162
167163 do {
@@ -182,27 +178,19 @@ public final class RealtimeChannelV2: Sendable {
182178 status = . unsubscribing
183179 logger? . debug ( " Unsubscribing from channel \( topic) " )
184180
185- await push (
186- RealtimeMessageV2 (
187- joinRef: mutableState. joinRef,
188- ref: socket. makeRef ( ) . description,
189- topic: topic,
190- event: ChannelEvent . leave,
191- payload: [ : ]
192- )
193- )
181+ await push ( ChannelEvent . leave)
194182 }
195183
184+ @available (
185+ * ,
186+ deprecated,
187+ message: " manually updating auth token per channel is not recommended, please use `setAuth` in RealtimeClient instead. "
188+ )
196189 public func updateAuth( jwt: String ? ) async {
197190 logger? . debug ( " Updating auth token for channel \( topic) " )
198191 await push (
199- RealtimeMessageV2 (
200- joinRef: mutableState. joinRef,
201- ref: socket. makeRef ( ) . description,
202- topic: topic,
203- event: ChannelEvent . accessToken,
204- payload: [ " access_token " : jwt. map { . string( $0) } ?? . null]
205- )
192+ ChannelEvent . accessToken,
193+ payload: [ " access_token " : jwt. map { . string( $0) } ?? . null]
206194 )
207195 }
208196
@@ -264,17 +252,12 @@ public final class RealtimeChannelV2: Sendable {
264252 }
265253 } else {
266254 await push (
267- RealtimeMessageV2 (
268- joinRef: mutableState. joinRef,
269- ref: socket. makeRef ( ) . description,
270- topic: topic,
271- event: ChannelEvent . broadcast,
272- payload: [
273- " type " : " broadcast " ,
274- " event " : . string( event) ,
275- " payload " : . object( message) ,
276- ]
277- )
255+ ChannelEvent . broadcast,
256+ payload: [
257+ " type " : " broadcast " ,
258+ " event " : . string( event) ,
259+ " payload " : . object( message) ,
260+ ]
278261 )
279262 }
280263 }
@@ -290,32 +273,22 @@ public final class RealtimeChannelV2: Sendable {
290273 )
291274
292275 await push (
293- RealtimeMessageV2 (
294- joinRef: mutableState. joinRef,
295- ref: socket. makeRef ( ) . description,
296- topic: topic,
297- event: ChannelEvent . presence,
298- payload: [
299- " type " : " presence " ,
300- " event " : " track " ,
301- " payload " : . object( state) ,
302- ]
303- )
276+ ChannelEvent . presence,
277+ payload: [
278+ " type " : " presence " ,
279+ " event " : " track " ,
280+ " payload " : . object( state) ,
281+ ]
304282 )
305283 }
306284
307285 public func untrack( ) async {
308286 await push (
309- RealtimeMessageV2 (
310- joinRef: mutableState. joinRef,
311- ref: socket. makeRef ( ) . description,
312- topic: topic,
313- event: ChannelEvent . presence,
314- payload: [
315- " type " : " presence " ,
316- " event " : " untrack " ,
317- ]
318- )
287+ ChannelEvent . presence,
288+ payload: [
289+ " type " : " presence " ,
290+ " event " : " untrack " ,
291+ ]
319292 )
320293 }
321294
@@ -572,13 +545,24 @@ public final class RealtimeChannelV2: Sendable {
572545 }
573546
574547 @discardableResult
575- private func push( _ message: RealtimeMessageV2 ) async -> PushStatus {
576- let push = PushV2 ( channel: self , message: message)
577- if let ref = message. ref {
578- mutableState. withValue {
548+ func push( _ event: String , ref: String ? = nil , payload: JSONObject = [ : ] ) async -> PushStatus {
549+ let push = mutableState. withValue {
550+ let message = RealtimeMessageV2 (
551+ joinRef: $0. joinRef,
552+ ref: ref ?? socket. makeRef ( ) . description,
553+ topic: self . topic,
554+ event: event,
555+ payload: payload
556+ )
557+
558+ let push = PushV2 ( channel: self , message: message)
559+ if let ref = message. ref {
579560 $0. pushes [ ref] = push
580561 }
562+
563+ return push
581564 }
565+
582566 return await push. send ( )
583567 }
584568
0 commit comments