Skip to content

Commit 879d829

Browse files
author
Shane Osbourne
committed
some debugging for subscriptions
1 parent d13a2da commit 879d829

File tree

8 files changed

+43
-12
lines changed

8 files changed

+43
-12
lines changed

packages/messaging/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ export class Subscription {
253253
}
254254
}
255255

256+
/**
257+
* This is the shape of payloads that can be delivered via subscriptions
258+
*/
256259
export class SubscriptionEvent {
257260
/**
258261
* @param {object} params

packages/messaging/lib/test-utils.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ export function simulateSubscriptionMessage(params) {
163163
break;
164164
}
165165
case "apple": {
166-
const methodName = 'webkitSubscriptionHandler' + params.messagingContext.context;
166+
const methodName = 'webkitSubscriptionHandler_' + params.messagingContext.context;
167+
if (!window[methodName]) throw new Error('cannot access webkit subscription handler');
167168
window[methodName].call(null, {
168169
context: params.messagingContext.context,
169170
featureName: params.messagingContext.featureName,

packages/messaging/lib/webkit.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,16 @@ export class WebkitMessagingTransport {
301301
* window.webkitSubscriptionHandlerContentScopeScripts({
302302
* content: "contentScopeScripts",
303303
* featureName: "duckPlayerOverlays",
304-
* subscriptionName: "userValuesSubscription",
304+
* subscriptionName: "onUserValuesChanged",
305305
* params: {...}
306306
* })
307307
* ```
308308
*/
309309
installGlobalSubscriptionHandler () {
310-
const methodName = 'webkitSubscriptionHandler' + this.messagingContext.context;
310+
const methodName = 'webkitSubscriptionHandler_' + this.messagingContext.context;
311+
// console.log("SUB", {methodName})
311312
window[methodName] = (payload) => {
313+
// console.log('debug: webkit received subscription method', methodName);
312314
if ('context' in payload && 'featureName' in payload && 'subscriptionName' in payload) {
313315
for (let subscriptionHandler of this.subscriptionHandlers) {
314316
if (subscriptionHandler.comparator(payload)) {

packages/special-pages/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'development')
2525

2626
export const support = {
2727
duckplayer: {
28-
// 'apple': ['copy', 'build-js', 'inline'],
28+
'apple': ['copy', 'build-js', 'inline'],
2929
'windows': ['copy', 'build-js']
3030
},
3131
}

packages/special-pages/pages/duckplayer/src/js/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* #### Messages:
2424
*
2525
* On Page Load
26-
* - {@link DuckPlayerPageMessages.userValuesSubscription} begins immediately. It expects an initial value, and then will continue to listen for updates
26+
* - {@link DuckPlayerPageMessages.onUserValuesChanged} begins immediately. It expects an initial value, and then will continue to listen for updates
2727
*
2828
* Then the following 2 messages can be sent at any time
2929
* - {@link DuckPlayerPageMessages.setUserValues}
@@ -345,7 +345,7 @@ const Comms = {
345345
const messaging = new Messaging(messageContext, opts)
346346
Comms.messaging = new DuckPlayerPageMessages(messaging)
347347
}
348-
Comms.messaging?.userValuesSubscription(value => {
348+
Comms.messaging?.onUserValuesChanged(value => {
349349
if ('enabled' in value.privatePlayerMode) {
350350
Setting.setState(true)
351351
} else {

packages/special-pages/pages/duckplayer/src/js/messages.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,33 @@ export class DuckPlayerPageMessages {
3838
}
3939

4040
/**
41-
* Send this when you want to communicate a change to 'UserValues'
41+
* This is a subscription that we set up when the page loads.
42+
* We use this value to show/hide the checkboxes.
43+
*
44+
* **Integration NOTE**: Native platforms should always send this at least once on initial page load.
45+
*
46+
* - See {@link Messaging.SubscriptionEvent} for details on each value of this message
47+
* - See {@link UserValues} for details on the `params`
48+
*
49+
* ```json
50+
* // the payload that we receive should look like this
51+
* {
52+
* "context": "specialPages",
53+
* "featureName": "duckPlayerPage",
54+
* "subscriptionName": "onUserValuesChanged",
55+
* "params": {
56+
* "overlayInteracted": false,
57+
* "privatePlayerMode": {
58+
* "enabled": {}
59+
* }
60+
* }
61+
* }
62+
* ```
4263
*
43-
* For example, on initial page load we use this value to show/hide the checkboxes
4464
* @param {(value: UserValues) => void} cb
4565
*/
46-
userValuesSubscription (cb) {
47-
return this.messaging.subscribe('userValuesSubscription', cb)
66+
onUserValuesChanged (cb) {
67+
return this.messaging.subscribe('onUserValuesChanged', cb)
4868
}
4969
}
5070

packages/special-pages/tests/page-objects/duck-player.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class DuckPlayerPage {
161161
* @return {Promise<void>}
162162
*/
163163
async didReceiveAlwaysOpenSetting (value) {
164-
await this.mocks.simulateSubscriptionMessage('userValuesSubscription', {
164+
await this.mocks.simulateSubscriptionMessage('onUserValuesChanged', {
165165
privatePlayerMode: {
166166
alwaysAsk: {}
167167
}

packages/special-pages/tests/page-objects/mocks.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export class Mocks {
4747
* @param {Record<string, any>} payload
4848
*/
4949
async simulateSubscriptionMessage (name, payload) {
50-
await this.page.evaluate(simulateSubscriptionMessage, { messagingContext: this.messagingContext, name, payload, platform: this.platform })
50+
await this.page.evaluate(simulateSubscriptionMessage, {
51+
messagingContext: this.messagingContext,
52+
name,
53+
payload,
54+
platform: this.platform
55+
})
5156
}
5257

5358
/**

0 commit comments

Comments
 (0)