@encorekit/react-native 1.1.30 → 1.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -21
- package/lib/commonjs/index.js +38 -6
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +38 -6
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +50 -7
package/README.md
CHANGED
|
@@ -60,34 +60,26 @@ const result = await Encore.show('paywall');
|
|
|
60
60
|
|
|
61
61
|
### 4. Handle Callbacks
|
|
62
62
|
|
|
63
|
+
> **Setter semantics.** `onPurchaseRequest`, `onPurchaseComplete`, and `onPassthrough` each **replace** the previous handler when called again (matching iOS, Android, and Flutter). They are global singleton handlers, not multi-listener subscriptions. No manual cleanup is required — re-registration is safe and idempotent.
|
|
64
|
+
|
|
63
65
|
```tsx
|
|
64
|
-
//
|
|
65
|
-
Encore.onPurchaseRequest(async ({
|
|
66
|
+
// Register once, e.g. right after configure or at app startup
|
|
67
|
+
Encore.onPurchaseRequest(async ({ productId, placementId }) => {
|
|
66
68
|
try {
|
|
67
69
|
await RevenueCat.purchase(productId);
|
|
68
|
-
await Encore.completePurchaseRequest(
|
|
70
|
+
await Encore.completePurchaseRequest(true);
|
|
69
71
|
} catch {
|
|
70
|
-
await Encore.completePurchaseRequest(
|
|
72
|
+
await Encore.completePurchaseRequest(false);
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
|
|
74
|
-
// Passthrough — user dismissed without purchasing
|
|
75
|
-
Encore.onPassthrough(({ placementId }) => {
|
|
76
|
-
// Resume your original flow
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Purchase complete (fire-and-forget, for syncing with backends)
|
|
80
76
|
Encore.onPurchaseComplete(({ productId, transactionId }) => {
|
|
81
|
-
|
|
77
|
+
// Optional: sync with backends that don't auto-detect StoreKit/Play Billing
|
|
82
78
|
});
|
|
83
|
-
```
|
|
84
79
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const unsubscribe = Encore.onPassthrough(handler);
|
|
89
|
-
// Later:
|
|
90
|
-
unsubscribe();
|
|
80
|
+
Encore.onPassthrough(({ placementId }) => {
|
|
81
|
+
// User dismissed without purchasing — resume your original flow
|
|
82
|
+
});
|
|
91
83
|
```
|
|
92
84
|
|
|
93
85
|
## API Reference
|
|
@@ -121,13 +113,13 @@ Present a native offer sheet. Returns `PlacementResult`.
|
|
|
121
113
|
|
|
122
114
|
Register native event handlers (purchase request, purchase complete, passthrough). Called automatically by `EncoreProvider`.
|
|
123
115
|
|
|
124
|
-
### `completePurchaseRequest(
|
|
116
|
+
### `completePurchaseRequest(success)`
|
|
125
117
|
|
|
126
|
-
Signal completion of a purchase request initiated via `onPurchaseRequest`.
|
|
118
|
+
Signal completion of a purchase request initiated via `onPurchaseRequest`. Pass `true` on successful purchase, `false` on failure/cancellation.
|
|
127
119
|
|
|
128
120
|
### `onPurchaseRequest(handler)`
|
|
129
121
|
|
|
130
|
-
|
|
122
|
+
Register a handler for purchase request events (setter semantics — replaces any previous handler). Your handler receives `{ productId, placementId?, promoOfferId? }` and should call `completePurchaseRequest` when done. Returns an unsubscribe function.
|
|
131
123
|
|
|
132
124
|
### `onPurchaseComplete(handler)`
|
|
133
125
|
|
package/lib/commonjs/index.js
CHANGED
|
@@ -29,6 +29,14 @@ if (!EncoreReactSDK) {
|
|
|
29
29
|
throw new Error(`EncoreReactSDK native module not found. Ensure the native ${_reactNative.Platform.OS} SDK is properly linked.`);
|
|
30
30
|
}
|
|
31
31
|
const encoreEmitter = new _reactNative.NativeEventEmitter(EncoreReactSDK);
|
|
32
|
+
|
|
33
|
+
// Setter semantics: each on*() call replaces the previous handler instead of
|
|
34
|
+
// appending. This matches Swift / Android / Flutter parity. Without this, repeat
|
|
35
|
+
// registrations (e.g. hot reload, re-renders without cleanup) would accumulate
|
|
36
|
+
// listeners and cause N duplicate purchase attempts per event.
|
|
37
|
+
let currentPurchaseRequestSubscription = null;
|
|
38
|
+
let currentPurchaseCompleteSubscription = null;
|
|
39
|
+
let currentPassthroughSubscription = null;
|
|
32
40
|
async function safeBridgeCall(method, call, fallback) {
|
|
33
41
|
try {
|
|
34
42
|
return await call();
|
|
@@ -79,16 +87,40 @@ const Encore = {
|
|
|
79
87
|
success: false
|
|
80
88
|
}),
|
|
81
89
|
onPurchaseRequest: handler => {
|
|
82
|
-
|
|
83
|
-
|
|
90
|
+
var _currentPurchaseReque;
|
|
91
|
+
(_currentPurchaseReque = currentPurchaseRequestSubscription) === null || _currentPurchaseReque === void 0 || _currentPurchaseReque.remove();
|
|
92
|
+
currentPurchaseRequestSubscription = encoreEmitter.addListener('onPurchaseRequest', handler);
|
|
93
|
+
const subscription = currentPurchaseRequestSubscription;
|
|
94
|
+
return () => {
|
|
95
|
+
subscription.remove();
|
|
96
|
+
if (currentPurchaseRequestSubscription === subscription) {
|
|
97
|
+
currentPurchaseRequestSubscription = null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
84
100
|
},
|
|
85
101
|
onPurchaseComplete: handler => {
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
var _currentPurchaseCompl;
|
|
103
|
+
(_currentPurchaseCompl = currentPurchaseCompleteSubscription) === null || _currentPurchaseCompl === void 0 || _currentPurchaseCompl.remove();
|
|
104
|
+
currentPurchaseCompleteSubscription = encoreEmitter.addListener('onPurchaseComplete', handler);
|
|
105
|
+
const subscription = currentPurchaseCompleteSubscription;
|
|
106
|
+
return () => {
|
|
107
|
+
subscription.remove();
|
|
108
|
+
if (currentPurchaseCompleteSubscription === subscription) {
|
|
109
|
+
currentPurchaseCompleteSubscription = null;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
88
112
|
},
|
|
89
113
|
onPassthrough: handler => {
|
|
90
|
-
|
|
91
|
-
|
|
114
|
+
var _currentPassthroughSu;
|
|
115
|
+
(_currentPassthroughSu = currentPassthroughSubscription) === null || _currentPassthroughSu === void 0 || _currentPassthroughSu.remove();
|
|
116
|
+
currentPassthroughSubscription = encoreEmitter.addListener('onPassthrough', handler);
|
|
117
|
+
const subscription = currentPassthroughSubscription;
|
|
118
|
+
return () => {
|
|
119
|
+
subscription.remove();
|
|
120
|
+
if (currentPassthroughSubscription === subscription) {
|
|
121
|
+
currentPassthroughSubscription = null;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
92
124
|
}
|
|
93
125
|
};
|
|
94
126
|
var _default = exports.default = Encore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_hooks","EncoreReactSDK","NativeModules","Error","Platform","OS","encoreEmitter","NativeEventEmitter","safeBridgeCall","method","call","fallback","error","console","warn","Encore","configure","apiKey","options","success","identify","userId","attributes","setUserAttributes","reset","placement","placementId","show","status","reason","placements","setClaimEnabled","enabled","registerCallbacks","completePurchaseRequest","onPurchaseRequest","handler","
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_hooks","EncoreReactSDK","NativeModules","Error","Platform","OS","encoreEmitter","NativeEventEmitter","currentPurchaseRequestSubscription","currentPurchaseCompleteSubscription","currentPassthroughSubscription","safeBridgeCall","method","call","fallback","error","console","warn","Encore","configure","apiKey","options","success","identify","userId","attributes","setUserAttributes","reset","placement","placementId","show","status","reason","placements","setClaimEnabled","enabled","registerCallbacks","completePurchaseRequest","onPurchaseRequest","handler","_currentPurchaseReque","remove","addListener","subscription","onPurchaseComplete","_currentPurchaseCompl","onPassthrough","_currentPassthroughSu","_default","exports","default"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;AAIA,IAAAA,YAAA,GAAAC,OAAA;AA6MA,IAAAC,MAAA,GAAAD,OAAA;AAjNA;AACA;AACA;;AASA,MAAM;EAAEE;AAAe,CAAC,GAAGC,0BAAa;AAExC,IAAI,CAACD,cAAc,EAAE;EACnB,MAAM,IAAIE,KAAK,CACb,6DAA6DC,qBAAQ,CAACC,EAAE,0BAC1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IACF,CAAC;EACH,CAAC;EAEDoC,kBAAkB,EAAGL,OAAO,IAAK;IAAA,IAAAM,qBAAA;IAC/B,CAAAA,qBAAA,GAAApC,mCAAmC,cAAAoC,qBAAA,eAAnCA,qBAAA,CAAqCJ,MAAM,CAAC,CAAC;IAC7ChC,mCAAmC,GAAGH,aAAa,CAACoC,WAAW,CAC7D,oBAAoB,EACpBH,OACF,CAAC;IACD,MAAMI,YAAY,GAAGlC,mCAAmC;IACxD,OAAO,MAAM;MACXkC,YAAY,CAACF,MAAM,CAAC,CAAC;MACrB,IAAIhC,mCAAmC,KAAKkC,YAAY,EAAE;QACxDlC,mCAAmC,GAAG,IAAI;MAC5C;IACF,CAAC;EACH,CAAC;EAEDqC,aAAa,EAAGP,OAAO,IAAK;IAAA,IAAAQ,qBAAA;IAC1B,CAAAA,qBAAA,GAAArC,8BAA8B,cAAAqC,qBAAA,eAA9BA,qBAAA,CAAgCN,MAAM,CAAC,CAAC;IACxC/B,8BAA8B,GAAGJ,aAAa,CAACoC,WAAW,CACxD,eAAe,EACfH,OACF,CAAC;IACD,MAAMI,YAAY,GAAGjC,8BAA8B;IACnD,OAAO,MAAM;MACXiC,YAAY,CAACF,MAAM,CAAC,CAAC;MACrB,IAAI/B,8BAA8B,KAAKiC,YAAY,EAAE;QACnDjC,8BAA8B,GAAG,IAAI;MACvC;IACF,CAAC;EACH;AACF,CAAC;AAAC,IAAAsC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEahC,MAAM","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -10,6 +10,14 @@ if (!EncoreReactSDK) {
|
|
|
10
10
|
throw new Error(`EncoreReactSDK native module not found. Ensure the native ${Platform.OS} SDK is properly linked.`);
|
|
11
11
|
}
|
|
12
12
|
const encoreEmitter = new NativeEventEmitter(EncoreReactSDK);
|
|
13
|
+
|
|
14
|
+
// Setter semantics: each on*() call replaces the previous handler instead of
|
|
15
|
+
// appending. This matches Swift / Android / Flutter parity. Without this, repeat
|
|
16
|
+
// registrations (e.g. hot reload, re-renders without cleanup) would accumulate
|
|
17
|
+
// listeners and cause N duplicate purchase attempts per event.
|
|
18
|
+
let currentPurchaseRequestSubscription = null;
|
|
19
|
+
let currentPurchaseCompleteSubscription = null;
|
|
20
|
+
let currentPassthroughSubscription = null;
|
|
13
21
|
async function safeBridgeCall(method, call, fallback) {
|
|
14
22
|
try {
|
|
15
23
|
return await call();
|
|
@@ -60,16 +68,40 @@ const Encore = {
|
|
|
60
68
|
success: false
|
|
61
69
|
}),
|
|
62
70
|
onPurchaseRequest: handler => {
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
var _currentPurchaseReque;
|
|
72
|
+
(_currentPurchaseReque = currentPurchaseRequestSubscription) === null || _currentPurchaseReque === void 0 || _currentPurchaseReque.remove();
|
|
73
|
+
currentPurchaseRequestSubscription = encoreEmitter.addListener('onPurchaseRequest', handler);
|
|
74
|
+
const subscription = currentPurchaseRequestSubscription;
|
|
75
|
+
return () => {
|
|
76
|
+
subscription.remove();
|
|
77
|
+
if (currentPurchaseRequestSubscription === subscription) {
|
|
78
|
+
currentPurchaseRequestSubscription = null;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
65
81
|
},
|
|
66
82
|
onPurchaseComplete: handler => {
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
var _currentPurchaseCompl;
|
|
84
|
+
(_currentPurchaseCompl = currentPurchaseCompleteSubscription) === null || _currentPurchaseCompl === void 0 || _currentPurchaseCompl.remove();
|
|
85
|
+
currentPurchaseCompleteSubscription = encoreEmitter.addListener('onPurchaseComplete', handler);
|
|
86
|
+
const subscription = currentPurchaseCompleteSubscription;
|
|
87
|
+
return () => {
|
|
88
|
+
subscription.remove();
|
|
89
|
+
if (currentPurchaseCompleteSubscription === subscription) {
|
|
90
|
+
currentPurchaseCompleteSubscription = null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
69
93
|
},
|
|
70
94
|
onPassthrough: handler => {
|
|
71
|
-
|
|
72
|
-
|
|
95
|
+
var _currentPassthroughSu;
|
|
96
|
+
(_currentPassthroughSu = currentPassthroughSubscription) === null || _currentPassthroughSu === void 0 || _currentPassthroughSu.remove();
|
|
97
|
+
currentPassthroughSubscription = encoreEmitter.addListener('onPassthrough', handler);
|
|
98
|
+
const subscription = currentPassthroughSubscription;
|
|
99
|
+
return () => {
|
|
100
|
+
subscription.remove();
|
|
101
|
+
if (currentPassthroughSubscription === subscription) {
|
|
102
|
+
currentPassthroughSubscription = null;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
73
105
|
}
|
|
74
106
|
};
|
|
75
107
|
export default Encore;
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","NativeEventEmitter","Platform","EncoreReactSDK","Error","OS","encoreEmitter","safeBridgeCall","method","call","fallback","error","console","warn","Encore","configure","apiKey","options","success","identify","userId","attributes","setUserAttributes","reset","placement","placementId","show","status","reason","placements","setClaimEnabled","enabled","registerCallbacks","completePurchaseRequest","onPurchaseRequest","handler","
|
|
1
|
+
{"version":3,"names":["NativeModules","NativeEventEmitter","Platform","EncoreReactSDK","Error","OS","encoreEmitter","currentPurchaseRequestSubscription","currentPurchaseCompleteSubscription","currentPassthroughSubscription","safeBridgeCall","method","call","fallback","error","console","warn","Encore","configure","apiKey","options","success","identify","userId","attributes","setUserAttributes","reset","placement","placementId","show","status","reason","placements","setClaimEnabled","enabled","registerCallbacks","completePurchaseRequest","onPurchaseRequest","handler","_currentPurchaseReque","remove","addListener","subscription","onPurchaseComplete","_currentPurchaseCompl","onPassthrough","_currentPassthroughSu","EncoreProvider","useEncoreContext"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA;AACA;;AAEA,SACEA,aAAa,EACbC,kBAAkB,EAClBC,QAAQ,QAEH,cAAc;AAErB,MAAM;EAAEC;AAAe,CAAC,GAAGH,aAAa;AAExC,IAAI,CAACG,cAAc,EAAE;EACnB,MAAM,IAAIC,KA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AAE;QACvDnC,kCAAkC,GAAG,IAAI;MAC3C;IACF,CAAC;EACH,CAAC;EAEDoC,kBAAkB,EAAGL,OAAO,IAAK;IAAA,IAAAM,qBAAA;IAC/B,CAAAA,qBAAA,GAAApC,mCAAmC,cAAAoC,qBAAA,eAAnCA,qBAAA,CAAqCJ,MAAM,CAAC,CAAC;IAC7ChC,mCAAmC,GAAGF,aAAa,CAACmC,WAAW,CAC7D,oBAAoB,EACpBH,OACF,CAAC;IACD,MAAMI,YAAY,GAAGlC,mCAAmC;IACxD,OAAO,MAAM;MACXkC,YAAY,CAACF,MAAM,CAAC,CAAC;MACrB,IAAIhC,mCAAmC,KAAKkC,YAAY,EAAE;QACxDlC,mCAAmC,GAAG,IAAI;MAC5C;IACF,CAAC;EACH,CAAC;EAEDqC,aAAa,EAAGP,OAAO,IAAK;IAAA,IAAAQ,qBAAA;IAC1B,CAAAA,qBAAA,GAAArC,8BAA8B,cAAAqC,qBAAA,eAA9BA,qBAAA,CAAgCN,MAAM,CAAC,CAAC;IACxC/B,8BAA8B,GAAGH,aAAa,CAACmC,WAAW,CACxD,eAAe,EACfH,OACF,CAAC;IACD,MAAMI,YAAY,GAAGjC,8BAA8B;IACnD,OAAO,MAAM;MACXiC,YAAY,CAACF,MAAM,CAAC,CAAC;MACrB,IAAI/B,8BAA8B,KAAKiC,YAAY,EAAE;QACnDjC,8BAA8B,GAAG,IAAI;MACvC;IACF,CAAC;EACH;AACF,CAAC;AAED,eAAeQ,MAAM;AACrB,SAAS8B,cAAc,EAAEC,gBAAgB,QAAQ,SAAS","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AA4CA,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAA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C;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACzE,iBAAiB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAC9E,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,qBAAqB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChF,aAAa,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACvE;AAID,QAAA,MAAM,MAAM,EAAE,SAkFb,CAAC;AAEF,eAAe,MAAM,CAAC;AACtB,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
// Bridge-only layer — delegates to native SDKs on each platform.
|
|
3
3
|
// iOS: encore-swift-sdk | Android: encore-android-sdk
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
NativeModules,
|
|
7
|
+
NativeEventEmitter,
|
|
8
|
+
Platform,
|
|
9
|
+
type EmitterSubscription,
|
|
10
|
+
} from 'react-native';
|
|
6
11
|
|
|
7
12
|
const { EncoreReactSDK } = NativeModules;
|
|
8
13
|
|
|
@@ -14,6 +19,14 @@ if (!EncoreReactSDK) {
|
|
|
14
19
|
|
|
15
20
|
const encoreEmitter = new NativeEventEmitter(EncoreReactSDK);
|
|
16
21
|
|
|
22
|
+
// Setter semantics: each on*() call replaces the previous handler instead of
|
|
23
|
+
// appending. This matches Swift / Android / Flutter parity. Without this, repeat
|
|
24
|
+
// registrations (e.g. hot reload, re-renders without cleanup) would accumulate
|
|
25
|
+
// listeners and cause N duplicate purchase attempts per event.
|
|
26
|
+
let currentPurchaseRequestSubscription: EmitterSubscription | null = null;
|
|
27
|
+
let currentPurchaseCompleteSubscription: EmitterSubscription | null = null;
|
|
28
|
+
let currentPassthroughSubscription: EmitterSubscription | null = null;
|
|
29
|
+
|
|
17
30
|
async function safeBridgeCall<T>(
|
|
18
31
|
method: string,
|
|
19
32
|
call: () => Promise<T>,
|
|
@@ -148,18 +161,48 @@ const Encore: EncoreSDK = {
|
|
|
148
161
|
safeBridgeCall('completePurchaseRequest', () => EncoreReactSDK.completePurchaseRequest(success), { success: false }),
|
|
149
162
|
|
|
150
163
|
onPurchaseRequest: (handler) => {
|
|
151
|
-
|
|
152
|
-
|
|
164
|
+
currentPurchaseRequestSubscription?.remove();
|
|
165
|
+
currentPurchaseRequestSubscription = encoreEmitter.addListener(
|
|
166
|
+
'onPurchaseRequest',
|
|
167
|
+
handler,
|
|
168
|
+
);
|
|
169
|
+
const subscription = currentPurchaseRequestSubscription;
|
|
170
|
+
return () => {
|
|
171
|
+
subscription.remove();
|
|
172
|
+
if (currentPurchaseRequestSubscription === subscription) {
|
|
173
|
+
currentPurchaseRequestSubscription = null;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
153
176
|
},
|
|
154
177
|
|
|
155
178
|
onPurchaseComplete: (handler) => {
|
|
156
|
-
|
|
157
|
-
|
|
179
|
+
currentPurchaseCompleteSubscription?.remove();
|
|
180
|
+
currentPurchaseCompleteSubscription = encoreEmitter.addListener(
|
|
181
|
+
'onPurchaseComplete',
|
|
182
|
+
handler,
|
|
183
|
+
);
|
|
184
|
+
const subscription = currentPurchaseCompleteSubscription;
|
|
185
|
+
return () => {
|
|
186
|
+
subscription.remove();
|
|
187
|
+
if (currentPurchaseCompleteSubscription === subscription) {
|
|
188
|
+
currentPurchaseCompleteSubscription = null;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
158
191
|
},
|
|
159
192
|
|
|
160
193
|
onPassthrough: (handler) => {
|
|
161
|
-
|
|
162
|
-
|
|
194
|
+
currentPassthroughSubscription?.remove();
|
|
195
|
+
currentPassthroughSubscription = encoreEmitter.addListener(
|
|
196
|
+
'onPassthrough',
|
|
197
|
+
handler,
|
|
198
|
+
);
|
|
199
|
+
const subscription = currentPassthroughSubscription;
|
|
200
|
+
return () => {
|
|
201
|
+
subscription.remove();
|
|
202
|
+
if (currentPassthroughSubscription === subscription) {
|
|
203
|
+
currentPassthroughSubscription = null;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
163
206
|
},
|
|
164
207
|
};
|
|
165
208
|
|