Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp
1.8 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-or-later

export const DESKTOP_HANDOFF_CHANNELS = Object.freeze({
	initiate: 'desktop-handoff:initiate',
	status: 'desktop-handoff:status',
} as const);

export const DesktopHandoffStatus = Object.freeze({
	PENDING: 'pending',
	EXPIRED: 'expired',
	DENIED: 'denied',
	COMPLETED: 'completed',
} as const);

export type DesktopHandoffStatus = (typeof DesktopHandoffStatus)[keyof typeof DesktopHandoffStatus];

export const DesktopHandoffReturnMethod = Object.freeze({
	DEEP_LINK: 'deep_link',
	CODE: 'code',
} as const);

export type DesktopHandoffReturnMethod = (typeof DesktopHandoffReturnMethod)[keyof typeof DesktopHandoffReturnMethod];

export interface DesktopHandoffInstance {
	readonly apiEndpoint: string;
	readonly apiVersion: number;
	readonly webAppEndpoint: string;
}

export interface DesktopHandoffSession {
	readonly instance: DesktopHandoffInstance;
	readonly code: string;
	readonly expiresAt: string;
	readonly returnMethod: DesktopHandoffReturnMethod;
}

export interface DesktopHandoffUser {
	readonly username: string;
	readonly discriminator: string;
	readonly global_name: string | null;
	readonly avatar: string | null;
	readonly email?: string | null;
}

interface DesktopHandoffIncompleteResult {
	readonly status:
		| typeof DesktopHandoffStatus.PENDING
		| typeof DesktopHandoffStatus.EXPIRED
		| typeof DesktopHandoffStatus.DENIED;
}

interface DesktopHandoffCompletedResult {
	readonly status: typeof DesktopHandoffStatus.COMPLETED;
	readonly token: string;
	readonly userId: string;
	readonly user: DesktopHandoffUser | null;
}

export type DesktopHandoffStatusResult = DesktopHandoffIncompleteResult | DesktopHandoffCompletedResult;

export interface DesktopHandoffAPI {
	initiate: (instance: DesktopHandoffInstance) => Promise<DesktopHandoffSession>;
	status: (code: string) => Promise<DesktopHandoffStatusResult>;
}