1
0
Fork 0

Reworked the BrowserIPC module

master
WolverinDEV 2021-02-20 17:46:16 +01:00
parent 1774b52504
commit 34e371ce64
3 changed files with 37 additions and 5 deletions

View File

@ -23,11 +23,14 @@ export function createErrorResult<T>(result: MessageCommandErrorResult) : Action
}
}
export function createResult<T>(result: T) : ActionResult<T> {
export function createResult() : ActionResult<void>;
export function createResult<T>(result: T) : ActionResult<T>;
export function createResult(result?) : ActionResult<any> {
return {
status: "success",
result: result,
unwrap(): T {
unwrap() {
return result;
}
}

View File

@ -1,12 +1,13 @@
import {ClientServices} from "./ClientService";
import {ActionResult, createErrorResult, createResult} from "./Action";
import {InviteAction} from "./Messages";
export type InviteLinkInfo = {
linkId: string,
timestampCreated: number,
timestampDeleted: number,
timestampExpired: number,
amountViewed: number,
amountClicked: number,
@ -14,6 +15,7 @@ export type InviteLinkInfo = {
propertiesConnect: {[key: string]: string},
propertiesInfo: {[key: string]: string},
};
export class ClientServiceInvite {
private readonly handle: ClientServices;
@ -73,9 +75,29 @@ export class ClientServiceInvite {
timestampCreated: notifyResult.value.timestamp_created,
timestampDeleted: notifyResult.value.timestamp_deleted,
timestampExpired: notifyResult.value.timestamp_expired,
propertiesConnect: notifyResult.value.properties_connect,
propertiesInfo: notifyResult.value.properties_info,
});
}
async logAction<A extends Exclude<InviteAction, InviteAction & { payload }>["type"]>(linkId: string, action: A) : Promise<ActionResult<void>>;
async logAction<A extends Extract<InviteAction, InviteAction & { payload }>["type"]>(linkId: string, action: A, value: Extract<InviteAction, { payload, type: A }>["payload"]) : Promise<ActionResult<void>>;
async logAction(linkId: string, action, payload?) : Promise<ActionResult<void>> {
/* TODO: If the session isn't available post the updates later on */
const connection = this.handle.getConnection();
const result = await connection.executeCommand("InviteLogAction", {
link_id: linkId,
action: (arguments.length >= 3 ? { type: action, payload: payload } : { type: action }) as any
});
if(result.type !== "Success") {
return createErrorResult(result);
}
return createResult();
}
}

View File

@ -43,6 +43,14 @@ export type MessageNotify =
| { type: "NotifyInviteInfo"; payload: NotifyInviteInfo };
/* Some command data payload */
export type InviteAction =
| { type: "OpenTeaClientProtocol" }
| { type: "RedirectWebClient" }
| { type: "ConnectAttempt" }
| { type: "ConnectSuccess" }
| { type: "ConnectFailure"; payload: { reason: string } }
| { type: "ConnectNoAction"; payload: { reason: string } };
export enum ClientSessionType {
WebClient = 0,
TeaClient = 1,
@ -58,7 +66,7 @@ export type CommandSessionUpdateLocale = { ip_country: string | null; select
export type CommandInviteQueryInfo = { link_id: string; register_view: boolean };
export type CommandInviteLogAction = { click_type: number };
export type CommandInviteLogAction = { link_id: string; action: InviteAction };
export type CommandInviteCreate = { new_link: boolean; properties_connect: { [key: string]: string }; properties_info: { [key: string]: string }; timestamp_expired: number };
@ -68,4 +76,3 @@ export type NotifyClientsOnline = { users_online: { [key: number]: number };
export type NotifyInviteCreated = { link_id: string; admin_token: string | null };
export type NotifyInviteInfo = { link_id: string; timestamp_created: number; timestamp_deleted: number; timestamp_expired: number; amount_viewed: number; amount_clicked: number; properties_connect: { [key: string]: string }; properties_info: { [key: string]: string } };