nitro-renderer/packages/utils/src/HabboWebTools.ts

339 lines
7.9 KiB
TypeScript
Raw Normal View History

2024-03-20 02:53:17 +01:00
import { LegacyExternalInterface } from './LegacyExternalInterface';
import { NitroLogger } from './NitroLogger';
2021-03-17 03:02:09 +01:00
export class HabboWebTools
{
public static ADVERTISEMENT: string = 'advertisement';
2022-03-03 01:21:30 +01:00
public static OPENLINK: string = 'openlink';
public static OPENROOM: string = 'openroom';
2021-03-17 03:02:09 +01:00
public static logEventLog(data: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('logEventLog', data);
}
}
catch (e)
{
NitroLogger.log('External interface not working, failed to log event log.');
}
}
public static openPage(pageUrl: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openPage', pageUrl);
}
else
{
NitroLogger.log('External interface not available, openPage failed.');
}
}
catch (e)
{
2022-11-08 22:44:41 +01:00
NitroLogger.log('Failed to open web page', pageUrl);
2021-03-17 03:02:09 +01:00
}
}
2021-07-22 06:29:34 +02:00
public static openWebPage(pageUrl: string): void
{
window.open(pageUrl);
}
2021-03-17 03:02:09 +01:00
public static sendHeartBeat(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('heartBeat');
}
}
catch (e)
{
NitroLogger.log('Failed to send heartbeat');
}
}
public static openWebPageAndMinimizeClient(pageUrl: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
HabboWebTools.openPage(pageUrl);
}
}
catch (e)
{
2022-11-08 22:44:41 +01:00
NitroLogger.log('Failed to open web page', pageUrl);
2021-03-17 03:02:09 +01:00
}
}
public static closeWebPageAndRestoreClient(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('closeWebPageAndRestoreClient');
}
}
catch (e)
{
NitroLogger.log('Failed to close web page and restore client!');
}
}
2022-10-30 03:59:33 +01:00
public static openHabblet(name: string, param: string = null): void
2021-03-17 03:02:09 +01:00
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openHabblet', name, param);
}
}
catch (e)
{
2022-11-08 22:44:41 +01:00
NitroLogger.log('Failed to open Habblet', name);
2021-03-17 03:02:09 +01:00
}
}
2022-10-30 03:59:33 +01:00
public static closeHabblet(name: string, param: string = null): void
2021-03-17 03:02:09 +01:00
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('closeHabblet', name, param);
}
}
catch (e)
{
2022-11-08 22:44:41 +01:00
NitroLogger.log('Failed to close Habblet', name);
2021-03-17 03:02:09 +01:00
}
}
public static send(reasonCode: number, reasonString: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('disconnect', reasonCode, reasonString);
}
}
catch (e)
{
NitroLogger.log('Failed to close send ');
}
}
public static showGame(gameUrl: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.callGame('showGame', gameUrl);
}
}
catch (e)
{
2022-11-08 22:44:41 +01:00
NitroLogger.log('Failed to open game', e);
2021-03-17 03:02:09 +01:00
}
}
public static hideGame(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.callGame('hideGame');
}
}
catch (e)
{
NitroLogger.log('Failed to hide game');
}
}
public static open(url: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openExternalLink', escape(url));
}
else
{
NitroLogger.log(('External interface not available. Could not request to open: ' + url));
}
}
catch (e)
{
NitroLogger.log(('External interface not working. Could not request to open: ' + url));
}
}
public static roomVisited(roomId: number): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('roomVisited', roomId);
}
else
{
NitroLogger.log('External interface not available. Could not store last room visit.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not store last room visit.');
}
}
public static openMinimail(target: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openMinimail', target);
}
else
{
NitroLogger.log('External interface not available. Could not open minimail.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not open minimail.');
}
}
public static openNews(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openNews');
}
else
{
NitroLogger.log('External interface not available. Could not open news.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not open news.');
}
}
public static closeNews(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('closeNews');
}
else
{
NitroLogger.log('External interface not available. Could not close news.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not close news.');
}
}
public static openAvatars(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openAvatars');
}
else
{
NitroLogger.log('External interface not available. Could not open avatars.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not open avatars.');
}
}
public static openRoomEnterAd(): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('openRoomEnterAd');
}
else
{
NitroLogger.log('External interface not available. Could not open roomenterad.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not open roomenterad.');
}
}
public static updateFigure(figure: string): void
{
try
{
2022-11-08 22:50:16 +01:00
if(LegacyExternalInterface.available)
2021-03-17 03:02:09 +01:00
{
LegacyExternalInterface.call('updateFigure', figure);
}
else
{
NitroLogger.log('External interface not available. Could not update figure.');
}
}
catch (e)
{
NitroLogger.log('External interface not working. Could not update figure.');
}
}
2021-07-22 06:29:34 +02:00
}