🩹(frontend) fix missing notification when state is clear

Notify iframe's parent while integrating Visio when state
is cleared. Requested by Eleonore.
This commit is contained in:
lebaudantoine
2025-04-03 23:26:01 +02:00
committed by aleb_the_flash
parent 66f307b7e8
commit 6324be9fd3
6 changed files with 32 additions and 13 deletions

View File

@@ -66,6 +66,7 @@ export const CreateMeetingButton = () => {
setRoom(undefined)
setCallbackId(undefined)
setIsPending(false)
popupManager.clearState()
}
if (isPending) {

View File

@@ -24,6 +24,21 @@ export class PopupManager {
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private messageParent(type: ClientMessageType, data: any) {
window?.parent.postMessage(
{
type: type,
data: data,
},
'*'
)
}
public clearState() {
this.messageParent(ClientMessageType.STATE_CLEAR, {})
}
public setupMessageListener(
onCallbackId: (id: string) => void,
onRoomData: (data: CallbackCreationRoomData) => void
@@ -39,18 +54,12 @@ export class PopupManager {
case PopupMessageType.ROOM_DATA:
if (!data?.room) return
onRoomData(data.room)
window?.parent.postMessage(
{
type: ClientMessageType.ROOM_CREATED,
data: {
room: {
url: getRouteUrl('room', data.room.slug),
...data.room,
},
},
this.messageParent(ClientMessageType.ROOM_CREATED, {
room: {
url: getRouteUrl('room', data.room.slug),
...data.room,
},
'*'
)
})
return
}
}

View File

@@ -4,6 +4,7 @@ export type CallbackCreationRoomData = {
export enum ClientMessageType {
ROOM_CREATED = 'ROOM_CREATED',
STATE_CLEAR = 'STATE_CLEAR',
}
export interface PopupMessageData {

View File

@@ -21,7 +21,10 @@ function App() {
</div>
<div className="group">
<label>Visioconference</label>
<VisioCreateButton onRoomCreated={(data) => setRoomUrl(data.url)} />
<VisioCreateButton
onRoomCreated={(data) => setRoomUrl(data.url)}
onClear={() => setRoomUrl("")}
/>
</div>
<div className="group">
<label>Description</label>

View File

@@ -4,6 +4,7 @@ export type ConfigType = typeof DEFAULT_CONFIG
export enum ClientMessageType {
ROOM_CREATED = 'ROOM_CREATED',
STATE_CLEAR = 'STATE_CLEAR',
}
export type RoomData = {

View File

@@ -4,10 +4,12 @@ import { DEFAULT_CONFIG } from '@/Config'
export const VisioCreateButton = ({
onRoomCreated,
onClear,
readOnly = false,
slug,
}: {
onRoomCreated: (roomData: RoomData) => void
onClear: () => void
readOnly?: boolean
slug?: string
}) => {
@@ -20,13 +22,15 @@ export const VisioCreateButton = ({
const { type, data } = event.data
if (type == ClientMessageType.ROOM_CREATED && data?.room) {
onRoomCreated(data.room)
} else if (type == ClientMessageType.STATE_CLEAR) {
onClear()
}
}
window.addEventListener('message', onMessage)
return () => {
window.removeEventListener('message', onMessage)
}
}, [onRoomCreated])
}, [onRoomCreated, onClear])
return (
// eslint-disable-next-line jsx-a11y/iframe-has-title