From bfa67083816d9e99446f018b3797f91a2671ea32 Mon Sep 17 00:00:00 2001 From: Embbnux Ji Date: Wed, 19 Jun 2024 17:53:38 +0800 Subject: [PATCH] misc: remove pubnub subscription support (#833) --- src/modules/Phone/index.js | 16 +- .../Subscription/PubnubReadyController.ts | 35 ---- .../Subscription/PubnubSubscription.ts | 65 ------- .../Subscription/RingCentralExtensions.ts | 10 -- .../Subscription/WebSocketReadyController.ts | 35 ---- src/modules/Subscription/index.ts | 164 ------------------ 6 files changed, 2 insertions(+), 323 deletions(-) delete mode 100644 src/modules/Subscription/PubnubReadyController.ts delete mode 100644 src/modules/Subscription/PubnubSubscription.ts delete mode 100644 src/modules/Subscription/RingCentralExtensions.ts delete mode 100644 src/modules/Subscription/WebSocketReadyController.ts delete mode 100644 src/modules/Subscription/index.ts diff --git a/src/modules/Phone/index.js b/src/modules/Phone/index.js index 2acd44b8e..9752a127a 100644 --- a/src/modules/Phone/index.js +++ b/src/modules/Phone/index.js @@ -107,8 +107,9 @@ import { VideoConfiguration, } from '@ringcentral-integration/commons/modules/VideoConfiguration'; import { - WebSocketSubscription, + WebSocketSubscription as Subscription, } from '@ringcentral-integration/commons/modules/WebSocketSubscription'; +import { RingCentralExtensions } from '@ringcentral-integration/commons/modules/RingCentralExtensions'; import { ActiveCallsUI, } from '@ringcentral-integration/widgets/modules/ActiveCallsUI'; @@ -211,15 +212,6 @@ import { RcVideo } from '../RcVideo'; import { RingtoneSettingsUI } from '../RingtoneSettingsUI'; import { SettingsUI } from '../SettingsUI'; import { Storage } from '../Storage'; -import { - GenericSubscription as Subscription, -} from '../Subscription'; // TODO: wsg subscription -import { PubnubReadyController } from '../Subscription/PubnubReadyController'; -import { PubnubSubscription } from '../Subscription/PubnubSubscription'; -import { RingCentralExtensions } from '../Subscription/RingCentralExtensions'; -import { - WebSocketReadyController, -} from '../Subscription/WebSocketReadyController'; import { TabManager } from '../TabManager'; import ThirdPartyService from '../ThirdPartyService'; import { ThirdPartySettingSectionUI } from '../ThirdPartySettingSectionUI'; @@ -273,10 +265,6 @@ import { SideDrawerUI } from '../SideDrawerUI'; { provide: 'ContactMatcher', useClass: ContactMatcher }, { provide: 'Subscription', useClass: Subscription }, { provide: 'RingCentralExtensions', useClass: RingCentralExtensions }, - { provide: 'PubnubReadyController', useClass: PubnubReadyController }, - { provide: 'WebSocketReadyController', useClass: WebSocketReadyController }, - { provide: 'PubnubSubscription', useClass: PubnubSubscription }, - { provide: 'WebSocketSubscription', useClass: WebSocketSubscription }, { provide: 'RegionSettings', useClass: RegionSettings }, { provide: 'NumberValidate', useClass: NumberValidate }, { provide: 'NoiseReduction', useClass: NoiseReduction }, diff --git a/src/modules/Subscription/PubnubReadyController.ts b/src/modules/Subscription/PubnubReadyController.ts deleted file mode 100644 index 433d26ab2..000000000 --- a/src/modules/Subscription/PubnubReadyController.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Module } from '@ringcentral-integration/commons/lib/di'; - -import { - RcModuleV2, - state, - action, -} from '@ringcentral-integration/core'; - -@Module({ - name: 'PubnubReadyController', - deps: [], -}) -export class PubnubReadyController extends RcModuleV2 { - constructor(deps) { - super({ - deps, - }); - } - - @state - isReady: boolean = false; - - get ready() { - return this.isReady; - } - - @action - _setReady(ready: boolean) { - this.isReady = ready; - } - - setReady() { - this._setReady(true); - } -} diff --git a/src/modules/Subscription/PubnubSubscription.ts b/src/modules/Subscription/PubnubSubscription.ts deleted file mode 100644 index ed4f640b2..000000000 --- a/src/modules/Subscription/PubnubSubscription.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { Subscription as SubscriptionBase } from '@ringcentral-integration/commons/modules/Subscription'; -import { Module } from '@ringcentral-integration/commons/lib/di'; -import { debounce } from '@ringcentral-integration/commons/lib/debounce-throttle'; -import { isFirefox } from '../../lib/isFirefox'; - -const SUBSCRIPTION_LOCK_KEY = 'subscription-creating-lock'; - -@Module({ - name: 'Subscription', - deps: ['PubnubReadyController'], -}) -export class PubnubSubscription extends SubscriptionBase { - constructor(deps) { - super(deps); - - this._createSubscriptionWithLock = debounce({ - fn: this._createSubscriptionWithLockWithDebounced, - threshold: 2000, - maxThreshold: 2000, - }); - this._retry = debounce({ - fn: this._createSubscriptionWithLockWithDebounced, - threshold: this._timeToRetry, - maxThreshold: this._timeToRetry, - }); - } - - async _createSubscription() { - await super._createSubscription(); - if (!navigator.locks || isFirefox() || !this._subscription) { - return; - } - if (this._subscription._$$automaticRenewHandler) { - return; - } - // add lock renewal - this._subscription._$$automaticRenewHandler = this._subscription._automaticRenewHandler; - this._subscription._automaticRenewHandler = () => { - return navigator.locks.request('subscription_auto_renew', { mode: 'exclusive'}, async () => { - const result = await this._subscription._$$automaticRenewHandler(); - return result; - }); - }; - this._subscription._$$resubscribeAtPubNub = this._subscription.resubscribeAtPubNub; - this._subscription.resubscribeAtPubNub = () => { - return navigator.locks.request('subscription_resubscribe_pubnub', { mode: 'exclusive'}, async () => { - const result = await this._subscription._$$resubscribeAtPubNub(); - return result; - }); - }; - } - - // TODO: remove this after sdk fixed, fix lock issue at firefox and long delay issue - async _createSubscriptionWithLockWithDebounced() { - if (!navigator?.locks?.request || isFirefox()) { - await this._createSubscription(); - } else { - await navigator.locks.request(SUBSCRIPTION_LOCK_KEY, () => this._createSubscription()); - } - } - - get _registerDelay() { - return 0; // no need to wait for register as we will wait for lock - } -} diff --git a/src/modules/Subscription/RingCentralExtensions.ts b/src/modules/Subscription/RingCentralExtensions.ts deleted file mode 100644 index c594b5aff..000000000 --- a/src/modules/Subscription/RingCentralExtensions.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { RingCentralExtensions as RingCentralExtensionsBase } from '@ringcentral-integration/commons/modules/RingCentralExtensions'; -import { Module } from '@ringcentral-integration/commons/lib/di'; - -@Module({ - name: 'NewRingCentralExtensions', - deps: ['WebSocketReadyController'], -}) -export class RingCentralExtensions extends RingCentralExtensionsBase { - // ... -} \ No newline at end of file diff --git a/src/modules/Subscription/WebSocketReadyController.ts b/src/modules/Subscription/WebSocketReadyController.ts deleted file mode 100644 index d27325dd7..000000000 --- a/src/modules/Subscription/WebSocketReadyController.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { Module } from '@ringcentral-integration/commons/lib/di'; - -import { - RcModuleV2, - state, - action, -} from '@ringcentral-integration/core'; - -@Module({ - name: 'WebSocketReadyController', - deps: [], -}) -export class WebSocketReadyController extends RcModuleV2 { - constructor(deps) { - super({ - deps, - }); - } - - @state - isReady: boolean = false; - - get ready() { - return this.isReady; - } - - @action - _setReady(ready: boolean) { - this.isReady = ready; - } - - setReady() { - this._setReady(true); - } -} diff --git a/src/modules/Subscription/index.ts b/src/modules/Subscription/index.ts deleted file mode 100644 index 24db59b83..000000000 --- a/src/modules/Subscription/index.ts +++ /dev/null @@ -1,164 +0,0 @@ -import { Module } from '@ringcentral-integration/commons/lib/di'; - -import { - RcModuleV2, - state, - action, - watch, -} from '@ringcentral-integration/core'; -import type { MessageBase } from '@ringcentral-integration/commons/modules/Subscription/Subscription.interface'; - -@Module({ - name: 'GenericSubscription', - deps: [ - 'Auth', - 'WebSocketReadyController', - 'PubnubReadyController', - 'PubnubSubscription', - 'WebSocketSubscription', - ], -}) -export class GenericSubscription extends RcModuleV2 { - constructor(deps) { - super({ - deps, - }); - this._ignoreModuleReadiness(deps.webSocketReadyController); - this._ignoreModuleReadiness(deps.pubnubReadyController); - this._ignoreModuleReadiness(deps.pubnubSubscription); - this._ignoreModuleReadiness(deps.webSocketSubscription); - } - - onInitOnce() { - const appScope = this._deps.auth.token?.scope ?? ''; - if (appScope.indexOf('SubscriptionWebSocket') > -1) { - this._deps.webSocketReadyController.setReady(); - this.setType('WebSocket'); - watch( - this, - () => this._deps.webSocketSubscription.message, - (message) => { - this.setMessage(message); - }, - ); - } else { - this._deps.pubnubReadyController.setReady(); - this.setType('Pubnub'); - watch( - this, - () => this._deps.pubnubSubscription.message, - (message) => { - this.setMessage(message); - }, - ); - console.warn('PubnubSubscription is deprecated, please use WebSocketsSubscription instead.'); - } - } - - override _shouldInit() { - return super._shouldInit() && this._deps.auth.loggedIn; - } - - @state - message: MessageBase = null; - - @state - type = null; - - get ready() { - if (!this.type) { - return false; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.ready; - } - return this._deps.pubnubSubscription.ready; - } - - @action - setType(type: string) { - this.type = type; - } - - @action - setMessage(message: MessageBase) { - this.message = message; - } - - async subscribe(events = []) { - if (!this.type) { - return; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.subscribe(events); - } - return this._deps.pubnubSubscription.subscribe(events); - } - - async unsubscribe(events = []) { - if (!this.type) { - return; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.unsubscribe(events); - } - return this._deps.pubnubSubscription.unsubscribe(events); - } - - get filters() { - if (!this.type) { - return []; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.filters; - } - return this._deps.pubnubSubscription.filters; - } - - get onlyOneTabConnected() { - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.onlyOneTabConnected; - } - return false - } - - get subscriptionStatus() { - if (!this.type) { - return null; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.subscriptionStatus; - } - return this._deps.pubnubSubscription.subscriptionStatus; - } - - get cachedSubscription() { - if (!this.type) { - return null; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.cachedSubscription; - } - return this._deps.pubnubSubscription.cachedSubscription; - } - - get subscriptionInfo() { - if (!this.type) { - return null; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.subscriptionInfo; - } - return this._deps.pubnubSubscription.subscriptionInfo; - } - - get subscriptionChannel() { - if (!this.type) { - return null; - } - if (this.type === 'WebSocket') { - return this._deps.webSocketSubscription.subscriptionChannel; - } - return this._deps.pubnubSubscription.subscriptionChannel; - } -} \ No newline at end of file