@@ -143,72 +143,96 @@ export default class StreamingMonitor extends LightningElement {
143143 `Subscribing to multiple streaming channels with filter ${ filter } and replay ID ${ replayId } `
144144 ) ;
145145
146- // Build list of channels
147- let channels = [ ] ;
148- EVENT_TYPES . forEach ( ( eventType ) => {
149- const eventTypeName = eventType . value ;
150- if ( filter === FILTER_ALL ) {
151- if ( eventTypeName === EVT_CDC ) {
146+ try {
147+ // Build list of channels
148+ let channels = [ ] ;
149+ switch ( filter ) {
150+ case FILTER_ALL :
151+ // Get all event channels
152+ EVENT_TYPES . forEach ( ( type ) => {
153+ const typeName = type . value ;
154+ if ( typeName === EVT_CDC ) {
155+ // Use global channel for all CDC events
156+ channels . push ( CHANNEL_ALL_CDC ) ;
157+ } else {
158+ // Get all channels for the other event types
159+ const channelPrefix = getChannelPrefix ( typeName ) ;
160+ this . channels [ typeName ] . forEach ( ( channelData ) => {
161+ channels . push (
162+ channelPrefix + channelData . value
163+ ) ;
164+ } ) ;
165+ }
166+ } ) ;
167+ break ;
168+ case FILTER_CUSTOM :
169+ // Get custom channels for all event types
170+ EVENT_TYPES . forEach ( ( type ) => {
171+ const typeName = type . value ;
172+ const channelPrefix = getChannelPrefix ( typeName ) ;
173+ this . channels [ typeName ] . forEach ( ( channelData ) => {
174+ if ( isCustomChannel ( typeName , channelData . value ) ) {
175+ channels . push (
176+ channelPrefix + channelData . value
177+ ) ;
178+ }
179+ } ) ;
180+ } ) ;
181+ break ;
182+ case EVT_CDC :
152183 // Use global channel for all CDC events
153184 channels . push ( CHANNEL_ALL_CDC ) ;
154- } else {
155- // Get all channels for the other event types
156- const channelPrefix = getChannelPrefix ( eventTypeName ) ;
157- this . channels [ eventTypeName ] . forEach ( ( channelData ) => {
185+ break ;
186+ default : {
187+ // Add channels of given type
188+ const channelPrefix = getChannelPrefix ( filter ) ;
189+ this . channels [ filter ] . forEach ( ( channelData ) => {
158190 channels . push ( channelPrefix + channelData . value ) ;
159191 } ) ;
160192 }
161- } else if ( filter === FILTER_CUSTOM ) {
162- // Get custom channels for all event types
163- const channelPrefix = getChannelPrefix ( eventTypeName ) ;
164- this . channels [ eventTypeName ] . forEach ( ( channelData ) => {
165- if ( isCustomChannel ( eventTypeName , channelData . value ) ) {
166- channels . push ( channelPrefix + channelData . value ) ;
167- }
168- } ) ;
169- } else {
170- throw new Error ( `Unsupported filter value: ${ filter } ` ) ;
171193 }
172- } ) ;
173194
174- // Remove already subscribed channels
175- channels = channels . filter (
176- ( channel ) =>
177- ! this . subscriptions . some ( ( sub ) => sub . channel === channel )
178- ) ;
179-
180- // Abort if there are no remaining channels
181- if ( channels . length === 0 ) {
182- this . notify (
183- 'warn' ,
184- 'There are no channels to subscribe to with the specified filter and current subscriptions'
195+ // Remove already subscribed channels
196+ channels = channels . filter (
197+ ( channel ) =>
198+ ! this . subscriptions . some ( ( sub ) => sub . channel === channel )
185199 ) ;
186- return ;
187- }
188200
189- // Temporarily ignore subscribe errors while subscribing to events
190- this . ignoreSubscribeErrors = true ;
191- setTimeout ( ( ) => {
192- this . ignoreSubscribeErrors = false ;
193- } , IGNORE_SUBCRIBE_ERRORS_DELAY ) ;
201+ // Abort if there are no remaining channels
202+ if ( channels . length === 0 ) {
203+ this . notify (
204+ 'warn' ,
205+ 'There are no channels to subscribe to with the specified filter and current subscriptions'
206+ ) ;
207+ return ;
208+ }
194209
195- // Queue subscriptions
196- const subscribePromises = channels . map ( ( channel ) => {
197- return subscribe ( channel , replayId , ( streamingEvent ) => {
198- this . handleStreamingEvent ( streamingEvent ) ;
210+ // Temporarily ignore subscribe errors while subscribing to events
211+ this . ignoreSubscribeErrors = true ;
212+ setTimeout ( ( ) => {
213+ this . ignoreSubscribeErrors = false ;
214+ } , IGNORE_SUBCRIBE_ERRORS_DELAY ) ;
215+
216+ // Queue subscriptions
217+ const subscribePromises = channels . map ( ( channel ) => {
218+ return subscribe ( channel , replayId , ( streamingEvent ) => {
219+ this . handleStreamingEvent ( streamingEvent ) ;
220+ } ) ;
199221 } ) ;
200- } ) ;
201222
202- // Save susbcriptions and notify success once done
203- const subscriptions = await Promise . all ( subscribePromises ) ;
204- subscriptions . forEach ( ( subscription ) => {
205- this . saveSubscription ( subscription ) ;
206- } ) ;
207- this . notify (
208- 'success' ,
209- 'Successfully subscribed to the specified channels'
210- ) ;
211- this . view = VIEW_MONITOR ;
223+ // Save susbcriptions and notify success once done
224+ const subscriptions = await Promise . all ( subscribePromises ) ;
225+ subscriptions . forEach ( ( subscription ) => {
226+ this . saveSubscription ( subscription ) ;
227+ } ) ;
228+ this . notify (
229+ 'success' ,
230+ 'Successfully subscribed to the specified channels'
231+ ) ;
232+ this . view = VIEW_MONITOR ;
233+ } catch ( error ) {
234+ console . error ( error . message ) ;
235+ }
212236 }
213237
214238 async handleSubscribe ( event ) {
0 commit comments