MCPcopy
hub / github.com/angular/angular / onMessage

Method onMessage

packages/service-worker/worker/src/driver.ts:298–329  ·  view source on GitHub ↗

* The handler for message events.

(event: ExtendableMessageEvent)

Source from the content-addressed store, hash-verified

296 * The handler for message events.
297 */
298 private onMessage(event: ExtendableMessageEvent): void {
299 // Ignore message events when the SW is in safe mode, for now.
300 if (this.state === DriverReadyState.SAFE_MODE) {
301 return;
302 }
303
304 // If the message doesn't have the expected signature, ignore it.
305 const data = event.data;
306 if (!data || !data.action) {
307 return;
308 }
309
310 event.waitUntil(
311 (async () => {
312 // Initialization is the only event which is sent directly from the SW to itself, and thus
313 // `event.source` is not a `Client`. Handle it here, before the check for `Client` sources.
314 if (data.action === 'INITIALIZE') {
315 return this.ensureInitialized(event);
316 }
317
318 // Only messages from true clients are accepted past this point.
319 // This is essentially a typecast.
320 if (!this.adapter.isClient(event.source)) {
321 return;
322 }
323
324 // Handle the message and keep the SW alive until it's handled.
325 await this.ensureInitialized(event);
326 await this.handleMessage(data, event.source);
327 })(),
328 );
329 }
330
331 private onPush(msg: PushEvent): void {
332 // Push notifications without data have no effect.

Callers 1

constructorMethod · 0.95

Calls 4

ensureInitializedMethod · 0.95
handleMessageMethod · 0.95
waitUntilMethod · 0.80
isClientMethod · 0.45

Tested by

no test coverage detected