import type * as tg from "generic-type-guard"; import { registeredCallbacks } from '../../iframe_api'; import type { IframeEvent, IframeEventMap, IframeResponseEventMap } from '../Events/IframeEvent'; export function sendToWorkadventure(content: IframeEvent) { window.parent.postMessage(content, "*") } type GuardedType> = Guard extends tg.TypeGuard ? T : never export function apiCallback(callbackData: IframeCallbackContribution): IframeCallbackContribution { const iframeCallback = { typeChecker: callbackData.typeChecker, callback: callbackData.callback } as IframeCallback; const newCallback = { [callbackData.type]: iframeCallback }; Object.assign(registeredCallbacks, newCallback) return callbackData as unknown as IframeCallbackContribution; } export interface IframeCallback> { typeChecker: Guard, callback: (payloadData: T) => void } export interface IframeCallbackContribution extends IframeCallback { type: Key } export type PossibleSubobjects = "zone" | "chat" | "ui" | "nav" | "sound" | "cowebsite" | "player" | "bubble" /** * !! be aware that the implemented attributes (addMethodsAtRoot and subObjectIdentifier) must be readonly * * */ export abstract class IframeApiContribution>, readonly subObjectIdentifier: PossibleSubobjects, readonly addMethodsAtRoot: boolean | undefined }> { abstract callbacks: T["callbacks"] /** * @deprecated this is only there for backwards compatibility on new apis this should be set to false or ignored */ addMethodsAtRoot = false abstract readonly subObjectIdentifier: T["subObjectIdentifier"] }