@afosecure/meetingsdk 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +253 -0
- package/dist/index.d.mts +210 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +1030 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +996 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ADELAJA OLUWATOBA
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
# 📹 @afosecure/meetingsdk — React Video Meeting SDK
|
|
2
|
+
|
|
3
|
+
A modern, lightweight React SDK for building peer-to-peer video communication applications using WebRTC. Designed with a clean, composable API and reactive state management.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- WebRTC peer-to-peer video (no central media server required)
|
|
10
|
+
- React Hooks API for seamless integration
|
|
11
|
+
- Reactive state system for participants & streams
|
|
12
|
+
- Lightweight core optimized for performance
|
|
13
|
+
- Flexible WebSocket signaling backend support
|
|
14
|
+
- Full TypeScript support
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @afosecure/meetingsdk
|
|
22
|
+
# or
|
|
23
|
+
yarn add @afosecure/meetingsdk
|
|
24
|
+
# or
|
|
25
|
+
pnpm add @afosecure/meetingsdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
### 1. Initialize SDK
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { useState } from "react";
|
|
36
|
+
import {
|
|
37
|
+
MeetingProvider,
|
|
38
|
+
MeetingState,
|
|
39
|
+
VideoSDKCore,
|
|
40
|
+
} from "@afosecure/meetingsdk";
|
|
41
|
+
|
|
42
|
+
function App() {
|
|
43
|
+
const [core] = useState(
|
|
44
|
+
() =>
|
|
45
|
+
new VideoSDKCore({
|
|
46
|
+
onTrack: (_, peerId) => {
|
|
47
|
+
console.log("📹 Received stream from:", peerId);
|
|
48
|
+
},
|
|
49
|
+
onUserJoined: (participant) => {
|
|
50
|
+
console.log("👤 User joined:", participant.name);
|
|
51
|
+
},
|
|
52
|
+
onUserLeft: (userId) => {
|
|
53
|
+
console.log("👤 User left:", userId);
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<MeetingProvider core={core}>
|
|
60
|
+
<VideoCall />
|
|
61
|
+
</MeetingProvider>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default App;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### 2. Basic Video Call
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { useRef, useState } from "react";
|
|
74
|
+
import { useMeeting, useParticipants } from "@afosecure/meetingsdk";
|
|
75
|
+
|
|
76
|
+
function VideoCall() {
|
|
77
|
+
const { join, startLocalStream, leave, localParticipant } = useMeeting();
|
|
78
|
+
const participants = useParticipants();
|
|
79
|
+
const localVideoRef = useRef<HTMLVideoElement>(null);
|
|
80
|
+
|
|
81
|
+
const [roomId, setRoomId] = useState("");
|
|
82
|
+
const [name, setName] = useState("");
|
|
83
|
+
|
|
84
|
+
const handleJoin = async () => {
|
|
85
|
+
if (!localVideoRef.current) return;
|
|
86
|
+
|
|
87
|
+
await startLocalStream(localVideoRef.current, name);
|
|
88
|
+
await join(roomId, name);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div>
|
|
93
|
+
{!localParticipant ? (
|
|
94
|
+
<>
|
|
95
|
+
<input value={name} onChange={(e) => setName(e.target.value)} />
|
|
96
|
+
<input value={roomId} onChange={(e) => setRoomId(e.target.value)} />
|
|
97
|
+
<button onClick={handleJoin}>Join Meeting</button>
|
|
98
|
+
</>
|
|
99
|
+
) : (
|
|
100
|
+
<>
|
|
101
|
+
<video ref={localVideoRef} autoPlay muted />
|
|
102
|
+
<button onClick={leave}>Leave</button>
|
|
103
|
+
|
|
104
|
+
{participants.map((p) => (
|
|
105
|
+
<div key={p.id}>{p.name}</div>
|
|
106
|
+
))}
|
|
107
|
+
</>
|
|
108
|
+
)}
|
|
109
|
+
</div>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## Core Concepts
|
|
117
|
+
|
|
118
|
+
### MeetingState
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const state = new MeetingState();
|
|
122
|
+
|
|
123
|
+
state.getParticipants();
|
|
124
|
+
|
|
125
|
+
state.subscribe(() => {
|
|
126
|
+
console.log("updated");
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
### VideoSDKCore
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
const core = new VideoSDKCore(state, {
|
|
136
|
+
onTrack: (stream, peerId) => {},
|
|
137
|
+
onUserJoined: (p) => {},
|
|
138
|
+
onUserLeft: (id) => {},
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Hooks API
|
|
145
|
+
|
|
146
|
+
### useMeeting()
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
const { join, startLocalStream, leave, localParticipant, meetingId } =
|
|
150
|
+
useMeeting();
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### useParticipants()
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
const participants = useParticipants();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
### useRemoteVideo()
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
const ref = useRemoteVideo(participantId);
|
|
167
|
+
|
|
168
|
+
return <video ref={ref} autoPlay />;
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### useLocalStream()
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
const stream = useLocalStream();
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
### useStreams()
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const streams = useStreams();
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Complete Example
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
export default function App() {
|
|
193
|
+
const [state] = useState(() => new MeetingState());
|
|
194
|
+
|
|
195
|
+
const [core] = useState(
|
|
196
|
+
() =>
|
|
197
|
+
new VideoSDKCore(state, {
|
|
198
|
+
onTrack: () => {},
|
|
199
|
+
onUserJoined: () => {},
|
|
200
|
+
onUserLeft: () => {},
|
|
201
|
+
}),
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<MeetingProvider core={core}>
|
|
206
|
+
<VideoCallContent />
|
|
207
|
+
</MeetingProvider>
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Server Requirements
|
|
215
|
+
|
|
216
|
+
Your WebSocket server must support:
|
|
217
|
+
|
|
218
|
+
### Client → Server
|
|
219
|
+
|
|
220
|
+
- JOIN
|
|
221
|
+
- OFFER
|
|
222
|
+
- ANSWER
|
|
223
|
+
- ICE
|
|
224
|
+
|
|
225
|
+
### Server → Client
|
|
226
|
+
|
|
227
|
+
- EXISTING_USERS
|
|
228
|
+
- USER_JOINED
|
|
229
|
+
- USER_LEFT
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Performance Tips
|
|
234
|
+
|
|
235
|
+
- Stop media tracks on leave
|
|
236
|
+
- Memoize participant components
|
|
237
|
+
- Use multiple STUN servers
|
|
238
|
+
- Avoid re-rendering video elements
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Browser Support
|
|
243
|
+
|
|
244
|
+
- Chrome 54+
|
|
245
|
+
- Firefox 55+
|
|
246
|
+
- Safari 11+
|
|
247
|
+
- Edge 79+
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## 📄 License
|
|
252
|
+
|
|
253
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import react__default from 'react';
|
|
4
|
+
|
|
5
|
+
type Events = {
|
|
6
|
+
onMicToggled?: (peerId: string, enabled: boolean) => void;
|
|
7
|
+
onError?: (err: SDKError) => void;
|
|
8
|
+
onCamToggled?: (peerId: string, enabled: boolean) => void;
|
|
9
|
+
onTrack?: (stream: MediaStream, peerId: string) => void;
|
|
10
|
+
onScreenTrack?: (stream: MediaStream, peerId: string) => void;
|
|
11
|
+
onUserJoined?: (p: Participant) => void;
|
|
12
|
+
onUserLeft?: (id: string) => void;
|
|
13
|
+
onChatMessage?: (msg: ChatMessage) => void;
|
|
14
|
+
onScreenShareStarted?: (peerId: string, stream: MediaStream) => void;
|
|
15
|
+
onScreenShareStopped?: (peerId: string) => void;
|
|
16
|
+
onMuteStateChanged?: (peerId: string, kind: "audio" | "video", muted: boolean) => void;
|
|
17
|
+
};
|
|
18
|
+
type ChatMessage = {
|
|
19
|
+
id: string;
|
|
20
|
+
text: string;
|
|
21
|
+
sender_id: string;
|
|
22
|
+
sender_name?: string;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
reply_to?: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
} | null;
|
|
28
|
+
target?: string | null;
|
|
29
|
+
};
|
|
30
|
+
type Participant = {
|
|
31
|
+
id: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
media?: ParticipantMedia;
|
|
34
|
+
};
|
|
35
|
+
type ParticipantMedia = {
|
|
36
|
+
stream?: MediaStream | null;
|
|
37
|
+
screenStream?: MediaStream | null;
|
|
38
|
+
cameraTrack?: MediaStreamTrack;
|
|
39
|
+
screenTrack?: MediaStreamTrack;
|
|
40
|
+
audioTrack?: MediaStreamTrack;
|
|
41
|
+
micEnabled: boolean;
|
|
42
|
+
camEnabled: boolean;
|
|
43
|
+
isScreenSharing: boolean;
|
|
44
|
+
remoteScreenStreamId?: string;
|
|
45
|
+
};
|
|
46
|
+
type Listener = () => void;
|
|
47
|
+
type ChatInput = {
|
|
48
|
+
message: string;
|
|
49
|
+
reply_to?: {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
} | null;
|
|
53
|
+
target?: string | null;
|
|
54
|
+
};
|
|
55
|
+
type MeetingConfig = {
|
|
56
|
+
roomId: string;
|
|
57
|
+
name: string;
|
|
58
|
+
audioMuted?: boolean;
|
|
59
|
+
videoMuted?: boolean;
|
|
60
|
+
token?: string;
|
|
61
|
+
};
|
|
62
|
+
type PubSubTopic = "SECURE_CHAT";
|
|
63
|
+
type StateScope = "participants" | "localParticipant" | "chat" | "presenter" | `participant:${string}`;
|
|
64
|
+
type SDKError = {
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
roomId?: string | null;
|
|
68
|
+
userId?: string;
|
|
69
|
+
raw?: any;
|
|
70
|
+
recoverable?: boolean;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
declare const useLocalParticipant: () => {
|
|
74
|
+
participant: Participant | null;
|
|
75
|
+
videoRef: (video: HTMLVideoElement | null) => void;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type LocalParticipantPatch = {
|
|
79
|
+
id?: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
media?: Partial<ParticipantMedia>;
|
|
82
|
+
};
|
|
83
|
+
declare class MeetingState {
|
|
84
|
+
participants: Map<string, Participant>;
|
|
85
|
+
localParticipant: Participant | null;
|
|
86
|
+
localStream: MediaStream | null;
|
|
87
|
+
chatMessages: Map<string, ChatMessage>;
|
|
88
|
+
presenterId: string | null;
|
|
89
|
+
private listeners;
|
|
90
|
+
subscribe(scope: StateScope, fn: Listener): () => void;
|
|
91
|
+
notify(scope: StateScope): void;
|
|
92
|
+
setPresenterId(id: string | null): void;
|
|
93
|
+
addParticipant(p: Participant): boolean;
|
|
94
|
+
removeParticipant(id: string): void;
|
|
95
|
+
updateParticipantMedia(id: string, patch: Partial<NonNullable<Participant["media"]>>): void;
|
|
96
|
+
updateLocalParticipant(patch: LocalParticipantPatch): void;
|
|
97
|
+
addChatMessage(msg: ChatMessage): void;
|
|
98
|
+
getChatMessages(): ChatMessage[];
|
|
99
|
+
clearChat(): void;
|
|
100
|
+
getParticipants(): Participant[];
|
|
101
|
+
getParticipant(id: string): Participant | null;
|
|
102
|
+
resetRemoteState(): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare class VideoSDKCore {
|
|
106
|
+
private events;
|
|
107
|
+
private url;
|
|
108
|
+
private ws;
|
|
109
|
+
private peers;
|
|
110
|
+
private initiators;
|
|
111
|
+
private myId;
|
|
112
|
+
private roomId;
|
|
113
|
+
private localStream;
|
|
114
|
+
private screenStream;
|
|
115
|
+
private isScreenSharing;
|
|
116
|
+
private screenSenders;
|
|
117
|
+
private pingInterval;
|
|
118
|
+
private pendingIceCandidates;
|
|
119
|
+
private reconnectAttempts;
|
|
120
|
+
private reconnectTimer?;
|
|
121
|
+
private participantName;
|
|
122
|
+
readonly state: MeetingState;
|
|
123
|
+
private joinResolver?;
|
|
124
|
+
private joinRejecter?;
|
|
125
|
+
private emitError;
|
|
126
|
+
constructor(events?: Events, url?: string);
|
|
127
|
+
initLocal(video: HTMLVideoElement, name: string): Promise<void>;
|
|
128
|
+
connect(roomId: string, name: string): Promise<void>;
|
|
129
|
+
joinMeeting(config: MeetingConfig): Promise<void>;
|
|
130
|
+
/** Expose the roomId without making it fully public */
|
|
131
|
+
getMeetingId(): string | null;
|
|
132
|
+
toggleMic(): void;
|
|
133
|
+
toggleCam(): void;
|
|
134
|
+
private scheduleReconnect;
|
|
135
|
+
private startHeartbeat;
|
|
136
|
+
private stopHeartbeat;
|
|
137
|
+
private reset;
|
|
138
|
+
private handle;
|
|
139
|
+
private createPeer;
|
|
140
|
+
private createOffer;
|
|
141
|
+
private handleOffer;
|
|
142
|
+
private closePeer;
|
|
143
|
+
startScreenShare(): Promise<MediaStream>;
|
|
144
|
+
stopScreenShare(): void;
|
|
145
|
+
sendChatMessage(payload: ChatInput): void;
|
|
146
|
+
disconnect(): void;
|
|
147
|
+
private flushIce;
|
|
148
|
+
private send;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type PubSubHandle = {
|
|
152
|
+
messages: ChatMessage[];
|
|
153
|
+
publish: (input: ChatInput) => void;
|
|
154
|
+
};
|
|
155
|
+
type MeetingContextValue = {
|
|
156
|
+
sdk: VideoSDKCore;
|
|
157
|
+
join: (config: MeetingConfig) => Promise<void>;
|
|
158
|
+
leave: () => void;
|
|
159
|
+
toggleMic: () => void;
|
|
160
|
+
toggleCam: () => void;
|
|
161
|
+
startScreenShare: () => Promise<MediaStream>;
|
|
162
|
+
stopScreenShare: () => void;
|
|
163
|
+
sendMessage: (input: ChatInput) => void;
|
|
164
|
+
meetingId: string | null;
|
|
165
|
+
localParticipant: Participant | null;
|
|
166
|
+
participants: Map<string, Participant>;
|
|
167
|
+
messages: ChatMessage[];
|
|
168
|
+
presenterId: string | null;
|
|
169
|
+
usePubSub: (topic: PubSubTopic) => PubSubHandle;
|
|
170
|
+
onError: (cb: (err: any) => void) => () => void;
|
|
171
|
+
};
|
|
172
|
+
declare const MeetingProvider: ({ config, children, }: {
|
|
173
|
+
config: MeetingConfig;
|
|
174
|
+
children: react__default.ReactNode;
|
|
175
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
176
|
+
declare const useMeetingContext: () => MeetingContextValue;
|
|
177
|
+
|
|
178
|
+
declare const useMeeting: (handlers?: {
|
|
179
|
+
onError?: (err: any) => void;
|
|
180
|
+
}) => {
|
|
181
|
+
sdk: VideoSDKCore;
|
|
182
|
+
join: (config: MeetingConfig) => Promise<void>;
|
|
183
|
+
leave: () => void;
|
|
184
|
+
toggleMic: () => void;
|
|
185
|
+
toggleCam: () => void;
|
|
186
|
+
startScreenShare: () => Promise<MediaStream>;
|
|
187
|
+
stopScreenShare: () => void;
|
|
188
|
+
sendMessage: (input: ChatInput) => void;
|
|
189
|
+
meetingId: string | null;
|
|
190
|
+
localParticipant: Participant | null;
|
|
191
|
+
participants: Map<string, Participant>;
|
|
192
|
+
messages: ChatMessage[];
|
|
193
|
+
presenterId: string | null;
|
|
194
|
+
usePubSub: (topic: PubSubTopic) => {
|
|
195
|
+
messages: ChatMessage[];
|
|
196
|
+
publish: (input: ChatInput) => void;
|
|
197
|
+
};
|
|
198
|
+
onError: (cb: (err: any) => void) => () => void;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
declare const useParticipants: () => Participant[];
|
|
202
|
+
|
|
203
|
+
declare const useRemoteMedia: (participantId: string) => {
|
|
204
|
+
videoRef: react.RefObject<HTMLVideoElement | null>;
|
|
205
|
+
audioRef: react.RefObject<HTMLAudioElement | null>;
|
|
206
|
+
isCamActive: boolean;
|
|
207
|
+
isMicEnabled: boolean;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export { type ChatInput, MeetingProvider, MeetingState, type Participant, VideoSDKCore, useLocalParticipant, useMeeting, useMeetingContext, useParticipants, useRemoteMedia };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import react__default from 'react';
|
|
4
|
+
|
|
5
|
+
type Events = {
|
|
6
|
+
onMicToggled?: (peerId: string, enabled: boolean) => void;
|
|
7
|
+
onError?: (err: SDKError) => void;
|
|
8
|
+
onCamToggled?: (peerId: string, enabled: boolean) => void;
|
|
9
|
+
onTrack?: (stream: MediaStream, peerId: string) => void;
|
|
10
|
+
onScreenTrack?: (stream: MediaStream, peerId: string) => void;
|
|
11
|
+
onUserJoined?: (p: Participant) => void;
|
|
12
|
+
onUserLeft?: (id: string) => void;
|
|
13
|
+
onChatMessage?: (msg: ChatMessage) => void;
|
|
14
|
+
onScreenShareStarted?: (peerId: string, stream: MediaStream) => void;
|
|
15
|
+
onScreenShareStopped?: (peerId: string) => void;
|
|
16
|
+
onMuteStateChanged?: (peerId: string, kind: "audio" | "video", muted: boolean) => void;
|
|
17
|
+
};
|
|
18
|
+
type ChatMessage = {
|
|
19
|
+
id: string;
|
|
20
|
+
text: string;
|
|
21
|
+
sender_id: string;
|
|
22
|
+
sender_name?: string;
|
|
23
|
+
timestamp: number;
|
|
24
|
+
reply_to?: {
|
|
25
|
+
id: string;
|
|
26
|
+
name: string;
|
|
27
|
+
} | null;
|
|
28
|
+
target?: string | null;
|
|
29
|
+
};
|
|
30
|
+
type Participant = {
|
|
31
|
+
id: string;
|
|
32
|
+
name?: string;
|
|
33
|
+
media?: ParticipantMedia;
|
|
34
|
+
};
|
|
35
|
+
type ParticipantMedia = {
|
|
36
|
+
stream?: MediaStream | null;
|
|
37
|
+
screenStream?: MediaStream | null;
|
|
38
|
+
cameraTrack?: MediaStreamTrack;
|
|
39
|
+
screenTrack?: MediaStreamTrack;
|
|
40
|
+
audioTrack?: MediaStreamTrack;
|
|
41
|
+
micEnabled: boolean;
|
|
42
|
+
camEnabled: boolean;
|
|
43
|
+
isScreenSharing: boolean;
|
|
44
|
+
remoteScreenStreamId?: string;
|
|
45
|
+
};
|
|
46
|
+
type Listener = () => void;
|
|
47
|
+
type ChatInput = {
|
|
48
|
+
message: string;
|
|
49
|
+
reply_to?: {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
} | null;
|
|
53
|
+
target?: string | null;
|
|
54
|
+
};
|
|
55
|
+
type MeetingConfig = {
|
|
56
|
+
roomId: string;
|
|
57
|
+
name: string;
|
|
58
|
+
audioMuted?: boolean;
|
|
59
|
+
videoMuted?: boolean;
|
|
60
|
+
token?: string;
|
|
61
|
+
};
|
|
62
|
+
type PubSubTopic = "SECURE_CHAT";
|
|
63
|
+
type StateScope = "participants" | "localParticipant" | "chat" | "presenter" | `participant:${string}`;
|
|
64
|
+
type SDKError = {
|
|
65
|
+
code: string;
|
|
66
|
+
message: string;
|
|
67
|
+
roomId?: string | null;
|
|
68
|
+
userId?: string;
|
|
69
|
+
raw?: any;
|
|
70
|
+
recoverable?: boolean;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
declare const useLocalParticipant: () => {
|
|
74
|
+
participant: Participant | null;
|
|
75
|
+
videoRef: (video: HTMLVideoElement | null) => void;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type LocalParticipantPatch = {
|
|
79
|
+
id?: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
media?: Partial<ParticipantMedia>;
|
|
82
|
+
};
|
|
83
|
+
declare class MeetingState {
|
|
84
|
+
participants: Map<string, Participant>;
|
|
85
|
+
localParticipant: Participant | null;
|
|
86
|
+
localStream: MediaStream | null;
|
|
87
|
+
chatMessages: Map<string, ChatMessage>;
|
|
88
|
+
presenterId: string | null;
|
|
89
|
+
private listeners;
|
|
90
|
+
subscribe(scope: StateScope, fn: Listener): () => void;
|
|
91
|
+
notify(scope: StateScope): void;
|
|
92
|
+
setPresenterId(id: string | null): void;
|
|
93
|
+
addParticipant(p: Participant): boolean;
|
|
94
|
+
removeParticipant(id: string): void;
|
|
95
|
+
updateParticipantMedia(id: string, patch: Partial<NonNullable<Participant["media"]>>): void;
|
|
96
|
+
updateLocalParticipant(patch: LocalParticipantPatch): void;
|
|
97
|
+
addChatMessage(msg: ChatMessage): void;
|
|
98
|
+
getChatMessages(): ChatMessage[];
|
|
99
|
+
clearChat(): void;
|
|
100
|
+
getParticipants(): Participant[];
|
|
101
|
+
getParticipant(id: string): Participant | null;
|
|
102
|
+
resetRemoteState(): void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
declare class VideoSDKCore {
|
|
106
|
+
private events;
|
|
107
|
+
private url;
|
|
108
|
+
private ws;
|
|
109
|
+
private peers;
|
|
110
|
+
private initiators;
|
|
111
|
+
private myId;
|
|
112
|
+
private roomId;
|
|
113
|
+
private localStream;
|
|
114
|
+
private screenStream;
|
|
115
|
+
private isScreenSharing;
|
|
116
|
+
private screenSenders;
|
|
117
|
+
private pingInterval;
|
|
118
|
+
private pendingIceCandidates;
|
|
119
|
+
private reconnectAttempts;
|
|
120
|
+
private reconnectTimer?;
|
|
121
|
+
private participantName;
|
|
122
|
+
readonly state: MeetingState;
|
|
123
|
+
private joinResolver?;
|
|
124
|
+
private joinRejecter?;
|
|
125
|
+
private emitError;
|
|
126
|
+
constructor(events?: Events, url?: string);
|
|
127
|
+
initLocal(video: HTMLVideoElement, name: string): Promise<void>;
|
|
128
|
+
connect(roomId: string, name: string): Promise<void>;
|
|
129
|
+
joinMeeting(config: MeetingConfig): Promise<void>;
|
|
130
|
+
/** Expose the roomId without making it fully public */
|
|
131
|
+
getMeetingId(): string | null;
|
|
132
|
+
toggleMic(): void;
|
|
133
|
+
toggleCam(): void;
|
|
134
|
+
private scheduleReconnect;
|
|
135
|
+
private startHeartbeat;
|
|
136
|
+
private stopHeartbeat;
|
|
137
|
+
private reset;
|
|
138
|
+
private handle;
|
|
139
|
+
private createPeer;
|
|
140
|
+
private createOffer;
|
|
141
|
+
private handleOffer;
|
|
142
|
+
private closePeer;
|
|
143
|
+
startScreenShare(): Promise<MediaStream>;
|
|
144
|
+
stopScreenShare(): void;
|
|
145
|
+
sendChatMessage(payload: ChatInput): void;
|
|
146
|
+
disconnect(): void;
|
|
147
|
+
private flushIce;
|
|
148
|
+
private send;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
type PubSubHandle = {
|
|
152
|
+
messages: ChatMessage[];
|
|
153
|
+
publish: (input: ChatInput) => void;
|
|
154
|
+
};
|
|
155
|
+
type MeetingContextValue = {
|
|
156
|
+
sdk: VideoSDKCore;
|
|
157
|
+
join: (config: MeetingConfig) => Promise<void>;
|
|
158
|
+
leave: () => void;
|
|
159
|
+
toggleMic: () => void;
|
|
160
|
+
toggleCam: () => void;
|
|
161
|
+
startScreenShare: () => Promise<MediaStream>;
|
|
162
|
+
stopScreenShare: () => void;
|
|
163
|
+
sendMessage: (input: ChatInput) => void;
|
|
164
|
+
meetingId: string | null;
|
|
165
|
+
localParticipant: Participant | null;
|
|
166
|
+
participants: Map<string, Participant>;
|
|
167
|
+
messages: ChatMessage[];
|
|
168
|
+
presenterId: string | null;
|
|
169
|
+
usePubSub: (topic: PubSubTopic) => PubSubHandle;
|
|
170
|
+
onError: (cb: (err: any) => void) => () => void;
|
|
171
|
+
};
|
|
172
|
+
declare const MeetingProvider: ({ config, children, }: {
|
|
173
|
+
config: MeetingConfig;
|
|
174
|
+
children: react__default.ReactNode;
|
|
175
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
176
|
+
declare const useMeetingContext: () => MeetingContextValue;
|
|
177
|
+
|
|
178
|
+
declare const useMeeting: (handlers?: {
|
|
179
|
+
onError?: (err: any) => void;
|
|
180
|
+
}) => {
|
|
181
|
+
sdk: VideoSDKCore;
|
|
182
|
+
join: (config: MeetingConfig) => Promise<void>;
|
|
183
|
+
leave: () => void;
|
|
184
|
+
toggleMic: () => void;
|
|
185
|
+
toggleCam: () => void;
|
|
186
|
+
startScreenShare: () => Promise<MediaStream>;
|
|
187
|
+
stopScreenShare: () => void;
|
|
188
|
+
sendMessage: (input: ChatInput) => void;
|
|
189
|
+
meetingId: string | null;
|
|
190
|
+
localParticipant: Participant | null;
|
|
191
|
+
participants: Map<string, Participant>;
|
|
192
|
+
messages: ChatMessage[];
|
|
193
|
+
presenterId: string | null;
|
|
194
|
+
usePubSub: (topic: PubSubTopic) => {
|
|
195
|
+
messages: ChatMessage[];
|
|
196
|
+
publish: (input: ChatInput) => void;
|
|
197
|
+
};
|
|
198
|
+
onError: (cb: (err: any) => void) => () => void;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
declare const useParticipants: () => Participant[];
|
|
202
|
+
|
|
203
|
+
declare const useRemoteMedia: (participantId: string) => {
|
|
204
|
+
videoRef: react.RefObject<HTMLVideoElement | null>;
|
|
205
|
+
audioRef: react.RefObject<HTMLAudioElement | null>;
|
|
206
|
+
isCamActive: boolean;
|
|
207
|
+
isMicEnabled: boolean;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export { type ChatInput, MeetingProvider, MeetingState, type Participant, VideoSDKCore, useLocalParticipant, useMeeting, useMeetingContext, useParticipants, useRemoteMedia };
|