server/front/src/Api/iframe/iframe-registration.ts
jonny 2de2d114a1 added typedef for subobject types
extracted popup functions

# Conflicts:
#	front/package-lock.json
#	front/package.json
#	front/src/iframe_api.ts
2021-05-28 00:30:51 +02:00

27 lines
969 B
TypeScript

import { IframeEvent, IframeEventMap, IframeResponseEventMap } from '../Events/IframeEvent';
import { registeredCallbacks, WorkAdventureApi } from "../../iframe_api"
/*export function registerWorkadventureCommand<T>(commnds: T): T {
const commandPrototype = Object.getPrototypeOf(commnds);
const commandClassPropertyNames = Object.getOwnPropertyNames(commandPrototype).filter(name => name !== "constructor");
for (const key of commandClassPropertyNames) {
window.WA[key as keyof WorkAdventureApi] = commandPrototype[key] as never
}
return commnds
}
*/
export function registerWorkadvntureCallback<T extends Function>(callbacks: Array<{
type: keyof IframeResponseEventMap,
typeChecker: Function,
callback: T
}>) {
for (const callback of callbacks) {
registeredCallbacks[callback.type] = {
typeChecker: callback.typeChecker,
callback: callback.callback
}
}
return callbacks
}