Skip to content

Commit

Permalink
Add more types
Browse files Browse the repository at this point in the history
  • Loading branch information
thyal committed Mar 11, 2024
1 parent a0a1907 commit 649c32b
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 58 deletions.
34 changes: 26 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,32 @@ const external = [...dependencies, ...peerDependencies];
module.exports = [
// Esm build of lib, to be used with bundlers
{
input: { webrtc: "src/webrtc/index.ts", utils: "src/utils/index.ts", model: "src/model/index.ts" },

output: [
{
format: "esm", // set ES modules
dir: "dist", // indicate not create a single-file
},
],
input: "src/webrtc/index.ts",
output: {
file: "dist/webrtc/index.esm.js",
format: "esm",
exports: "named",
},
plugins,
external,
},
{
input: "src/utils/index.ts",
output: {
file: "dist/utils/index.esm.js",
format: "esm",
exports: "named",
},
plugins,
external,
},
{
input: "src/model/index.ts",
output: {
file: "dist/model/index.esm.js",
format: "esm",
exports: "named",
},
plugins,
external,
},
Expand Down
4 changes: 3 additions & 1 deletion src/model/connectionStatusConstants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const EVENTS = {
import { RtcEvents } from "src/webrtc/types";

export const EVENTS: Record<string, keyof RtcEvents> = {
CLIENT_CONNECTION_STATUS_CHANGED: "client_connection_status_changed",
STREAM_ADDED: "stream_added",
RTC_MANAGER_CREATED: "rtc_manager_created",
Expand Down
3 changes: 2 additions & 1 deletion src/utils/ServerSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { io } from "socket.io-client";
import adapter from "webrtc-adapter";
import { ReconnectManager } from "./ReconnectManager";
import { PROTOCOL_RESPONSES } from "../model/protocol";
import { RtcManager } from "src/webrtc";

const DEFAULT_SOCKET_PATH = "/protocol/socket.io/v4";

Expand Down Expand Up @@ -73,7 +74,7 @@ export class ServerSocket {
});
}

setRtcManager(rtcManager?: any) {
setRtcManager(rtcManager?: RtcManager) {
if (this._reconnectManager) {
this._reconnectManager.rtcManager = rtcManager;
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export * from "./optimalBitrate";
export * from "./ReconnectManager";
export * from "./ServerSocket";
export * from "./transportSettings";
export { default as fromLocation } from "./urls";
export * from "./types";
export * from "./urls";
209 changes: 209 additions & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
export interface Credentials {
credentials: {
uuid: string;
};
hmac: string;
userId: string;
}

/*
Socket
*/

export interface SocketConf {
host?: string;
path?: string;
reconnectionDelay?: number;
reconnectoinDelayMax?: number;
timeout?: number;
autoConnect?: boolean;
}

export interface SocketManager {
on: (eventName: string, callback: (args: unknown) => void) => void;
}

export interface ClientRole {
roleName: string;
}

export interface SignalKnocker {
clientId: string;
displayName: string | null;
imageUrl: string | null;
liveVideo: boolean;
userAvatarUrl: string | null;
userId: string | null;
}

export interface SignalClient {
displayName: string;
id: string;
streams: string[];
isAudioEnabled: boolean;
isVideoEnabled: boolean;
role: ClientRole;
startedCloudRecordingAt: string | null;
}

export interface AudioEnabledEvent {
clientId: string;
isAudioEnabled: boolean;
}

export interface ChatMessage {
id: string;
messageType: "text";
roomName: string;
senderId: string;
sig: string;
text: string;
timestamp: string;
userId: string;
}

export interface CloudRecordingStartedEvent {
error?: string;
startedAt?: string;
}

export interface ClientLeftEvent {
clientId: string;
}
export interface NewClientEvent {
client: SignalClient;
room?: {
session: {
createdAt: string;
id: string;
} | null;
};
}

export interface ClientKickedEvent {
clientId: string;
}

export interface KnockerLeftEvent {
clientId: string;
}

export interface KnockAcceptedEvent {
clientId: string;
metadata: {
roomKey: string;
roomName: string;
};
resolution: "accepted";
}

export interface KnockRejectedEvent {
clientId: string;
resolution: "rejected";
}

export interface RoomJoinedEvent {
error?: string;
isLocked: boolean;
room?: {
clients: SignalClient[];
knockers: SignalKnocker[];
session: {
createdAt: string;
id: string;
} | null;
};
selfId: string;
}

export interface RoomKnockedEvent {
clientId: string;
displayName: string | null;
imageUrl: string | null;
liveVideo: boolean;
}

export interface RoomSessionEndedEvent {
roomSessionId: string;
}

export interface ScreenshareStartedEvent {
clientId: string;
streamId: string;
hasAudioTrack: boolean;
}

export interface ScreenshareStoppedEvent {
clientId: string;
streamId: string;
}

export interface VideoEnabledEvent {
clientId: string;
isVideoEnabled: boolean;
}

export interface ClientMetadataReceivedEvent {
type: string;
payload: { clientId: string; displayName: string };
}

export interface SignalEvents {
audio_enabled: AudioEnabledEvent;
client_left: ClientLeftEvent;
client_kicked: ClientKickedEvent;
client_metadata_received: ClientMetadataReceivedEvent;
cloud_recording_started: CloudRecordingStartedEvent;
cloud_recording_stopped: void;
chat_message: ChatMessage;
connect: void;
connect_error: void;
device_identified: void;
disconnect: void;
knock_handled: KnockAcceptedEvent | KnockRejectedEvent;
knocker_left: KnockerLeftEvent;
new_client: NewClientEvent;
room_joined: RoomJoinedEvent;
room_knocked: RoomKnockedEvent;
room_left: void;
room_session_ended: RoomSessionEndedEvent;
screenshare_started: ScreenshareStartedEvent;
screenshare_stopped: ScreenshareStoppedEvent;
streaming_stopped: void;
video_enabled: VideoEnabledEvent;
}

export interface IdentifyDeviceRequest {
deviceCredentials: Credentials;
}

export interface JoinRoomRequest {
config: { isAudioEnabled: boolean; isVideoEnabled: boolean };
organizationId: string;
roomName: string;
displayName?: string;
}

export interface KnockRoomRequest {
displayName: string;
imageUrl: string | null;
kickFromOtherRooms: boolean;
liveVideo: boolean;
organizationId: string;
roomKey: string | null;
roomName: string;
}

export interface SignalRequests {
chat_message: { text: string };
enable_audio: { enabled: boolean };
enable_video: { enabled: boolean };
handle_knock: { action: "accept" | "reject"; clientId: string; response: unknown };
identify_device: IdentifyDeviceRequest;
join_room: JoinRoomRequest;
knock_room: KnockRoomRequest;
leave_room: void;
send_client_metadata: { type: string; payload: { displayName?: string } };
start_recording: { recording: string };
stop_recording: void;
}
Loading

0 comments on commit 649c32b

Please sign in to comment.