Changing callback signature of registerAnswerer so that it can return a value and not necessarily a promise.
This commit is contained in:
parent
5b4a72ea1f
commit
280c59e6b5
@ -81,7 +81,7 @@ WA.room.getCurrentRoom(): Promise<Room>
|
|||||||
```
|
```
|
||||||
Return a promise that resolves to a `Room` object with the following attributes :
|
Return a promise that resolves to a `Room` object with the following attributes :
|
||||||
* **id (string) :** ID of the current room
|
* **id (string) :** ID of the current room
|
||||||
* **map (ITiledMap) :** contains the JSON map file with the properties that were setted by the script if `setProperty` was called.
|
* **map (ITiledMap) :** contains the JSON map file with the properties that were set by the script if `setProperty` was called.
|
||||||
* **mapUrl (string) :** Url of the JSON map file
|
* **mapUrl (string) :** Url of the JSON map file
|
||||||
* **startLayer (string | null) :** Name of the layer where the current user started, only if different from `start` layer
|
* **startLayer (string | null) :** Name of the layer where the current user started, only if different from `start` layer
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import { isLoadPageEvent } from "./Events/LoadPageEvent";
|
|||||||
import { handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent } from "./Events/ui/MenuItemRegisterEvent";
|
import { handleMenuItemRegistrationEvent, isMenuItemRegisterIframeEvent } from "./Events/ui/MenuItemRegisterEvent";
|
||||||
import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent";
|
import { SetTilesEvent, isSetTilesEvent } from "./Events/SetTilesEvent";
|
||||||
|
|
||||||
type AnswererCallback<T extends keyof IframeQueryMap> = (query: IframeQueryMap[T]['query']) => Promise<IframeQueryMap[T]['answer']>;
|
type AnswererCallback<T extends keyof IframeQueryMap> = (query: IframeQueryMap[T]['query']) => IframeQueryMap[T]['answer']|Promise<IframeQueryMap[T]['answer']>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listens to messages from iframes and turn those messages into easy to use observables.
|
* Listens to messages from iframes and turn those messages into easy to use observables.
|
||||||
@ -164,7 +164,7 @@ class IframeListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
answerer(query.data).then((value) => {
|
Promise.resolve(answerer(query.data)).then((value) => {
|
||||||
iframe?.contentWindow?.postMessage({
|
iframe?.contentWindow?.postMessage({
|
||||||
id: queryId,
|
id: queryId,
|
||||||
type: query.type,
|
type: query.type,
|
||||||
@ -411,7 +411,7 @@ class IframeListener {
|
|||||||
* @param key The "type" of the query we are answering
|
* @param key The "type" of the query we are answering
|
||||||
* @param callback
|
* @param callback
|
||||||
*/
|
*/
|
||||||
public registerAnswerer<T extends keyof IframeQueryMap>(key: T, callback: (query: IframeQueryMap[T]['query']) => Promise<IframeQueryMap[T]['answer']> ): void {
|
public registerAnswerer<T extends keyof IframeQueryMap>(key: T, callback: (query: IframeQueryMap[T]['query']) => IframeQueryMap[T]['answer']|Promise<IframeQueryMap[T]['answer']> ): void {
|
||||||
this.answerers[key] = callback;
|
this.answerers[key] = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1045,14 +1045,14 @@ ${escapedMessage}
|
|||||||
);
|
);
|
||||||
|
|
||||||
iframeListener.registerAnswerer('getState', () => {
|
iframeListener.registerAnswerer('getState', () => {
|
||||||
return Promise.resolve({
|
return {
|
||||||
mapUrl: this.MapUrlFile,
|
mapUrl: this.MapUrlFile,
|
||||||
startLayerName: this.startPositionCalculator.startLayerName,
|
startLayerName: this.startPositionCalculator.startLayerName,
|
||||||
uuid: localUserStore.getLocalUser()?.uuid,
|
uuid: localUserStore.getLocalUser()?.uuid,
|
||||||
nickname: localUserStore.getName(),
|
nickname: localUserStore.getName(),
|
||||||
roomId: this.RoomId,
|
roomId: this.RoomId,
|
||||||
tags: this.connection ? this.connection.getAllTags() : [],
|
tags: this.connection ? this.connection.getAllTags() : [],
|
||||||
});
|
};
|
||||||
});
|
});
|
||||||
this.iframeSubscriptionList.push(
|
this.iframeSubscriptionList.push(
|
||||||
iframeListener.setTilesStream.subscribe((eventTiles) => {
|
iframeListener.setTilesStream.subscribe((eventTiles) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user