Skip to content

Commit 6519c27

Browse files
committed
Fix TS errors
1 parent 3636ae6 commit 6519c27

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/features/click-to-load.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ export default class ClickToLoad extends ContentFeature {
17191719
if (!this.messaging) {
17201720
throw new Error('Cannot operate click to load without a messaging backend')
17211721
}
1722-
_messagingModuleScope = this._messaging
1722+
_messagingModuleScope = this.messaging
17231723

17241724
const websiteOwner = args?.site?.parentEntity
17251725
const settings = args?.featureSettings?.clickToLoad || {}
@@ -1839,6 +1839,10 @@ export default class ClickToLoad extends ContentFeature {
18391839
const messageType = message?.messageType
18401840
if (!messageType) return
18411841

1842+
if (!this._clickToLoadMessagingTransport) {
1843+
throw new Error('_clickToLoadMessagingTransport not ready. Cannot operate click to load without a messaging backend')
1844+
}
1845+
18421846
// Send to Messaging layer the response or subscription message received
18431847
// from the Platform.
18441848
return this._clickToLoadMessagingTransport.onResponse(message)
@@ -1864,11 +1868,11 @@ export default class ClickToLoad extends ContentFeature {
18641868
if (this._messaging) return this._messaging
18651869

18661870
if (this.platform.name === 'android' || this.platform.name === 'extension' || this.platform.name === 'macos') {
1867-
this._clickToLoadMessagingTransport = new ClickToLoadMessagingTransport()
1871+
this._clickToLoadMessagingTransport = new ClickToLoadMessagingTransport(this.messagingContext)
18681872
const config = new TestTransportConfig(this._clickToLoadMessagingTransport)
18691873
this._messaging = new Messaging(this.messagingContext, config)
18701874
return this._messaging
1871-
} else if (this.platform.name === 'macos' || this.platform.name === 'ios') {
1875+
} else if (this.platform.name === 'ios') {
18721876
const config = new WebkitMessagingConfig({
18731877
secret: '',
18741878
hasModernWebkitAPI: true,

src/features/click-to-load/ctl-messaging-transport.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { sendMessage } from '../../utils'
22

3+
/** Workaround defining MessagingTransport locally because "import()" is not working in @implements
4+
* @typedef {import('@duckduckgo/messaging').MessagingTransport} MessagingTransport */
5+
36
/**
47
* A temporary implementation of {@link MessagingTransport} to communicate with Android and Extension.
58
* It wraps the current messaging system that calls `sendMessage`
69
*
7-
* @implements {import("@duckduckgo/messaging").MessagingTransport}
10+
* @implements {MessagingTransport}
811
* @deprecated - Use this only to communicate with Android and the Extension while support to {@link Messaging}
912
* is not ready and we need to use `sendMessage()`.
1013
*/
@@ -16,11 +19,10 @@ export class ClickToLoadMessagingTransport {
1619
_queue = new Set()
1720

1821
/**
19-
* @param {TestTransportConfig} config
20-
* @param {import("@duckduckgo/messaging").MessagingContext} messagingContext
22+
* @param {import('@duckduckgo/messaging').MessagingContext} messagingContext
2123
* @internal
2224
*/
23-
constructor (config, messagingContext) {
25+
constructor (messagingContext) {
2426
this.messagingContext = messagingContext
2527
this.globals = {
2628
window,
@@ -42,14 +44,14 @@ export class ClickToLoadMessagingTransport {
4244
}
4345

4446
/**
45-
* @param {import("@duckduckgo/messaging").NotificationMessage} msg
47+
* @param {import('@duckduckgo/messaging').NotificationMessage} msg
4648
*/
4749
notify (msg) {
4850
sendMessage(msg.method, msg.params)
4951
}
5052

5153
/**
52-
* @param {import("@duckduckgo/messaging").RequestMessage} msg
54+
* @param {import('@duckduckgo/messaging').RequestMessage} req
5355
* @return {Promise<any>}
5456
*/
5557
request (req) {
@@ -70,19 +72,19 @@ export class ClickToLoadMessagingTransport {
7072
eventData.response.videoURL === req.params?.videoURL
7173
)
7274
}
73-
params = req.params.videoURL
75+
params = req.params?.videoURL
7476
break
7577
}
7678
// Unwrap 'updateYouTubeCTLAddedFlag' params to match expected payload
7779
// for sendMessage()
7880
case 'updateYouTubeCTLAddedFlag': {
79-
params = req.params.youTubeCTLAddedFlag
81+
params = req.params?.youTubeCTLAddedFlag
8082
break
8183
}
8284
// Unwrap 'setYoutubePreviewsEnabled' params to match expected payload
8385
// for sendMessage()
8486
case 'setYoutubePreviewsEnabled': {
85-
params = req.params.youtubePreviewsEnabled
87+
params = req.params?.youtubePreviewsEnabled
8688
break
8789
}
8890
}
@@ -99,7 +101,7 @@ export class ClickToLoadMessagingTransport {
99101
}
100102

101103
/**
102-
* @param {import("@duckduckgo/messaging").Subscription} msg
104+
* @param {import('@duckduckgo/messaging').Subscription} msg
103105
* @param {(value: unknown | undefined) => void} callback
104106
*/
105107
subscribe (msg, callback) {

0 commit comments

Comments
 (0)