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