UNPKG

open-collaboration-protocol

Version:

Open Collaboration Protocol implementation, part of the Open Collaboration Tools project

85 lines 3.3 kB
import { MessageTransportProvider } from './transport/transport.js'; import { ProtocolBroadcastConnection } from './connection.js'; import * as types from './types.js'; import { Info } from './utils/info.js'; export type Fetch = (url: string, options?: FetchRequestOptions) => Promise<FetchResponse>; export interface ConnectionProviderOptions { url: string; userToken?: string; client?: string; protocolVersion?: string; fetch: Fetch; /** * Client specific handler function to handle authentication. * * @param token The token supplied by the server to identify the authentication process. * @param authenticationMetadata The authentication metadata supplied by the server. * @returns Whether or not the authentication was successfully started. * `false` can be returned in case the browser fails to open the URL or the user does not supply a user name. * In that case the authentication process will be cancelled. */ authenticationHandler: (token: string, authenticationMetadata: types.AuthMetadata) => Promise<boolean>; transports: MessageTransportProvider[]; useCookieAuth?: boolean; } export interface FetchRequestOptions { method?: string; headers?: Record<string, string>; signal?: AbortSignal | null; credentials?: 'include' | 'same-origin' | 'omit'; body?: string; } export interface FetchResponse { status?: number; ok: boolean; json(): Promise<any>; text(): Promise<string>; } export interface LoginOptions { abortSignal?: AbortSignal; reporter?: ResponseReporter; } export interface JoinRoomOptions { roomId: string; reporter?: ResponseReporter; abortSignal?: AbortSignal; } export interface CreateRoomOptions { reporter?: ResponseReporter; abortSignal?: AbortSignal; } export type ResponseReporter = (info: Info) => void; export declare class ConnectionProvider { private options; private fetch; private protocolVersion; constructor(options: ConnectionProviderOptions); protected userAuthToken?: string; protected roomAuthToken?: string; get authToken(): string | undefined; protected getUrl(path: string): string; /** * @returns the auth token if the authentication or undefined when using cookie based authentication */ login(options: LoginOptions): Promise<string>; private readonly cookieAuthPollOptions; private pollLogin; /** * only neccessary for cookie based authentication to delete the cookie. * If not using cookie based authentication, just deletes the JWT. * Please ensure yourself it is not saved in local storage or similar. */ logout(): Promise<void>; ensureCompatibility(): Promise<void>; validate(): Promise<boolean>; createRoom(options: CreateRoomOptions): Promise<types.CreateRoomResponse>; joinRoom(options: JoinRoomOptions): Promise<types.JoinRoomResponse>; pollJoin(joinToken: string, options: JoinRoomOptions): Promise<types.JoinRoomResponse>; private readError; connect(roomAuthToken: string, host?: types.Peer): Promise<ProtocolBroadcastConnection>; private getMetaData; private findFitting; private mergeAbortSignals; private getAuthHeader; } //# sourceMappingURL=connection-provider.d.ts.map