File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -246,6 +246,26 @@ export class EventHub {
246246 return subscriber . metadata . id ;
247247 }
248248
249+ /**
250+ * Unsubscribe from *subscription* events.
251+ *
252+ * @param {String } identifier Subscriber ID returned from subscribe method.
253+ * @return {Boolean } True if a subscriber was removed, false otherwise
254+ */
255+ unsubscribe ( identifier ) {
256+ let hasFoundSubscriberToRemove = false ;
257+ this . _subscribers = this . _subscribers . filter ( ( subscriber ) => {
258+ if ( subscriber . metadata . id === identifier ) {
259+ this . _notifyServerAboutUnsubscribe ( hasFoundSubscriberToRemove ) ;
260+ hasFoundSubscriberToRemove = true ;
261+ return false ;
262+ }
263+ return true ;
264+ } ) ;
265+
266+ return hasFoundSubscriberToRemove ;
267+ }
268+
249269 /**
250270 * Return topic from *subscription* expression.
251271 *
@@ -317,6 +337,13 @@ export class EventHub {
317337 this . publish ( subscribeEvent ) ;
318338 }
319339
340+ _notifyServerAboutUnsubscribe ( subscriber ) {
341+ const unsubscribeEvent = new Event ( "ftrack.meta.unsubscribe" , {
342+ subscriber,
343+ } ) ;
344+ this . publish ( unsubscribeEvent ) ;
345+ }
346+
320347 /**
321348 * Return subscriber with matching *identifier*.
322349 *
You can’t perform that action at this time.
0 commit comments