Class DeputyCommunications

Handles inter-tab communication and automatically broadcasts events to listeners.

Hierarchy

Constructors

Properties

broadcastChannel: BroadcastChannel

Methods

  • Type Parameters

    • T extends
          | "userConfigUpdate"
          | "acknowledge"
          | "sessionRequest"
          | "sessionResponse"
          | "sessionClosed"
          | "sessionStarted"
          | "sessionReady"
          | "sessionStop"
          | "pageStatusRequest"
          | "pageStatusResponse"
          | "pageStatusUpdate"
          | "revisionStatusUpdate"
          | "pageNextRevisionRequest"
          | "pageNextRevisionResponse"
          | "wikiConfigUpdate"

    Parameters

    • type: T

      The type of message to send.

    • callback: ((event: Event & {
          data: LowLevelDeputyMessage & {
              type: T;
          };
      }) => void)

      The callback to call when the message is received.

    • Optionaloptions: boolean | AddEventListenerOptions

      Optional options for the event listener.

    Returns void

  • Type Parameters

    • T extends
          | never
          | DeputySessionRequestMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputySessionResponseMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | never
          | never
          | never
          | DeputySessionStopMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusRequestMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusResponseMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusUpdateMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyRevisionStatusUpdateMessage & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageNextRevisionRequest & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageNextRevisionResponse & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyUserConfigurationUpdate & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyWikiConfigurationUpdate & {
              _deputy: true;
              _deputyMessageId: string;
          } & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }

    Parameters

    Returns void

  • Sends a message and waits for the first response. Subsequent responses are ignored. Returns null once the timeout has passed with no responses.

    Type Parameters

    • T extends
          | never
          | DeputySessionRequestMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputySessionResponseMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | never
          | never
          | never
          | DeputySessionStopMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusRequestMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusResponseMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageStatusUpdateMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyRevisionStatusUpdateMessage & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageNextRevisionRequest & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyPageNextRevisionResponse & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyUserConfigurationUpdate & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }
          | DeputyWikiConfigurationUpdate & {
              type:
                  | "userConfigUpdate"
                  | "sessionRequest"
                  | "sessionResponse"
                  | "sessionStop"
                  | "pageStatusRequest"
                  | "pageStatusResponse"
                  | "pageStatusUpdate"
                  | "revisionStatusUpdate"
                  | "pageNextRevisionRequest"
                  | "pageNextRevisionResponse"
                  | "wikiConfigUpdate";
          }

    Parameters

    • data: T
    • timeout: number = 500

      Time to wait for a response, 500ms by default

    Returns Promise<
        | never
        | DeputySessionRequestMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputySessionResponseMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | never
        | never
        | never
        | DeputySessionStopMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyPageStatusRequestMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyPageStatusResponseMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyPageStatusUpdateMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyRevisionStatusUpdateMessage & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyPageNextRevisionRequest & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyPageNextRevisionResponse & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyUserConfigurationUpdate & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }
        | DeputyWikiConfigurationUpdate & {
            _deputy: true;
            _deputyMessageId: string;
        } & {
            type:
                | "userConfigUpdate"
                | "sessionRequest"
                | "sessionResponse"
                | "sessionStop"
                | "pageStatusRequest"
                | "pageStatusResponse"
                | "pageStatusUpdate"
                | "revisionStatusUpdate"
                | "pageNextRevisionRequest"
                | "pageNextRevisionResponse"
                | "wikiConfigUpdate";
        } & {
            _deputyRespondsTo: string;
        } & {
            type: {
                pageNextRevisionRequest: "pageNextRevisionResponse";
                pageNextRevisionResponse: "pageNextRevisionRequest";
                pageStatusRequest: "pageStatusResponse";
                pageStatusResponse: "pageStatusRequest";
                pageStatusUpdate: "acknowledge";
                revisionStatusUpdate: "acknowledge";
                sessionRequest: "sessionResponse";
                sessionResponse: "sessionRequest";
                sessionStop: "acknowledge";
                userConfigUpdate: "userConfigUpdate";
                wikiConfigUpdate: "wikiConfigUpdate";
            }[T["type"]];
        }>