1 | /**
|
2 | * @license
|
3 | * Copyright 2019 Google LLC
|
4 | *
|
5 | * Licensed under the Apache License, Version 2.0 (the "License");
|
6 | * you may not use this file except in compliance with the License.
|
7 | * You may obtain a copy of the License at
|
8 | *
|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
10 | *
|
11 | * Unless required by applicable law or agreed to in writing, software
|
12 | * distributed under the License is distributed on an "AS IS" BASIS,
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14 | * See the License for the specific language governing permissions and
|
15 | * limitations under the License.
|
16 | */
|
17 | import { ReceiverHandler, _EventType, _ReceiverResponse, _SenderRequest } from './index';
|
18 | /**
|
19 | * Interface class for receiving messages.
|
20 | *
|
21 | */
|
22 | export declare class Receiver {
|
23 | private readonly eventTarget;
|
24 | private static readonly receivers;
|
25 | private readonly boundEventHandler;
|
26 | private readonly handlersMap;
|
27 | constructor(eventTarget: EventTarget);
|
28 | /**
|
29 | * Obtain an instance of a Receiver for a given event target, if none exists it will be created.
|
30 | *
|
31 | * @param eventTarget - An event target (such as window or self) through which the underlying
|
32 | * messages will be received.
|
33 | */
|
34 | static _getInstance(eventTarget: EventTarget): Receiver;
|
35 | private isListeningto;
|
36 | /**
|
37 | * Fans out a MessageEvent to the appropriate listeners.
|
38 | *
|
39 | * @remarks
|
40 | * Sends an { Status.ACK} upon receipt and a { Status.DONE} once all handlers have
|
41 | * finished processing.
|
42 | *
|
43 | * event - The MessageEvent.
|
44 | *
|
45 | */
|
46 | private handleEvent;
|
47 | /**
|
48 | * Subscribe an event handler for a particular event.
|
49 | *
|
50 | * @param eventType - Event name to subscribe to.
|
51 | * @param eventHandler - The event handler which should receive the events.
|
52 | *
|
53 | */
|
54 | _subscribe<T extends _ReceiverResponse, S extends _SenderRequest>(eventType: _EventType, eventHandler: ReceiverHandler<T, S>): void;
|
55 | /**
|
56 | * Unsubscribe an event handler from a particular event.
|
57 | *
|
58 | * @param eventType - Event name to unsubscribe from.
|
59 | * @param eventHandler - Optinoal event handler, if none provided, unsubscribe all handlers on this event.
|
60 | *
|
61 | */
|
62 | _unsubscribe<T extends _ReceiverResponse, S extends _SenderRequest>(eventType: _EventType, eventHandler?: ReceiverHandler<T, S>): void;
|
63 | }
|