mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-18 21:36:27 +01:00
Update packet listeners
This commit is contained in:
parent
71f9540e99
commit
afba605318
@ -1,20 +1,23 @@
|
||||
import { IMessageComposer, IMessageEvent } from 'nitro-renderer';
|
||||
import { IMessageComposer, IMessageEvent, MessageEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function CreateMessageHook(event: IMessageEvent): void
|
||||
export function CreateMessageHook(eventType: typeof MessageEvent, handler: (event: IMessageEvent) => void): void
|
||||
{
|
||||
useEffect(() =>
|
||||
{
|
||||
console.log('register', event);
|
||||
//@ts-ignore
|
||||
const event = new eventType(handler);
|
||||
|
||||
console.log('register', eventType.name);
|
||||
Nitro.instance.communication.registerMessageEvent(event);
|
||||
|
||||
return () =>
|
||||
{
|
||||
console.log('unregister', event);
|
||||
console.log('unregister', eventType.name);
|
||||
Nitro.instance.communication.removeMessageEvent(event);
|
||||
}
|
||||
}, []);
|
||||
}, [ eventType, handler ]);
|
||||
}
|
||||
|
||||
export function SendMessageHook(event: IMessageComposer<unknown[]>): void
|
||||
|
@ -133,15 +133,15 @@ export function NavigatorMessageHandler(props: NavigatorMessageHandlerProps): JS
|
||||
setSearchResults(parser.result.results);
|
||||
}, [ setSearchResults ]);
|
||||
|
||||
CreateMessageHook(new UserInfoEvent(onUserInfoEvent));
|
||||
CreateMessageHook(new RoomForwardEvent(onRoomForwardEvent));
|
||||
CreateMessageHook(new RoomInfoOwnerEvent(onRoomInfoOwnerEvent));
|
||||
CreateMessageHook(new RoomInfoEvent(onRoomInfoEvent));
|
||||
CreateMessageHook(new RoomDoorbellEvent(onRoomDoorbellEvent));
|
||||
CreateMessageHook(new RoomDoorbellAcceptedEvent(onRoomDoorbellAcceptedEvent));
|
||||
CreateMessageHook(new GenericErrorEvent(onGenericErrorEvent));
|
||||
CreateMessageHook(new NavigatorMetadataEvent(onNavigatorMetadataEvent));
|
||||
CreateMessageHook(new NavigatorSearchEvent(onNavigatorSearchEvent));
|
||||
CreateMessageHook(UserInfoEvent, onUserInfoEvent);
|
||||
CreateMessageHook(RoomForwardEvent, onRoomForwardEvent);
|
||||
CreateMessageHook(RoomInfoOwnerEvent, onRoomInfoOwnerEvent);
|
||||
CreateMessageHook(RoomInfoEvent, onRoomInfoEvent);
|
||||
CreateMessageHook(RoomDoorbellEvent, onRoomDoorbellEvent);
|
||||
CreateMessageHook(RoomDoorbellAcceptedEvent, onRoomDoorbellAcceptedEvent);
|
||||
CreateMessageHook(GenericErrorEvent, onGenericErrorEvent);
|
||||
CreateMessageHook(NavigatorMetadataEvent, onNavigatorMetadataEvent);
|
||||
CreateMessageHook(NavigatorSearchEvent, onNavigatorSearchEvent);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ export function PurseView(props: PurseViewProps): JSX.Element
|
||||
});
|
||||
}
|
||||
|
||||
CreateMessageHook(new UserCreditsEvent(onUserCreditsEvent));
|
||||
CreateMessageHook(new UserCurrencyEvent(onUserCurrencyEvent));
|
||||
CreateMessageHook(new UserCurrencyUpdateEvent(onUserCurrencyUpdateEvent));
|
||||
CreateMessageHook(UserCreditsEvent, onUserCreditsEvent);
|
||||
CreateMessageHook(UserCurrencyEvent, onUserCurrencyEvent);
|
||||
CreateMessageHook(UserCurrencyUpdateEvent, onUserCurrencyUpdateEvent);
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { RoomInfoComposer } from 'nitro-renderer';
|
||||
import { UserInfoEvent } from 'nitro-renderer/src/nitro/communication/messages/incoming/user/data/UserInfoEvent';
|
||||
import { UserInfoDataParser } from 'nitro-renderer/src/nitro/communication/messages/parser/user/data/UserInfoDataParser';
|
||||
import { KeyboardEvent, MouseEvent, useState } from 'react';
|
||||
import { KeyboardEvent, MouseEvent, useCallback, useState } from 'react';
|
||||
import { NavigatorEvent } from '../../events';
|
||||
import { dispatchUiEvent } from '../../hooks/events/ui/ui-event';
|
||||
import { CreateMessageHook, SendMessageHook } from '../../hooks/messages/message-event';
|
||||
@ -18,12 +18,12 @@ export function ToolbarView(props: ToolbarViewProps): JSX.Element
|
||||
const unseenFriendListCount = 0;
|
||||
const unseenAchievementsCount = 0;
|
||||
|
||||
const onUserInfoEvent = (event: UserInfoEvent) =>
|
||||
const onUserInfoEvent = useCallback((event: UserInfoEvent) =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
|
||||
setUserInfo(parser.userInfo);
|
||||
};
|
||||
}, []);
|
||||
|
||||
function onKeyUp(event: KeyboardEvent<HTMLInputElement>)
|
||||
{
|
||||
@ -48,7 +48,7 @@ export function ToolbarView(props: ToolbarViewProps): JSX.Element
|
||||
}
|
||||
}
|
||||
|
||||
CreateMessageHook(new UserInfoEvent(onUserInfoEvent));
|
||||
CreateMessageHook(UserInfoEvent, onUserInfoEvent);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
Loading…
Reference in New Issue
Block a user