mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 21:36:27 +01:00
Update events
This commit is contained in:
parent
88c9b1b202
commit
a2054aa435
@ -18,7 +18,7 @@ export function CreateEventDispatcherHook(type: string, eventDispatcher: IEventD
|
||||
{
|
||||
eventDispatcher.removeEventListener(type, handlerRef.current);
|
||||
}
|
||||
}, [ type, eventDispatcher, handler ]);
|
||||
}, [ type, eventDispatcher ]);
|
||||
}
|
||||
|
||||
export function DispatchEventHook(eventDispatcher: IEventDispatcher, event: NitroEvent): void
|
||||
|
@ -9,14 +9,9 @@ export function CreateMessageHook(eventType: typeof MessageEvent, handler: (even
|
||||
//@ts-ignore
|
||||
const event = new eventType(handler);
|
||||
|
||||
console.log('register', eventType.name);
|
||||
Nitro.instance.communication.registerMessageEvent(event);
|
||||
|
||||
return () =>
|
||||
{
|
||||
console.log('unregister', eventType.name);
|
||||
Nitro.instance.communication.removeMessageEvent(event);
|
||||
}
|
||||
return () => Nitro.instance.communication.removeMessageEvent(event);
|
||||
}, [ eventType, handler ]);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,8 @@ export function RoomHostView(props: RoomHostViewProps): JSX.Element
|
||||
|
||||
const onRoomEngineObjectEvent = useCallback((event: RoomEngineObjectEvent) =>
|
||||
{
|
||||
if(!eventDispatcher) return;
|
||||
|
||||
const objectId = event.objectId;
|
||||
const category = event.category;
|
||||
|
||||
@ -116,12 +118,22 @@ export function RoomHostView(props: RoomHostViewProps): JSX.Element
|
||||
switch(event.type)
|
||||
{
|
||||
case RoomSessionEvent.CREATED:
|
||||
setEventDispatcher(new EventDispatcher());
|
||||
setEventDispatcher(prevValue =>
|
||||
{
|
||||
if(prevValue) prevValue.removeAllListeners();
|
||||
|
||||
return new EventDispatcher();
|
||||
});
|
||||
StartRoomSession(event.session);
|
||||
return;
|
||||
case RoomSessionEvent.ENDED:
|
||||
setRoomSession(null);
|
||||
setEventDispatcher(null);
|
||||
setEventDispatcher(prevValue =>
|
||||
{
|
||||
if(prevValue) prevValue.removeAllListeners();
|
||||
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
|
Loading…
Reference in New Issue
Block a user