Implement disable/restore proximity meeting in api (#2166)

Co-authored-by: Alexis Faizeau <a.faizeau@workadventu.re>
This commit is contained in:
Alexis Faizeau 2022-05-05 12:03:03 +02:00 committed by Alexis Faizeau
parent b6e006d7bb
commit f7caacc598
5 changed files with 72 additions and 10 deletions

View File

@ -14,7 +14,7 @@ When controls are disabled, the user cannot move anymore using keyboard input. T
Example:
```javascript
```ts
WA.room.onEnterLayer('myZone').subscribe(() => {
WA.controls.disablePlayerControls();
WA.ui.openPopup("popupRectangle", 'This is an imporant message!', [{
@ -25,5 +25,28 @@ WA.room.onEnterLayer('myZone').subscribe(() => {
popup.close();
}
}]);
})
});
```
### Disabling / restoring proximity meeting
```
WA.controls.disablePlayerProximityMeeting(): void
WA.controls.restorePlayerProximityMeeting(): void
```
These 2 methods can be used to completely disable player proximity meeting and to enable them again.
When proximity meeting are disabled, the user cannot speak with anyone.
Example:
```ts
WA.room.onEnterLayer('myZone').subscribe(() => {
WA.controls.disablePlayerProximityMeeting();
});
WA.room.onLeaveLayer('myZone').subscribe(() => {
WA.controls.restorePlayerProximityMeeting();
});
```

View File

@ -97,6 +97,14 @@ export const isIframeEventWrapper = z.union([
type: z.literal("restorePlayerControls"),
data: z.undefined(),
}),
z.object({
type: z.literal("disablePlayerProximityMeeting"),
data: z.undefined(),
}),
z.object({
type: z.literal("restorePlayerProximityMeeting"),
data: z.undefined(),
}),
z.object({
type: z.literal("displayBubble"),
data: z.undefined(),

View File

@ -59,6 +59,15 @@ class IframeListener {
private readonly _disablePlayerControlStream: Subject<void> = new Subject();
public readonly disablePlayerControlStream = this._disablePlayerControlStream.asObservable();
private readonly _enablePlayerControlStream: Subject<void> = new Subject();
public readonly enablePlayerControlStream = this._enablePlayerControlStream.asObservable();
private readonly _disablePlayerProximityMeetingStream: Subject<void> = new Subject();
public readonly disablePlayerProximityMeetingStream = this._disablePlayerProximityMeetingStream.asObservable();
private readonly _enablePlayerProximityMeetingStream: Subject<void> = new Subject();
public readonly enablePlayerProximityMeetingStream = this._enablePlayerProximityMeetingStream.asObservable();
private readonly _cameraSetStream: Subject<CameraSetEvent> = new Subject();
public readonly cameraSetStream = this._cameraSetStream.asObservable();
@ -74,9 +83,6 @@ class IframeListener {
public readonly removeActionsMenuKeyFromRemotePlayerEvent =
this._removeActionsMenuKeyFromRemotePlayerEvent.asObservable();
private readonly _enablePlayerControlStream: Subject<void> = new Subject();
public readonly enablePlayerControlStream = this._enablePlayerControlStream.asObservable();
private readonly _closePopupStream: Subject<ClosePopupEvent> = new Subject();
public readonly closePopupStream = this._closePopupStream.asObservable();
@ -264,6 +270,10 @@ class IframeListener {
this._disablePlayerControlStream.next();
} else if (iframeEvent.type === "restorePlayerControls") {
this._enablePlayerControlStream.next();
} else if (iframeEvent.type === "disablePlayerProximityMeeting") {
this._disablePlayerProximityMeetingStream.next();
} else if (iframeEvent.type === "restorePlayerProximityMeeting") {
this._enablePlayerProximityMeetingStream.next();
} else if (iframeEvent.type === "displayBubble") {
this._displayBubbleStream.next();
} else if (iframeEvent.type === "removeBubble") {

View File

@ -10,6 +10,14 @@ export class WorkadventureControlsCommands extends IframeApiContribution<Workadv
restorePlayerControls(): void {
sendToWorkadventure({ type: "restorePlayerControls", data: undefined });
}
disablePlayerProximityMeeting(): void {
sendToWorkadventure({ type: "disablePlayerProximityMeeting", data: undefined });
}
restorePlayerProximityMeeting(): void {
sendToWorkadventure({ type: "restorePlayerProximityMeeting", data: undefined });
}
}
export default new WorkadventureControlsCommands();

View File

@ -1103,6 +1103,24 @@ ${escapedMessage}
})
);
this.iframeSubscriptionList.push(
iframeListener.enablePlayerControlStream.subscribe(() => {
this.userInputManager.restoreControls();
})
);
this.iframeSubscriptionList.push(
iframeListener.disablePlayerProximityMeetingStream.subscribe(() => {
this.disableMediaBehaviors();
})
);
this.iframeSubscriptionList.push(
iframeListener.enablePlayerProximityMeetingStream.subscribe(() => {
this.enableMediaBehaviors();
})
);
this.iframeSubscriptionList.push(
iframeListener.cameraSetStream.subscribe((cameraSetEvent) => {
const duration = cameraSetEvent.smooth ? 1000 : 0;
@ -1190,11 +1208,6 @@ ${escapedMessage}
})
);
this.iframeSubscriptionList.push(
iframeListener.enablePlayerControlStream.subscribe(() => {
this.userInputManager.restoreControls();
})
);
this.iframeSubscriptionList.push(
iframeListener.loadPageStream.subscribe((url: string) => {
this.loadNextGameFromExitUrl(url)