@@ -155,13 +155,8 @@ 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+ payload: try ! JSONObject ( payload)
165160 )
166161
167162 do {
@@ -182,27 +177,19 @@ public final class RealtimeChannelV2: Sendable {
182177 status = . unsubscribing
183178 logger? . debug ( " Unsubscribing from channel \( topic) " )
184179
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- )
180+ await push ( ChannelEvent . leave)
194181 }
195182
183+ @available (
184+ * ,
185+ deprecated,
186+ message: " manually updating auth token per channel is not recommended, please use `setAuth` in RealtimeClient instead. "
187+ )
196188 public func updateAuth( jwt: String ? ) async {
197189 logger? . debug ( " Updating auth token for channel \( topic) " )
198190 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- )
191+ ChannelEvent . accessToken,
192+ payload: [ " access_token " : jwt. map { . string( $0) } ?? . null]
206193 )
207194 }
208195
@@ -264,17 +251,12 @@ public final class RealtimeChannelV2: Sendable {
264251 }
265252 } else {
266253 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- )
254+ ChannelEvent . broadcast,
255+ payload: [
256+ " type " : " broadcast " ,
257+ " event " : . string( event) ,
258+ " payload " : . object( message) ,
259+ ]
278260 )
279261 }
280262 }
@@ -290,32 +272,22 @@ public final class RealtimeChannelV2: Sendable {
290272 )
291273
292274 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- )
275+ ChannelEvent . presence,
276+ payload: [
277+ " type " : " presence " ,
278+ " event " : " track " ,
279+ " payload " : . object( state) ,
280+ ]
304281 )
305282 }
306283
307284 public func untrack( ) async {
308285 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- )
286+ ChannelEvent . presence,
287+ payload: [
288+ " type " : " presence " ,
289+ " event " : " untrack " ,
290+ ]
319291 )
320292 }
321293
@@ -572,13 +544,24 @@ public final class RealtimeChannelV2: Sendable {
572544 }
573545
574546 @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 {
547+ func push( _ event: String , payload: JSONObject = [ : ] ) async -> PushStatus {
548+ let push = mutableState. withValue {
549+ let message = RealtimeMessageV2 (
550+ joinRef: $0. joinRef,
551+ ref: socket. makeRef ( ) . description,
552+ topic: self . topic,
553+ event: event,
554+ payload: payload
555+ )
556+
557+ let push = PushV2 ( channel: self , message: message)
558+ if let ref = message. ref {
579559 $0. pushes [ ref] = push
580560 }
561+
562+ return push
581563 }
564+
582565 return await push. send ( )
583566 }
584567
0 commit comments