mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-31 10:22:36 +01:00
Update api
This commit is contained in:
parent
ac392c71cf
commit
28804ba67a
18
src/App.tsx
18
src/App.tsx
@ -1,6 +1,6 @@
|
||||
import { ConfigurationEvent, LegacyExternalInterface, Nitro, NitroCommunicationDemoEvent, NitroEvent, NitroLocalizationEvent, RoomEngineEvent, WebGL } from 'nitro-renderer';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { GetConfiguration } from './api';
|
||||
import { GetCommunication, GetConfiguration, GetNitroInstance } from './api';
|
||||
import { useConfigurationEvent } from './hooks/events/core/configuration/configuration-event';
|
||||
import { useLocalizationEvent } from './hooks/events/nitro/localization/localization-event';
|
||||
import { dispatchMainEvent, useMainEvent } from './hooks/events/nitro/main-event';
|
||||
@ -19,7 +19,7 @@ export const App: FC<{}> = props =>
|
||||
//@ts-ignore
|
||||
if(!NitroConfig) throw new Error('NitroConfig is not defined!');
|
||||
|
||||
if(!Nitro.instance) Nitro.bootstrap();
|
||||
if(!GetNitroInstance()) Nitro.bootstrap();
|
||||
|
||||
const getPreloadAssetUrls = useCallback(() =>
|
||||
{
|
||||
@ -28,7 +28,7 @@ export const App: FC<{}> = props =>
|
||||
|
||||
if(assetUrls && assetUrls.length)
|
||||
{
|
||||
for(const url of assetUrls) urls.push(Nitro.instance.core.configuration.interpolate(url));
|
||||
for(const url of assetUrls) urls.push(GetNitroInstance().core.configuration.interpolate(url));
|
||||
}
|
||||
|
||||
return urls;
|
||||
@ -39,7 +39,7 @@ export const App: FC<{}> = props =>
|
||||
switch(event.type)
|
||||
{
|
||||
case ConfigurationEvent.LOADED:
|
||||
Nitro.instance.localization.init();
|
||||
GetNitroInstance().localization.init();
|
||||
return;
|
||||
case ConfigurationEvent.FAILED:
|
||||
setIsError(true);
|
||||
@ -73,14 +73,14 @@ export const App: FC<{}> = props =>
|
||||
case NitroCommunicationDemoEvent.CONNECTION_AUTHENTICATED:
|
||||
setMessage('Finishing Up');
|
||||
|
||||
Nitro.instance.init();
|
||||
GetNitroInstance().init();
|
||||
return;
|
||||
case NitroCommunicationDemoEvent.CONNECTION_ERROR:
|
||||
setIsError(true);
|
||||
setMessage('Connection Error');
|
||||
return;
|
||||
case NitroCommunicationDemoEvent.CONNECTION_CLOSED:
|
||||
if(Nitro.instance.roomEngine) Nitro.instance.roomEngine.dispose();
|
||||
if(GetNitroInstance().roomEngine) GetNitroInstance().roomEngine.dispose();
|
||||
|
||||
setIsError(true);
|
||||
setMessage('Connection Error');
|
||||
@ -91,13 +91,13 @@ export const App: FC<{}> = props =>
|
||||
setIsReady(true);
|
||||
return;
|
||||
case NitroLocalizationEvent.LOADED:
|
||||
Nitro.instance.core.asset.downloadAssets(getPreloadAssetUrls(), (status: boolean) =>
|
||||
GetNitroInstance().core.asset.downloadAssets(getPreloadAssetUrls(), (status: boolean) =>
|
||||
{
|
||||
if(status)
|
||||
{
|
||||
setMessage('Connecting');
|
||||
|
||||
Nitro.instance.communication.init();
|
||||
GetCommunication().init();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -127,7 +127,7 @@ export const App: FC<{}> = props =>
|
||||
}
|
||||
else
|
||||
{
|
||||
Nitro.instance.core.configuration.init();
|
||||
GetNitroInstance().core.configuration.init();
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -1,6 +0,0 @@
|
||||
import { CatalogPageComposer } from 'nitro-renderer';
|
||||
|
||||
export function GetCatalogPageComposer(...args: ConstructorParameters<typeof CatalogPageComposer>): CatalogPageComposer
|
||||
{
|
||||
return new CatalogPageComposer(...args);
|
||||
}
|
7
src/api/core/GetConfigurationManager.ts
Normal file
7
src/api/core/GetConfigurationManager.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { IConfigurationManager } from 'nitro-renderer';
|
||||
import { GetNitroCore } from './GetNitroCore';
|
||||
|
||||
export function GetConfigurationManager(): IConfigurationManager
|
||||
{
|
||||
return GetNitroCore().configuration;
|
||||
}
|
7
src/api/core/GetNitroCore.ts
Normal file
7
src/api/core/GetNitroCore.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { INitroCore } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../nitro';
|
||||
|
||||
export function GetNitroCore(): INitroCore
|
||||
{
|
||||
return GetNitroInstance().core;
|
||||
}
|
2
src/api/core/index.ts
Normal file
2
src/api/core/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './GetConfigurationManager';
|
||||
export * from './GetNitroCore';
|
@ -1 +1,2 @@
|
||||
export * from './core';
|
||||
export * from './nitro';
|
||||
|
7
src/api/nitro/AddLinkEventTracker.ts
Normal file
7
src/api/nitro/AddLinkEventTracker.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { ILinkEventTracker } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function AddEventLinkTracker(tracker: ILinkEventTracker): void
|
||||
{
|
||||
GetNitroInstance().addLinkEventTracker(tracker);
|
||||
}
|
7
src/api/nitro/GetCommunication.ts
Normal file
7
src/api/nitro/GetCommunication.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { INitroCommunicationManager } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function GetCommunication(): INitroCommunicationManager
|
||||
{
|
||||
return GetNitroInstance().communication;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { Nitro } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function GetConfiguration<T>(key: string, value: T = null): T
|
||||
{
|
||||
return Nitro.instance.getConfiguration(key, value);
|
||||
return GetNitroInstance().getConfiguration(key, value);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { IConnection, Nitro } from 'nitro-renderer';
|
||||
import { IConnection } from 'nitro-renderer';
|
||||
import { GetCommunication } from './GetCommunication';
|
||||
|
||||
export function GetConnection(): IConnection
|
||||
{
|
||||
return Nitro.instance.communication.connection;
|
||||
return GetCommunication().connection;
|
||||
}
|
||||
|
6
src/api/nitro/GetNitroInstance.ts
Normal file
6
src/api/nitro/GetNitroInstance.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { INitro, Nitro } from 'nitro-renderer';
|
||||
|
||||
export function GetNitroInstance(): INitro
|
||||
{
|
||||
return Nitro.instance;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { Nitro } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function GetTicker()
|
||||
{
|
||||
return Nitro.instance.ticker;
|
||||
return GetNitroInstance().ticker;
|
||||
}
|
||||
|
7
src/api/nitro/RemoveLinkEventTracker.ts
Normal file
7
src/api/nitro/RemoveLinkEventTracker.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { ILinkEventTracker } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from './GetNitroInstance';
|
||||
|
||||
export function RemoveLinkEventTracker(tracker: ILinkEventTracker): void
|
||||
{
|
||||
GetNitroInstance().removeLinkEventTracker(tracker);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
import { IAvatarRenderManager, Nitro } from 'nitro-renderer';
|
||||
import { IAvatarRenderManager } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../GetNitroInstance';
|
||||
|
||||
export function GetAvatarRenderManager(): IAvatarRenderManager
|
||||
{
|
||||
return Nitro.instance.avatar;
|
||||
return GetNitroInstance().avatar;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Nitro } from 'nitro-renderer';
|
||||
import { IRoomCameraWidgetManager } from 'nitro-renderer/src/nitro/camera/IRoomCameraWidgetManager';
|
||||
import { GetNitroInstance } from '../GetNitroInstance';
|
||||
|
||||
export function GetRoomCameraWidgetManager(): IRoomCameraWidgetManager
|
||||
{
|
||||
return Nitro.instance.cameraManager;
|
||||
return GetNitroInstance().cameraManager;
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
export * from './AddLinkEventTracker';
|
||||
export * from './avatar';
|
||||
export * from './camera';
|
||||
export * from './GetCommunication';
|
||||
export * from './GetConfiguration';
|
||||
export * from './GetConnection';
|
||||
export * from './GetNitroInstance';
|
||||
export * from './GetTicker';
|
||||
export * from './RemoveLinkEventTracker';
|
||||
export * from './room';
|
||||
export * from './session';
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { IRoomEngine, Nitro } from 'nitro-renderer';
|
||||
import { IRoomEngine } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../GetNitroInstance';
|
||||
|
||||
export function GetRoomEngine(): IRoomEngine
|
||||
{
|
||||
return Nitro.instance.roomEngine;
|
||||
return GetNitroInstance().roomEngine;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { IRoomSessionManager, Nitro } from 'nitro-renderer';
|
||||
import { IRoomSessionManager } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../GetNitroInstance';
|
||||
|
||||
export function GetRoomSessionManager(): IRoomSessionManager
|
||||
{
|
||||
return Nitro.instance.roomSessionManager;
|
||||
return GetNitroInstance().roomSessionManager;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { ISessionDataManager, Nitro } from 'nitro-renderer';
|
||||
import { ISessionDataManager } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../GetNitroInstance';
|
||||
|
||||
export function GetSessionDataManager(): ISessionDataManager
|
||||
{
|
||||
return Nitro.instance.sessionDataManager;
|
||||
return GetNitroInstance().sessionDataManager;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetCommunication } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useCommunicationEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.communication.events, handler);
|
||||
CreateEventDispatcherHook(type, GetCommunication().events, handler);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetConfigurationManager } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useConfigurationEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.core.configuration.events, handler);
|
||||
CreateEventDispatcherHook(type, GetConfigurationManager().events, handler);
|
||||
}
|
||||
|
@ -1 +1,2 @@
|
||||
export * from './communication';
|
||||
export * from './configuration';
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetAvatarRenderManager } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useAvatarEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.avatar.events, handler);
|
||||
CreateEventDispatcherHook(type, GetAvatarRenderManager().events, handler);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetNitroInstance } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useCameraEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.cameraManager.events, handler);
|
||||
CreateEventDispatcherHook(type, GetNitroInstance().cameraManager.events, handler);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
export * from './avatar';
|
||||
export * from './camera';
|
||||
export * from './communication';
|
||||
export * from './localization';
|
||||
export * from './main-event';
|
||||
export * from './room';
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetNitroInstance } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useLocalizationEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.localization.events, handler);
|
||||
CreateEventDispatcherHook(type, GetNitroInstance().localization.events, handler);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { Nitro, NitroEvent } from 'nitro-renderer';
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../../../api';
|
||||
import { CreateEventDispatcherHook, DispatchEventHook } from '../event-dispatcher.base';
|
||||
|
||||
export function useMainEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.events, handler);
|
||||
CreateEventDispatcherHook(type, GetNitroInstance().events, handler);
|
||||
}
|
||||
|
||||
export function dispatchMainEvent(event: NitroEvent): void
|
||||
{
|
||||
DispatchEventHook(Nitro.instance.events, event);
|
||||
DispatchEventHook(GetNitroInstance().events, event);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { GetRoomEngine } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useRoomEngineEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.roomEngine.events, handler);
|
||||
CreateEventDispatcherHook(type, GetRoomEngine().events, handler);
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { Nitro, NitroEvent } from 'nitro-renderer';
|
||||
import { NitroEvent } from 'nitro-renderer';
|
||||
import { GetRoomSessionManager } from '../../../../api';
|
||||
import { CreateEventDispatcherHook } from '../../event-dispatcher.base';
|
||||
|
||||
export function useRoomSessionManagerEvent(type: string, handler: (event: NitroEvent) => void): void
|
||||
{
|
||||
CreateEventDispatcherHook(type, Nitro.instance.roomSessionManager.events, handler);
|
||||
CreateEventDispatcherHook(type, GetRoomSessionManager().events, handler);
|
||||
}
|
||||
|
@ -1,13 +1,6 @@
|
||||
export * from './events';
|
||||
export * from './events/core';
|
||||
export * from './events/core/configuration';
|
||||
export * from './events/nitro';
|
||||
export * from './events/nitro/avatar';
|
||||
export * from './events/nitro/camera';
|
||||
export * from './events/nitro/communication';
|
||||
export * from './events/nitro/localization';
|
||||
export * from './events/nitro/room';
|
||||
export * from './events/nitro/session';
|
||||
export * from './events/ui';
|
||||
export * from './messages';
|
||||
export * from './UseMountEffect';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IMessageComposer, IMessageEvent, MessageEvent } from 'nitro-renderer';
|
||||
import { Nitro } from 'nitro-renderer/src/nitro/Nitro';
|
||||
import { useEffect } from 'react';
|
||||
import { GetCommunication, GetConnection } from '../../api';
|
||||
|
||||
export function CreateMessageHook(eventType: typeof MessageEvent, handler: (event: IMessageEvent) => void): void
|
||||
{
|
||||
@ -9,13 +9,13 @@ export function CreateMessageHook(eventType: typeof MessageEvent, handler: (even
|
||||
//@ts-ignore
|
||||
const event = new eventType(handler);
|
||||
|
||||
Nitro.instance.communication.registerMessageEvent(event);
|
||||
GetCommunication().registerMessageEvent(event);
|
||||
|
||||
return () => Nitro.instance.communication.removeMessageEvent(event);
|
||||
return () => GetCommunication().removeMessageEvent(event);
|
||||
}, [ eventType, handler ]);
|
||||
}
|
||||
|
||||
export function SendMessageHook(event: IMessageComposer<unknown[]>): void
|
||||
{
|
||||
Nitro.instance.communication.connection.send(event);
|
||||
GetConnection().send(event);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Nitro } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../api';
|
||||
|
||||
export function LocalizeBadgeName(key: string): string
|
||||
{
|
||||
return Nitro.instance.localization.getBadgeName(key);
|
||||
return GetNitroInstance().localization.getBadgeName(key);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Nitro } from 'nitro-renderer';
|
||||
import { GetNitroInstance } from '../api';
|
||||
|
||||
export function LocalizeText(key: string, parameters: string[] = null, replacements: string[] = null): string
|
||||
{
|
||||
return Nitro.instance.getLocalizationWithParameters(key, parameters, replacements);
|
||||
return GetNitroInstance().getLocalizationWithParameters(key, parameters, replacements);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user