@@ -23,22 +23,11 @@ export interface TransmitLifecycleHooks<Context> {
2323 unsubscribe : { uid : string ; channel : string ; context : Context }
2424}
2525
26- type TransmitMessage =
27- | {
28- type : typeof TransportMessageType . Broadcast
29- channel : string
30- payload : Broadcastable
31- }
32- | {
33- type : typeof TransportMessageType . Subscribe
34- channel : string
35- payload : { uid : string }
36- }
37- | {
38- type : typeof TransportMessageType . Unsubscribe
39- channel : string
40- payload : { uid : string }
41- }
26+ type TransmitMessage = {
27+ type : typeof TransportMessageType . Broadcast
28+ channel : string
29+ payload : Broadcastable
30+ }
4231
4332export class Transmit < Context extends unknown > {
4433 /**
@@ -82,15 +71,7 @@ export class Transmit<Context extends unknown> {
8271
8372 // Subscribe to the transport channel and handle incoming messages
8473 void this . #bus?. subscribe < TransmitMessage > ( this . #transportChannel, ( message ) => {
85- const { type, channel, payload } = message
86-
87- if ( type === TransportMessageType . Broadcast ) {
88- void this . #broadcastLocally( channel , payload )
89- } else if ( type === TransportMessageType . Subscribe ) {
90- void this . #subscribeLocally( { uid : payload . uid , channel } )
91- } else if ( type === TransportMessageType . Unsubscribe ) {
92- void this . #unsubscribeLocally( { uid : payload . uid , channel } )
93- }
74+ void this . #broadcastLocally( message . channel , message . payload )
9475 } )
9576
9677 // Start the ping interval if configured
@@ -133,13 +114,6 @@ export class Transmit<Context extends unknown> {
133114 this . #manager. authorize ( channel , callback )
134115 }
135116
136- #subscribeLocally( params : Omit < SubscribeParams < Context > , 'onSubscribe' > ) {
137- return this . #manager. subscribe ( {
138- ...params ,
139- skipAuthorization : true ,
140- } )
141- }
142-
143117 subscribe ( params : Omit < SubscribeParams < Context > , 'onSubscribe' > ) {
144118 return this . #manager. subscribe ( {
145119 ...params ,
@@ -149,22 +123,10 @@ export class Transmit<Context extends unknown> {
149123 channel,
150124 context,
151125 } )
152-
153- void this . #bus?. publish ( this . #transportChannel, {
154- type : TransportMessageType . Subscribe ,
155- channel,
156- payload : { uid } ,
157- } )
158126 } ,
159127 } )
160128 }
161129
162- #unsubscribeLocally( params : Omit < UnsubscribeParams < Context > , 'onUnsubscribe' > ) {
163- return this . #manager. unsubscribe ( {
164- ...params ,
165- } )
166- }
167-
168130 unsubscribe ( params : Omit < UnsubscribeParams < Context > , 'onUnsubscribe' > ) {
169131 return this . #manager. unsubscribe ( {
170132 ...params ,
@@ -174,12 +136,6 @@ export class Transmit<Context extends unknown> {
174136 channel,
175137 context,
176138 } )
177-
178- void this . #bus?. publish ( this . #transportChannel, {
179- type : TransportMessageType . Unsubscribe ,
180- channel,
181- payload : { uid } ,
182- } )
183139 } ,
184140 } )
185141 }
0 commit comments