2022-09-04 01:06:07 +03:00
|
|
|
import { Context } from "../context/context";
|
2022-09-05 08:25:12 +03:00
|
|
|
import { ConnectionState } from "../rtmt/rtmt";
|
2022-09-04 01:06:07 +03:00
|
|
|
import notyf from "./Notyf";
|
2022-07-14 08:53:26 +03:00
|
|
|
|
|
|
|
|
export default class Util {
|
|
|
|
|
public static range(size: number) {
|
2022-09-04 01:06:07 +03:00
|
|
|
var ans: number[] = [];
|
2022-07-14 08:53:26 +03:00
|
|
|
for (let i = 0; i < size; i++) {
|
|
|
|
|
ans.push(i);
|
|
|
|
|
}
|
|
|
|
|
return ans;
|
|
|
|
|
}
|
2022-09-04 01:06:07 +03:00
|
|
|
|
|
|
|
|
public static checkConnectionAndMaybeAlert(context: Context): boolean {
|
|
|
|
|
if (context.rtmt.connectionState !== "connected") {
|
|
|
|
|
notyf.error(context.texts.ConnectionLost);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-05 08:25:12 +03:00
|
|
|
|
|
|
|
|
public static getTextByConnectionState(context: Context, connectionState: ConnectionState): string {
|
|
|
|
|
const map: { [key: string]: string } = {
|
|
|
|
|
connecting: context.texts.Connecting,
|
|
|
|
|
connected: context.texts.Connected,
|
|
|
|
|
error: context.texts.CannotConnect,
|
|
|
|
|
closed: context.texts.ConnectingAgain,
|
|
|
|
|
reconnecting: context.texts.ConnectingAgain,
|
|
|
|
|
};
|
|
|
|
|
return map[connectionState];
|
|
|
|
|
}
|
2022-07-14 08:53:26 +03:00
|
|
|
}
|