-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
real-time-config-impl.js
720 lines (677 loc) · 22.6 KB
/
real-time-config-impl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
import {CONSENT_POLICY_STATE} from '#core/constants/consent-state';
import {isArray, isObject} from '#core/types';
import {tryParseJson} from '#core/types/object/json';
import {Services} from '#service';
import {dev, user, userAssert} from '#utils/log';
import {RTC_VENDORS} from './callout-vendors';
import {isCancellation} from '../../error-reporting';
import {getMode} from '../../mode';
import {registerServiceBuilderForDoc} from '../../service-helpers';
import {isAmpScriptUri} from '../../url';
/** @type {string} */
const TAG = 'real-time-config';
/** @type {number} */
const MAX_RTC_CALLOUTS = 5;
/** @type {number} */
const MAX_URL_LENGTH = 16384;
/** @typedef {{
urls: (undefined|Array<string>|
Array<{url:string, errorReportingUrl:string,
sendRegardlessOfConsentState:(undefined|boolean|Array<string>)}>),
vendors: (undefined|Object),
timeoutMillis: number,
errorReportingUrl: (undefined|string),
sendRegardlessOfConsentState: (undefined|boolean|Array<string>)
}} */
let RtcConfigDef;
/**
* Enum starts at 4 because 1-3 reserved as:
* 1 = custom remote.html in use.
* 2 = RTC succeeded.
* 3 = deprecated generic RTC failures.
* @enum {string}
*/
export const RTC_ERROR_ENUM = {
// Occurs when response is unparseable as JSON
MALFORMED_JSON_RESPONSE: '4',
// Occurs when a publisher has specified the same url
// or vendor url (after macros are substituted) to call out to more than once.
DUPLICATE_URL: '5',
// Occurs when a URL fails isSecureUrl check.
INSECURE_URL: '6',
// Occurs when 5 valid callout urls have already been built, and additional
// urls are still specified.
MAX_CALLOUTS_EXCEEDED: '7',
// Occurs due to XHR failure.
NETWORK_FAILURE: '8',
// Occurs when a specified vendor does not exist in RTC_VENDORS.
UNKNOWN_VENDOR: '9',
// Occurs when request took longer than timeout
TIMEOUT: '10',
// Occurs when URL expansion time exceeded allowed timeout, request never
// sent.
MACRO_EXPAND_TIMEOUT: '11',
};
/** @const {!{[key: string]: boolean}} */
const GLOBAL_MACRO_ALLOWLIST = {
CLIENT_ID: true,
TITLE: true,
SOURCE_URL: true,
};
export class RealTimeConfigService {
/**
* @param {!../ampdoc-impl.AmpDoc} ampDoc
*/
constructor(ampDoc) {
/** @protected {!../ampdoc-impl.AmpDoc} */
this.ampDoc_ = ampDoc;
}
/**
* For a given A4A Element, sends out Real Time Config requests to
* any urls or vendors specified by the publisher.
* @param {!Element} element
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} customMacros The ad-network specified macro
* substitutions available to use.
* @param {?CONSENT_POLICY_STATE} consentState
* @param {?string} consentString
* @param {?{[key: string]: string|number|boolean|undefined}} consentMetadata
* @param {!Function} checkStillCurrent
* @return {Promise<!Array<!rtcResponseDef>>|undefined}
* @visibleForTesting
*/
maybeExecuteRealTimeConfig(
element,
customMacros,
consentState,
consentString,
consentMetadata,
checkStillCurrent
) {
return new RealTimeConfigManager(this.ampDoc_).execute(
element,
customMacros,
consentState,
consentString,
consentMetadata,
checkStillCurrent
);
}
}
export class RealTimeConfigManager {
/**
* @param {!../ampdoc-impl.AmpDoc} ampDoc
*/
constructor(ampDoc) {
/** @protected {!../ampdoc-impl.AmpDoc} */
this.ampDoc_ = ampDoc;
/** @private {!Window} */
this.win_ = ampDoc.win;
/** @private {!{[key: string]: boolean}} */
this.seenUrls_ = {};
/** @private {?number} */
this.rtcStartTime_ = null;
/** @private {!Array<!Promise<!rtcResponseDef>>} */
this.promiseArray_ = [];
/** @private {?RtcConfigDef} */
this.rtcConfig_ = null;
/** @private {?CONSENT_POLICY_STATE} */
this.consentState_ = null;
/** @private {?string} */
this.consentString_ = null;
/** @private {?{[key: string]: string|number|boolean|undefined}} */
this.consentMetadata_ = null;
}
/**
* @param {string} error
* @param {string} callout
* @param {string} errorReportingUrl
* @param {number=} opt_rtcTime
* @return {!Promise<!rtcResponseDef>}
* @private
*/
buildErrorResponse_(error, callout, errorReportingUrl, opt_rtcTime) {
dev().warn(TAG, `RTC callout to ${callout} caused ${error}`);
if (errorReportingUrl) {
this.sendErrorMessage(error, errorReportingUrl);
}
return Promise.resolve(
/**@type {rtcResponseDef} */ ({error, callout, rtcTime: opt_rtcTime || 0})
);
}
/**
* @param {string} errorType Uses the RTC_ERROR_ENUM above.
* @param {string} errorReportingUrl
*/
sendErrorMessage(errorType, errorReportingUrl) {
if (
!getMode(this.win_).localDev &&
!getMode(this.win_).test &&
Math.random() >= 0.01
) {
return;
}
const allowlist = {ERROR_TYPE: true, HREF: true};
const macros = {
ERROR_TYPE: errorType,
HREF: this.win_.location.href,
};
const service = Services.urlReplacementsForDoc(this.ampDoc_);
const url = service.expandUrlSync(errorReportingUrl, macros, allowlist);
new this.win_.Image().src = url;
}
/**
* Converts a URL into its corresponding shortened callout string.
* We also truncate to a maximum length of 50 characters.
* For instance, if we are passed
* "https://example.test/example.php?foo=a&bar=b, then we return
* example.test/example.php
* @param {string} url
* @return {string}
*/
getCalloutParam_(url) {
const urlService = Services.urlForDoc(this.ampDoc_);
const parsedUrl = urlService.parse(url);
return (parsedUrl.hostname + parsedUrl.pathname).substr(0, 50);
}
/**
* Returns whether a given callout object is valid to send an RTC request
* to, for the given consentState.
* @param {Object|string} calloutConfig
* @param {boolean=} optIsGloballyValid
* @return {boolean}
* @visibleForTesting
*/
isValidCalloutForConsentState(calloutConfig, optIsGloballyValid) {
const {sendRegardlessOfConsentState} = calloutConfig;
if (!isObject(calloutConfig) || !sendRegardlessOfConsentState) {
return !!optIsGloballyValid;
}
if (typeof sendRegardlessOfConsentState == 'boolean') {
return sendRegardlessOfConsentState;
}
if (isArray(sendRegardlessOfConsentState)) {
for (let i = 0; i < sendRegardlessOfConsentState.length; i++) {
if (
this.consentState_ ==
CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]
) {
return true;
} else if (!CONSENT_POLICY_STATE[sendRegardlessOfConsentState[i]]) {
dev().warn(
TAG,
'Invalid RTC consent state given: ' +
`${sendRegardlessOfConsentState[i]}`
);
}
}
return false;
}
user().warn(
TAG,
'Invalid value for sendRegardlessOfConsentState:' +
`${sendRegardlessOfConsentState}`
);
return !!optIsGloballyValid;
}
/**
* Goes through the RTC config, and for any URL that we should not callout
* as per the current consent state, deletes it from the RTC config.
* For example, if the RTC config looked like:
* {vendors: {vendorA: {'sendRegardlessOfConsentState': true}
* vendorB: {'macros': {'SLOT_ID': 1}}},
* urls: ['https://www.rtc.example/example',
* {url: 'https://www.rtcSite2.example/example',
* sendRegardlessOfConsentState: ['UNKNOWN']}]
* }
* and the consentState is CONSENT_POLICY_STATE.UNKNOWN,
* then this method call would clear the callouts to vendorB, and to the first
* custom URL.
*/
modifyRtcConfigForConsentStateSettings() {
if (
this.consentState_ == undefined ||
this.consentState_ == CONSENT_POLICY_STATE.SUFFICIENT ||
this.consentState_ == CONSENT_POLICY_STATE.UNKNOWN_NOT_REQUIRED
) {
return;
}
const isGloballyValid = this.isValidCalloutForConsentState(this.rtcConfig_);
this.rtcConfig_.urls = (this.rtcConfig_.urls || []).filter((url) =>
this.isValidCalloutForConsentState(url, isGloballyValid)
);
Object.keys(this.rtcConfig_.vendors || {}).forEach((vendor) => {
if (
!this.isValidCalloutForConsentState(
this.rtcConfig_.vendors[vendor],
isGloballyValid
)
) {
delete this.rtcConfig_.vendors[vendor];
}
});
}
/**
* Assigns constant macros that should exist for all RTC to object of custom
* per-network macros.
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} macros
* @return {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}}
*/
assignMacros(macros) {
macros['TIMEOUT'] = () => this.rtcConfig_.timeoutMillis;
macros['CONSENT_STATE'] = () => this.consentState_;
macros['CONSENT_STRING'] = () => this.consentString_;
macros['CONSENT_METADATA'] =
/** @type {!../../../src/service/variable-source.AsyncResolverDef} */ (
(key) => {
userAssert(key, 'CONSENT_METADATA macro must contian a key');
return this.consentMetadata_ ? this.consentMetadata_[key] : null;
}
);
return macros;
}
/**
* Manages sending the RTC callouts for the Custom URLs.
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} customMacros The ad-network specified macro
* @param {!Function} checkStillCurrent
* @param {!Element} element
*/
handleRtcForCustomUrls(customMacros, checkStillCurrent, element) {
// For each publisher defined URL, inflate the url using the macros,
// and send the RTC request.
(this.rtcConfig_.urls || []).forEach((urlObj) => {
let url, errorReportingUrl;
if (isObject(urlObj)) {
url = urlObj.url;
errorReportingUrl = urlObj.errorReportingUrl;
} else if (typeof urlObj == 'string') {
url = urlObj;
} else {
dev().warn(TAG, `Invalid url: ${urlObj}`);
}
this.inflateAndSendRtc_(
url,
customMacros,
errorReportingUrl,
checkStillCurrent,
/* opt_vendor */ undefined,
element
);
});
}
/**
* Manages sending the RTC callouts for all specified vendors.
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} customMacros The ad-network specified macro
* @param {!Function} checkStillCurrent
*/
handleRtcForVendorUrls(customMacros, checkStillCurrent) {
// For each vendor the publisher has specified, inflate the vendor
// url if it exists, and send the RTC request.
Object.keys(this.rtcConfig_.vendors || []).forEach((vendor) => {
const vendorObject = RTC_VENDORS[vendor.toLowerCase()];
const url = vendorObject ? vendorObject.url : '';
const errorReportingUrl =
vendorObject && vendorObject.errorReportingUrl
? vendorObject.errorReportingUrl
: '';
if (!url) {
return this.promiseArray_.push(
this.buildErrorResponse_(
RTC_ERROR_ENUM.UNKNOWN_VENDOR,
vendor,
errorReportingUrl
)
);
}
// There are two valid configurations of the vendor object.
// It can either be an object of macros mapping string to string,
// or it can be an object with sub-objects, one of which can be
// 'macros'. This is for backwards compatability.
const vendorMacros = isObject(this.rtcConfig_.vendors[vendor]['macros'])
? this.rtcConfig_.vendors[vendor]['macros']
: this.rtcConfig_.vendors[vendor];
const validVendorMacros = {};
Object.keys(vendorMacros).forEach((macro) => {
if (!(vendorObject.macros && vendorObject.macros.includes(macro))) {
user().error(TAG, `Unknown macro: ${macro} for vendor: ${vendor}`);
} else {
const value = vendorMacros[macro];
validVendorMacros[macro] =
isObject(value) || isArray(value) ? JSON.stringify(value) : value;
}
});
// The ad network defined macros override vendor defined/pub specifed.
const macros = Object.assign(validVendorMacros, customMacros);
this.inflateAndSendRtc_(
url,
macros,
errorReportingUrl,
checkStillCurrent,
vendor.toLowerCase()
);
});
}
/**
* @param {string} url
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} macros
* @param {string} errorReportingUrl
* @param {!Function} checkStillCurrent
* @param {string=} opt_vendor
* @param {!Element=} opt_element
* @private
*/
inflateAndSendRtc_(
url,
macros,
errorReportingUrl,
checkStillCurrent,
opt_vendor,
opt_element
) {
let {timeoutMillis} = this.rtcConfig_;
const callout = opt_vendor || this.getCalloutParam_(url);
/**
* The time that it takes to substitute the macros into the URL can vary
* depending on what the url requires to be substituted, i.e. a long
* async call. Thus, however long the URL replacement took is treated as a
* time penalty.
* @param {string} url
* @return {*} TODO(#23582): Specify return type
*/
const send = (url) => {
if (Object.keys(this.seenUrls_).length == MAX_RTC_CALLOUTS) {
return this.buildErrorResponse_(
RTC_ERROR_ENUM.MAX_CALLOUTS_EXCEEDED,
callout,
errorReportingUrl
);
}
if (
!Services.urlForDoc(this.ampDoc_).isSecure(url) &&
!isAmpScriptUri(url)
) {
return this.buildErrorResponse_(
RTC_ERROR_ENUM.INSECURE_URL,
callout,
errorReportingUrl
);
}
if (this.seenUrls_[url]) {
return this.buildErrorResponse_(
RTC_ERROR_ENUM.DUPLICATE_URL,
callout,
errorReportingUrl
);
}
this.seenUrls_[url] = true;
if (url.length > MAX_URL_LENGTH) {
url = this.truncUrl_(url);
}
return this.sendRtcCallout_(
url,
timeoutMillis,
callout,
checkStillCurrent,
errorReportingUrl,
opt_element
);
};
const allowlist = {...GLOBAL_MACRO_ALLOWLIST};
Object.keys(macros).forEach((key) => (allowlist[key] = true));
const urlReplacementStartTime = Date.now();
this.promiseArray_.push(
Services.timerFor(this.win_)
.timeoutPromise(
timeoutMillis,
Services.urlReplacementsForDoc(this.ampDoc_).expandUrlAsync(
url,
macros,
allowlist
)
)
.then((url) => {
checkStillCurrent();
timeoutMillis -= urlReplacementStartTime - Date.now();
return send(url);
})
.catch((error) => {
return isCancellation(error)
? undefined
: this.buildErrorResponse_(
RTC_ERROR_ENUM.MACRO_EXPAND_TIMEOUT,
callout,
errorReportingUrl
);
})
);
}
/**
* @param {string} url
* @return {string}
*/
truncUrl_(url) {
url = url.substr(0, MAX_URL_LENGTH - 12).replace(/%\w?$/, '');
return url + '&__trunc__=1';
}
/**
* @param {string} url
* @param {number} timeoutMillis
* @param {string} callout
* @param {!Function} checkStillCurrent
* @param {string} errorReportingUrl
* @param {!Element=} opt_element
* @return {!Promise<!rtcResponseDef>}
* @private
*/
sendRtcCallout_(
url,
timeoutMillis,
callout,
checkStillCurrent,
errorReportingUrl,
opt_element
) {
let rtcFetch;
if (isAmpScriptUri(url)) {
rtcFetch = Services.scriptForDocOrNull(opt_element)
.then((service) => {
userAssert(service, 'AMP-SCRIPT is not installed.');
return service.fetch(url);
})
.then((json) => {
checkStillCurrent();
const rtcTime = Date.now() - this.rtcStartTime_;
if (typeof json !== 'object') {
return this.buildErrorResponse_(
RTC_ERROR_ENUM.MALFORMED_JSON_RESPONSE,
callout,
errorReportingUrl,
rtcTime
);
}
return {response: json, rtcTime, callout};
});
} else {
rtcFetch = Services.xhrFor(this.win_)
.fetchJson(
// NOTE(bradfrizzell): we could include ampCors:false allowing
// the request to be cached across sites but for now assume that
// is not a required feature.
url,
{credentials: 'include'}
)
.then((res) => {
checkStillCurrent();
return res.text().then((text) => {
checkStillCurrent();
const rtcTime = Date.now() - this.rtcStartTime_;
// An empty text response is allowed, not an error.
if (!text) {
return {rtcTime, callout};
}
const response = tryParseJson(text);
return response
? {response, rtcTime, callout}
: this.buildErrorResponse_(
RTC_ERROR_ENUM.MALFORMED_JSON_RESPONSE,
callout,
errorReportingUrl,
rtcTime
);
});
});
}
/**
* Note: Timeout is enforced by timerFor, not the value of
* rtcTime. There are situations where rtcTime could thus
* end up being greater than timeoutMillis.
*/
return Services.timerFor(this.win_)
.timeoutPromise(timeoutMillis, rtcFetch)
.catch((error) => {
return isCancellation(error)
? undefined
: this.buildErrorResponse_(
// The relevant error message for timeout looks like it is
// just 'message' but is in fact 'messageXXX' where the
// X's are hidden special characters. That's why we use
// match here.
/^timeout/.test(error.message)
? RTC_ERROR_ENUM.TIMEOUT
: RTC_ERROR_ENUM.NETWORK_FAILURE,
callout,
errorReportingUrl,
Date.now() - this.rtcStartTime_
);
});
}
/**
* For a given A4A Element, sends out Real Time Config requests to
* any urls or vendors specified by the publisher.
* @param {!Element} element
* @param {!{[key: string]: !../../../src/service/variable-source.AsyncResolverDef}} customMacros The ad-network specified macro
* substitutions available to use.
* @param {?CONSENT_POLICY_STATE} consentState
* @param {?string} consentString
* @param {?{[key: string]: string|number|boolean|undefined}} consentMetadata
* @param {!Function} checkStillCurrent
* @return {Promise<!Array<!rtcResponseDef>>|undefined}
* @visibleForTesting
*/
execute(
element,
customMacros,
consentState,
consentString,
consentMetadata,
checkStillCurrent
) {
if (!this.validateRtcConfig_(element)) {
return;
}
this.consentState_ = consentState;
this.consentString_ = consentString;
this.consentMetadata_ = consentMetadata;
this.modifyRtcConfigForConsentStateSettings();
customMacros = this.assignMacros(customMacros);
this.rtcStartTime_ = Date.now();
this.handleRtcForCustomUrls(customMacros, checkStillCurrent, element);
this.handleRtcForVendorUrls(customMacros, checkStillCurrent);
return Promise.all(this.promiseArray_);
}
/**
* Attempts to parse the publisher-defined RTC config off the amp-ad
* element, then validates that the rtcConfig exists, and contains
* an entry for either vendor URLs, or publisher-defined URLs. If the
* config contains an entry for timeoutMillis, validates that it is a
* number, or converts to a number if number-like, otherwise overwrites
* with the default.
* IMPORTANT: If the rtcConfig is invalid, RTC is aborted, and the ad
* request continues without RTC.
* @param {!Element} element
* @return {boolean}
*/
validateRtcConfig_(element) {
const defaultTimeoutMillis = 1000;
const unparsedRtcConfig = element.getAttribute('rtc-config');
if (!unparsedRtcConfig) {
return false;
}
const rtcConfig = tryParseJson(unparsedRtcConfig);
if (!rtcConfig) {
user().warn(TAG, 'Could not JSON parse rtc-config attribute');
return false;
}
let timeout;
try {
userAssert(
rtcConfig['vendors'] || rtcConfig['urls'],
'RTC Config must specify vendors or urls'
);
Object.keys(rtcConfig).forEach((key) => {
switch (key) {
case 'vendors':
userAssert(isObject(rtcConfig[key]), 'RTC invalid vendors');
break;
case 'urls':
userAssert(isArray(rtcConfig[key]), 'RTC invalid urls');
break;
case 'timeoutMillis':
timeout = parseInt(rtcConfig[key], 10);
if (isNaN(timeout)) {
user().warn(
TAG,
'Invalid RTC timeout is NaN, ' +
`using default timeout ${defaultTimeoutMillis}ms`
);
timeout = undefined;
} else if (timeout > defaultTimeoutMillis || timeout < 0) {
user().warn(
TAG,
`Invalid RTC timeout: ${timeout}ms, ` +
`using default timeout ${defaultTimeoutMillis}ms`
);
timeout = undefined;
}
break;
default:
user().warn(TAG, `Unknown RTC Config key: ${key}`);
break;
}
});
if (
!Object.keys(rtcConfig['vendors'] || {}).length &&
!(rtcConfig['urls'] || []).length
) {
return false;
}
const validateErrorReportingUrl = (urlObj) => {
const errorUrl = urlObj['errorReportingUrl'];
if (errorUrl && !Services.urlForDoc(this.ampDoc_).isSecure(errorUrl)) {
dev().warn(TAG, `Insecure RTC errorReportingUrl: ${errorUrl}`);
urlObj['errorReportingUrl'] = undefined;
}
};
/** @type {!Array} */ (rtcConfig['urls'] || []).forEach((urlObj) => {
if (isObject(urlObj)) {
validateErrorReportingUrl(urlObj);
}
});
validateErrorReportingUrl(rtcConfig);
} catch (unusedErr) {
// This error would be due to the asserts above.
return false;
}
rtcConfig['timeoutMillis'] =
timeout !== undefined ? timeout : defaultTimeoutMillis;
this.rtcConfig_ = /** @type {RtcConfigDef} */ (rtcConfig);
return true;
}
}
/**
* @param {!../ampdoc-impl.AmpDoc} ampdoc
*/
export function installRealTimeConfigServiceForDoc(ampdoc) {
registerServiceBuilderForDoc(ampdoc, 'real-time-config', function (doc) {
return new RealTimeConfigService(doc);
});
}