import type { Emitter, IDisposable } from "@codesandbox/pitcher-common"; import type { SandpackMessage } from "@codesandbox/sandpack-client"; import type { States } from "class-states"; export type ChannelData = Record; export type ChannelErrorEvent = { code: number; message: string; }; export type ChannelMessageEvent = { clientId: string; isUser: boolean; data: T; }; export type ChannelState = { hasSubscribed: true; disposeNotificationListeners: () => void; } | { hasSubscribed: false; }; export interface IChannel extends IDisposable { state: ChannelState; subscribers: Set; onError: Emitter["event"]; onSubscribe: Emitter["event"]; onUnsubscribe: Emitter["event"]; onMessage: Emitter>["event"]; subscribe(): Promise; unsubscribe(): Promise; sendAll(data: T): Promise<{ clients: string[]; }>; send(subscribers: Set, data: T): Promise<{ clients: string[]; }>; resync(): void; } export interface IChannelClient { getChannel(name: string): IChannel; getFollowChannel(name: string): IFollowChannel; getCommandChannel(name: string): ICommandChannel; getSharedChannel(name: string): ISharedChannel; } export type FollowingState = { state: "FOLLOWING"; clientId: string; } | { state: "NOT_FOLLOWING"; }; export type FollowersState = { state: "FOLLOWERS"; clientIds: string[]; } | { state: "NO_FOLLOWERS"; }; export interface IFollowChannel extends IDisposable { onFollowerJoin: IChannel["onSubscribe"]; onFollowerLeave: IChannel["onUnsubscribe"]; onFollowMessage: Emitter>["event"]; onUnfollow: Emitter["event"]; state: { following: States; followers: States; }; sendAllFollowers(message: T): Promise<{ clients: string[]; }> | undefined; sendFollower(clientId: string, message: T): Promise<{ clients: string[]; }> | undefined; follow(clientId: string): void; unfollow(): void; resync(): void; } export type CommandState = { state: "SOLO"; } | { state: "MULTIPLAYER"; channels: Record>; }; export interface ICommandChannel extends IDisposable { state: States>; /** * Messages from your other clients */ onMessage(cb: (message: ChannelMessageEvent) => void): IDisposable; /** * Send to your other clients */ send(message: T): void; resync(): void; } export interface ISharedChannel extends IDisposable { onJoin(cb: (clientId: string) => void): void; onLeave(cb: (clientId: string) => void): void; sendAll(message: T): void; send(clientId: string, message: T): void; onMessage(cb: (message: ChannelMessageEvent) => void): IDisposable; resync(): void; } export interface ISandpackChannel extends IDisposable { send(message: SandpackMessage): void; onMessage(cb: (message: SandpackMessage) => void): IDisposable; resync(): void; } //# sourceMappingURL=IChannelClient.d.ts.map