{"version":3,"sources":["../src/index.ts","../src/event-manager/event-manager.ts","../src/common/safe-interval.ts","../src/common/unique-id.ts","../src/event-manager/event-manager.constant.ts","../src/logger/logger.ts","../src/logger/error-messages.constant.ts","../src/config/config.default.ts","../src/config/config.ts","../src/event-manager/broadcast-event.type.ts","../src/event-manager/broadcast-messenger.ts"],"sourcesContent":["import { AdvancedBroadcastMessage } from \"./event-manager/event-manager\";\n\nexport default AdvancedBroadcastMessage;\n\nexport * from \"./types\";\n","import { ZalgoPromise } from \"zalgo-promise\";\nimport { safeInterval } from \"../common/safe-interval\";\nimport { uniqueId } from \"../common/unique-id\";\nimport { Config } from \"../config\";\nimport { Logger, getErrorMessage } from \"../logger\";\nimport { ERROR_CODES, ERROR_MESSAGES } from \"../logger/error-messages.constant\";\nimport { UserChannelConfig } from \"../types\";\nimport {\n  EditorBroadcastChannelNature,\n  EditorRequestEventMessage,\n} from \"./broadcast-event.type\";\nimport { EVENT_MANAGER_NAME, RESPONSE_CYCLE } from \"./event-manager.constant\";\nimport {\n  OnEvent,\n  RequestHandler,\n  RequestListener,\n  ResponseListener,\n} from \"./event-manager.type\";\nimport { BroadcastMessenger } from \"./broadcast-messenger\";\n\n/**\n * Manages the events and message communication between different windows or iframes.\n */\nexport class AdvancedBroadcastMessage {\n  private requestMessageHandlers = new Map<string, RequestListener>();\n  private responseMessageHandlers = new Map<string, ResponseListener>();\n  private broadcastMessenger: BroadcastMessenger;\n  private logger: Logger;\n  private config: Config;\n\n  constructor(channelId: string, options: UserChannelConfig = {}) {\n    if (!channelId) {\n      throw new Error(getErrorMessage(ERROR_MESSAGES.common.channelIdRequired));\n    }\n    this.config = new Config(channelId, options);\n    this.logger = new Logger(this.config);\n    this.broadcastMessenger = new BroadcastMessenger(this.logger, this.config);\n\n    this.handleIncomingMessage = this.handleIncomingMessage.bind(this);\n    this.send = this.send.bind(this);\n    this.on = this.on.bind(this);\n    this.unregisterEvent = this.unregisterEvent.bind(this);\n\n    this.broadcastMessenger.onMessage(this.handleIncomingMessage);\n  }\n\n  /**\n   * Handle an incoming post message event\n   * @param event The post message event containing details of the request\n   * @returns A promise that resolves when the response is received\n   */\n  private async handleIncomingMessage(event: EditorRequestEventMessage) {\n    const { type, channel, payload, eventManager, metadata, error } = event;\n\n    if (\n      eventManager !== EVENT_MANAGER_NAME ||\n      channel !== this.config.get(\"channelId\")\n    ) {\n      return;\n    }\n\n    const { hash, nature } = metadata;\n\n    switch (nature) {\n      case EditorBroadcastChannelNature.REQUEST: {\n        this.logger.debug(\"REQUEST received\", event);\n        if (this.broadcastMessenger.isClosed) {\n          this.logger.error(\n            getErrorMessage(ERROR_MESSAGES.common.channelIsClosed),\n          );\n        }\n\n        this.broadcastMessenger.sendAck({ type, hash });\n\n        if (!this.requestMessageHandlers.has(type)) {\n          this.logger.debug(\n            getErrorMessage(\n              ERROR_MESSAGES.receiveEvent.noRequestListenerFound(type),\n            ),\n          );\n\n          this.broadcastMessenger.sendResponse({\n            type,\n            hash,\n            payload: undefined,\n            error: {\n              code: ERROR_CODES.receiveEvent.noRequestListenerFound,\n              message: getErrorMessage(\n                ERROR_MESSAGES.receiveEvent.noRequestListenerFound(type),\n              ),\n            },\n          });\n          return;\n        }\n\n        const { handler } = this.requestMessageHandlers.get(type)!;\n\n        const handlerEvent: OnEvent = {\n          data: payload,\n        };\n\n        return ZalgoPromise.all([\n          ZalgoPromise.try(() => {\n            return handler(handlerEvent);\n          })\n            .then((data) => {\n              this.broadcastMessenger.sendResponse({\n                type,\n                hash,\n                payload: data,\n                error: undefined,\n              });\n            })\n            .catch((err) => {\n              this.logger.error(\n                getErrorMessage(ERROR_MESSAGES.receiveEvent.codeReturnedError),\n                err,\n              );\n            }),\n        ]);\n      }\n      case EditorBroadcastChannelNature.RESPONSE: {\n        this.logger.debug(\"RESPONSE received\", event);\n\n        if (!this.responseMessageHandlers.has(hash)) {\n          this.logger.error(\n            getErrorMessage(\n              ERROR_MESSAGES.receiveEvent.noResponseListenerFound(hash),\n            ),\n          );\n          return;\n        }\n\n        const responseListener = this.responseMessageHandlers.get(hash)!;\n\n        if (error) {\n          responseListener.promise.reject(error);\n        } else {\n          responseListener.promise.resolve(payload);\n        }\n\n        break;\n      }\n      case EditorBroadcastChannelNature.ACK: {\n        this.logger.debug(\"ACK received\", event);\n\n        if (!this.responseMessageHandlers.has(hash)) {\n          this.logger.error(\n            getErrorMessage(\n              ERROR_MESSAGES.receiveEvent.noAckListenerFound(hash),\n            ),\n          );\n          return;\n        }\n\n        const responseListener = this.responseMessageHandlers.get(hash)!;\n        responseListener.hasReceivedAck = true;\n\n        break;\n      }\n      default:\n        this.logger.error(\n          getErrorMessage(ERROR_MESSAGES.receiveEvent.unknownNature(nature)),\n          event,\n        );\n    }\n  }\n\n  /**\n   * Send an event to the target window\n   * @param type The type of event to send\n   * @param payload The payload to send with the event\n   *\n   * @example\n   * const eventManager = new EventManager(\"channel-id\");\n   *\n   * const output = eventManager.send(\"my-event\", { foo: \"bar\" });\n   * console.log(output) // { foo: \"bar1\" }\n   */\n  async send<ReturnType = undefined>(type: string, payload?: any) {\n    const promise = new ZalgoPromise<ReturnType>();\n    const hash = uniqueId(type);\n\n    const responseListener: ResponseListener = {\n      type,\n      promise,\n      hasCancelled: false,\n      hasReceivedAck: false,\n    };\n\n    this.responseMessageHandlers.set(hash, responseListener);\n\n    const totalAllowedAckTime = 1000;\n    let ackTimeLeft = totalAllowedAckTime;\n\n    const interval = safeInterval(() => {\n      if (this.broadcastMessenger.isClosed) {\n        return promise.reject(\n          new Error(getErrorMessage(ERROR_MESSAGES.common.channelIsClosed)),\n        );\n      }\n\n      // TODO: raise this event\n      // if (responseListener.hasCancelled) {\n      //     return promise.reject(\n      //         new Error(\n      //             getErrorMessage(ERROR_MESSAGES.sendEvent.eventCancelled)\n      //         )\n      //     );\n      // }\n\n      ackTimeLeft = Math.max(ackTimeLeft - RESPONSE_CYCLE, 0);\n\n      if (!responseListener.hasReceivedAck && ackTimeLeft <= 0) {\n        return promise.reject(\n          getErrorMessage(ERROR_MESSAGES.sendEvent.noAckReceived),\n        );\n      }\n    }, RESPONSE_CYCLE);\n\n    promise\n      .finally(() => {\n        this.responseMessageHandlers.delete(hash);\n        interval.cancel();\n      })\n      .catch((err) => {\n        this.logger.debug(\n          getErrorMessage(ERROR_MESSAGES.sendEvent.receiverReturnedError),\n          err,\n        );\n      });\n\n    this.broadcastMessenger.sendRequest({\n      type,\n      hash,\n      error: undefined,\n      payload,\n    });\n\n    return promise;\n  }\n\n  /**\n   * Register an event handler for a specific event type\n   * @param type The type of event to listen for\n   * @param handler The handler to call when the event is received\n   * @returns An object with an unregister method to unregister the event\n   *\n   * @example\n   * const eventManager = new EventManager(\"channel-id\");\n   *\n   * const unregister = eventManager.on(\"my-event\", (event) => {\n   *  console.log(\"event received\", event);\n   *  return { foo: \"bar1\" };\n   * });\n   *\n   * unregister();\n   */\n  on<Payload = unknown, ReturnType = any>(\n    type: string,\n    handler: RequestHandler<Payload, ReturnType>,\n  ) {\n    if (this.requestMessageHandlers.has(type)) {\n      this.logger.error(\n        getErrorMessage(\n          ERROR_MESSAGES.registerEvent.eventAlreadyRegistered(type),\n        ),\n      );\n    }\n\n    const requestListener: RequestListener = {\n      handler,\n    };\n    this.requestMessageHandlers.set(type, requestListener);\n\n    return {\n      unregister: () => {\n        this.unregisterEvent(type);\n      },\n    };\n  }\n\n  /**\n   * Unregister an event handler for a specific event type\n   * @param type The type of event to unregister\n   */\n  private unregisterEvent(type: string) {\n    if (!this.requestMessageHandlers.has(type)) {\n      this.logger.error(\n        getErrorMessage(ERROR_MESSAGES.unregisterEvent.eventDoesNotExist(type)),\n      );\n    } else {\n      this.logger.debug(\"Unregistering event\", type);\n\n      this.requestMessageHandlers.delete(type);\n    }\n  }\n\n  /**\n   * Destroy the event manager\n   */\n  destroy(config?: { soft?: boolean }) {\n    this.requestMessageHandlers.clear();\n    this.responseMessageHandlers.clear();\n\n    if (!config?.soft) {\n      this.broadcastMessenger.close();\n    }\n  }\n}\n","export function safeInterval(\n  method: () => void,\n  time: number,\n): { cancel: () => void } {\n  let timeout: NodeJS.Timeout;\n\n  function loop() {\n    timeout = setTimeout(() => {\n      method();\n      loop();\n    }, time);\n  }\n  loop();\n\n  return {\n    cancel() {\n      clearTimeout(timeout);\n    },\n  };\n}\n","export function uniqueId(prefix?: string) {\n  const suffix = crypto.randomUUID().split(\"-\")[0];\n  return prefix ? `${prefix}-${suffix}` : suffix;\n}\n","export const RESPONSE_CYCLE = 500;\nexport const EVENT_MANAGER_NAME = \"advanced-broadcast-message\";\n","import { Config } from \"../config\";\nimport { EVENT_MANAGER_NAME } from \"../event-manager/event-manager.constant\";\n\nexport class Logger {\n  prefix = EVENT_MANAGER_NAME;\n\n  constructor(private config: Config) {\n    this.log = this.log.bind(this);\n    this.info = this.info.bind(this);\n    this.debug = this.debug.bind(this);\n    this.error = this.error.bind(this);\n  }\n\n  public log(...args: any[]) {\n    console.log(this.prefix, ...args);\n  }\n\n  public info(...args: any[]) {\n    console.info(this.prefix, ...args);\n  }\n\n  public debug(...args: any[]) {\n    if (this.config.get(\"developmentConfig.debug\")) {\n      console.debug(this.prefix, \"DEBUG:\", ...args, this.getDebugOptions());\n    }\n  }\n\n  public error(...args: any[]) {\n    if (!this.config.get(\"developmentConfig.suppressErrors\")) {\n      console.error(this.prefix, ...args);\n    }\n  }\n\n  private getDebugOptions() {\n    return {\n      // You can add more debug options here\n    };\n  }\n}\n\nexport function getErrorMessage(message: string) {\n  return EVENT_MANAGER_NAME + \": \" + message;\n}\n","export const ERROR_MESSAGES = {\n  common: {\n    channelIdRequired: \"The channelId is required\",\n    channelIsClosed: \"The broadcast channel is closed\",\n  },\n  sendEvent: {\n    receiverReturnedError: \"The receiver returned an error\",\n    eventCancelled: \"The event was cancelled\",\n    noAckReceived: \"The ACK was not received\",\n  },\n  receiveEvent: {\n    noRequestListenerFound(type: string) {\n      return `No request listener found for event \"${type}\"` as const;\n    },\n    codeReturnedError: \"The code returned an error\",\n    noResponseListenerFound(hash: string) {\n      return `No response listener found for hash \"${hash}\"` as const;\n    },\n    noAckListenerFound(hash: string) {\n      return `No ack listener found for hash \"${hash}\"` as const;\n    },\n    unknownNature(nature: string) {\n      return `The nature \"${nature}\" is unknown` as const;\n    },\n  },\n  registerEvent: {\n    eventAlreadyRegistered(type: string) {\n      return `The event \"${type}\" is already registered` as const;\n    },\n  },\n  unregisterEvent: {\n    eventDoesNotExist(type: string) {\n      return `The event \"${type}\" does not exist` as const;\n    },\n  },\n} as const;\n\nexport const ERROR_CODES = {\n  common: {},\n  sendEvent: {\n    receiverReturnedError: \"RECEIVER_RETURNED_ERROR\",\n    eventCancelled: \"EVENT_CANCELLED\",\n    noAckReceived: \"NO_ACK_RECEIVED\",\n  },\n  receiveEvent: {\n    noRequestListenerFound: \"NO_REQUEST_LISTENER_FOUND\",\n    codeReturnedError: \"CODE_RETURNED_ERROR\",\n    noResponseListenerFound: \"NO_RESPONSE_LISTENER_FOUND\",\n    noAckListenerFound: \"NO_ACK_LISTENER_FOUND\",\n    unknownNature: \"UNKNOWN_NATURE\",\n  },\n  registerEvent: {\n    eventAlreadyRegistered: \"EVENT_ALREADY_REGISTERED\",\n  },\n  unregisterEvent: {\n    eventDoesNotExist: \"EVENT_DOES_NOT_EXIST\",\n  },\n} as const;\n","import { ChannelConfig } from \"./config.type\";\n\nexport function getDefaultConfig(): ChannelConfig {\n  return {\n    channelId: \"\",\n    developmentConfig: {\n      debug: false,\n      suppressErrors: false,\n    },\n    channelConfig: {},\n  };\n}\n","import { Path, PathValue } from \"../common/util.type\";\nimport { getErrorMessage } from \"../logger\";\nimport { ERROR_MESSAGES } from \"../logger/error-messages.constant\";\nimport { getDefaultConfig } from \"./config.default\";\nimport type { ChannelConfig, UserChannelConfig } from \"./config.type\";\nimport { get, set } from \"lodash-es\";\n\n/**\n * Class responsible for handling the configuration settings.\n */\nexport class Config {\n  private config: ChannelConfig;\n\n  constructor(channelId: string, options: UserChannelConfig = {}) {\n    this.config = updateConfig({ channelId, ...options });\n  }\n\n  /**\n   * Sets a specific configuration key to the provided value.\n   * @param key - The configuration key to set.\n   * @param value - The value to set for the configuration key.\n   */\n  set<K extends Path<ChannelConfig>>(\n    key: K,\n    value: PathValue<ChannelConfig, K>,\n  ): void {\n    set(this.config, key, value);\n  }\n\n  /**\n   * Retrieves the value of a specific configuration key.\n   * @param key - The configuration key to retrieve the value for.\n   * @returns The value of the configuration key.\n   */\n  get<K extends Path<ChannelConfig>>(key: K): PathValue<ChannelConfig, K> {\n    return get(this.config, key) as PathValue<ChannelConfig, K>;\n  }\n\n  /**\n   * Retrieves all user configurations.\n   * @returns {ChannelConfig} The user configurations.\n   */\n  getAll(): ChannelConfig {\n    return this.config;\n  }\n\n  /**\n   * Resets the configuration to the default values.\n   */\n  reset(): void {\n    this.config = getDefaultConfig();\n  }\n}\n\n/**\n * Updates the configuration object with the provided partial configuration.\n * @param userInput - The partial configuration provided by the user.\n * @param config - The current configuration object.\n */\nfunction updateConfig(\n  userInput: UserChannelConfig & { channelId: string },\n): ChannelConfig {\n  if (userInput.channelId === \"\") {\n    throw new Error(getErrorMessage(ERROR_MESSAGES.common.channelIdRequired));\n  }\n\n  const config = getDefaultConfig();\n  config.channelId = userInput.channelId;\n  const { debug, suppressErrors, ...channelConfig } = userInput;\n\n  // * development configurations\n  config.developmentConfig.debug = debug ?? config.developmentConfig.debug;\n\n  config.developmentConfig.suppressErrors =\n    suppressErrors ?? config.developmentConfig.suppressErrors;\n\n  // * channel configurations\n  config.channelConfig = channelConfig; // Since it will always be an object, we can directly assign it.\n\n  return config;\n}\n","import { EVENT_MANAGER_NAME } from \"./event-manager.constant\";\n\nexport enum EditorBroadcastChannelNature {\n  ACK = \"ACK\",\n  RESPONSE = \"RESPONSE\",\n  REQUEST = \"REQUEST\",\n}\n\nexport interface AdvBroadcastChannelErrorObject {\n  code: string;\n  message: string;\n}\nexport interface EditorRequestEventMessage {\n  eventManager: typeof EVENT_MANAGER_NAME;\n  metadata: {\n    hash: string;\n    nature: EditorBroadcastChannelNature;\n  };\n  channel: string;\n  payload: any;\n  error: undefined | AdvBroadcastChannelErrorObject;\n  type: string;\n}\n\nexport interface BroadcastChannelSendOptions {\n  hash: string;\n  error: undefined | AdvBroadcastChannelErrorObject;\n  payload: any;\n  type: string;\n}\n","import { BroadcastChannel, OnMessageHandler } from \"broadcast-channel\";\nimport { Config } from \"../config\";\nimport { Logger } from \"../logger\";\nimport {\n  EditorBroadcastChannelNature,\n  EditorRequestEventMessage,\n  BroadcastChannelSendOptions,\n} from \"./broadcast-event.type\";\nimport { EVENT_MANAGER_NAME } from \"./event-manager.constant\";\nimport { ERROR_MESSAGES } from \"../logger/error-messages.constant\";\n\nexport class BroadcastMessenger {\n  private config: Config;\n  private broadcastChannel: BroadcastChannel<EditorRequestEventMessage>;\n\n  constructor(\n    private logger: Logger,\n    config: Config,\n  ) {\n    this.sendResponse = this.sendResponse.bind(this);\n    this.sendRequest = this.sendRequest.bind(this);\n    this.sendAck = this.sendAck.bind(this);\n    this.getMessage = this.getMessage.bind(this);\n\n    this.config = config;\n    this.broadcastChannel = new BroadcastChannel<EditorRequestEventMessage>(\n      this.config.get(\"channelId\"),\n      this.config.get(\"channelConfig\"),\n    );\n  }\n\n  sendRequest(config: BroadcastChannelSendOptions) {\n    const completeConfig = {\n      ...config,\n      nature: EditorBroadcastChannelNature.REQUEST,\n    };\n    this.logger.debug(\"Sending REQUEST\", completeConfig);\n\n    const message = this.getMessage(completeConfig);\n    this.broadcastChannel.postMessage(message);\n  }\n\n  sendResponse(config: BroadcastChannelSendOptions) {\n    const completeConfig = {\n      ...config,\n      nature: EditorBroadcastChannelNature.RESPONSE,\n    };\n    this.logger.debug(\"Sending RESPONSE\", completeConfig);\n\n    const message = this.getMessage(completeConfig);\n    this.broadcastChannel.postMessage(message);\n  }\n\n  sendAck(config: Omit<BroadcastChannelSendOptions, \"payload\" | \"error\">) {\n    const completeConfig = {\n      ...config,\n      payload: undefined,\n      error: undefined,\n      nature: EditorBroadcastChannelNature.ACK,\n    };\n    this.logger.debug(\"Sending ACK\", completeConfig);\n\n    const message = this.getMessage(completeConfig);\n    this.broadcastChannel.postMessage(message);\n  }\n\n  private getMessage(\n    config: BroadcastChannelSendOptions & {\n      nature: EditorBroadcastChannelNature;\n    },\n  ): EditorRequestEventMessage {\n    const { nature, hash, payload, type, error } = config;\n    return {\n      eventManager: EVENT_MANAGER_NAME,\n      metadata: {\n        hash,\n        nature,\n      },\n      channel: this.config.get(\"channelId\"),\n      error,\n      payload,\n      type,\n    };\n  }\n\n  onMessage(handler: OnMessageHandler<EditorRequestEventMessage>) {\n    if (this.broadcastChannel.isClosed) {\n      throw new Error(ERROR_MESSAGES.common.channelIsClosed);\n    }\n\n    this.broadcastChannel.onmessage = handler;\n  }\n\n  get isClosed() {\n    return this.broadcastChannel.isClosed;\n  }\n\n  close() {\n    this.broadcastChannel.close();\n  }\n}\n"],"mappings":"mqCAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GCAA,IAAAK,EAA6B,yBCAtB,SAASC,EACdC,EACAC,EACwB,CACxB,IAAIC,EAEJ,SAASC,GAAO,CACdD,EAAU,WAAW,IAAM,CACzBF,EAAO,EACPG,EAAK,CACP,EAAGF,CAAI,CACT,CACA,OAAAE,EAAK,EAEE,CACL,QAAS,CACP,aAAaD,CAAO,CACtB,CACF,CACF,CCnBO,SAASE,EAASC,EAAiB,CACxC,IAAMC,EAAS,OAAO,WAAW,EAAE,MAAM,GAAG,EAAE,CAAC,EAC/C,OAAOD,EAAS,GAAGA,CAAM,IAAIC,CAAM,GAAKA,CAC1C,CCFO,IAAMC,EAAqB,6BCE3B,IAAMC,EAAN,KAAa,CAGlB,YAAoBC,EAAgB,CAAhB,YAAAA,EAFpBC,EAAA,cAASC,GAGP,KAAK,IAAM,KAAK,IAAI,KAAK,IAAI,EAC7B,KAAK,KAAO,KAAK,KAAK,KAAK,IAAI,EAC/B,KAAK,MAAQ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,EAAmC,CACvC,QAAAV,CACF,EACA,YAAK,uBAAuB,IAAIV,EAAMoB,CAAe,EAE9C,CACL,WAAY,IAAM,CAChB,KAAK,gBAAgBpB,CAAI,CAC3B,CACF,CACF,CAMQ,gBAAgBA,EAAc,CAC/B,KAAK,uBAAuB,IAAIA,CAAI,GAKvC,KAAK,OAAO,MAAM,sBAAuBA,CAAI,EAE7C,KAAK,uBAAuB,OAAOA,CAAI,GANvC,KAAK,OAAO,MACVP,EAAgBC,EAAe,gBAAgB,kBAAkBM,CAAI,CAAC,CACxE,CAMJ,CAKA,QAAQqB,EAA6B,CACnC,KAAK,uBAAuB,MAAM,EAClC,KAAK,wBAAwB,MAAM,EAE9BA,GAAA,MAAAA,EAAQ,MACX,KAAK,mBAAmB,MAAM,CAElC,CACF,EDnTA,IAAOC,EAAQC","names":["src_exports","__export","EditorBroadcastChannelNature","src_default","__toCommonJS","import_zalgo_promise","safeInterval","method","time","timeout","loop","uniqueId","prefix","suffix","EVENT_MANAGER_NAME","Logger","config","__publicField","EVENT_MANAGER_NAME","args","getErrorMessage","message","ERROR_MESSAGES","type","hash","nature","ERROR_CODES","getDefaultConfig","import_lodash_es","Config","channelId","options","__publicField","updateConfig","__spreadValues","key","value","getDefaultConfig","userInput","getErrorMessage","ERROR_MESSAGES","config","_a","debug","suppressErrors","channelConfig","__objRest","EditorBroadcastChannelNature","import_broadcast_channel","BroadcastMessenger","logger","config","__publicField","completeConfig","__spreadProps","__spreadValues","message","nature","hash","payload","type","error","EVENT_MANAGER_NAME","handler","ERROR_MESSAGES","AdvancedBroadcastMessage","channelId","options","__publicField","getErrorMessage","ERROR_MESSAGES","Config","Logger","BroadcastMessenger","event","__async","type","channel","payload","eventManager","metadata","error","EVENT_MANAGER_NAME","hash","nature","ERROR_CODES","handler","handlerEvent","data","err","responseListener","promise","uniqueId","ackTimeLeft","interval","safeInterval","requestListener","config","src_default","AdvancedBroadcastMessage"]}