@voicemaster/react 1.0.4 → 1.0.5
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/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +0 -1
- package/dist/index.mjs +0 -1
- package/package.json +2 -1
- package/src/useVoice.ts +13 -11
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface UseVoiceOptions {
|
|
2
|
+
signalingUrl: string;
|
|
3
|
+
roomId: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
iceServers?: any[];
|
|
4
6
|
autoConnect?: boolean;
|
|
5
7
|
}
|
|
6
8
|
declare function useVoice(options: UseVoiceOptions): {
|
|
7
9
|
isConnected: boolean;
|
|
8
10
|
isMuted: boolean;
|
|
9
|
-
remoteStream:
|
|
11
|
+
remoteStream: any;
|
|
10
12
|
peers: string[];
|
|
11
13
|
speakingUsers: Set<string>;
|
|
12
14
|
connect: () => void;
|
|
13
15
|
disconnect: () => void;
|
|
14
16
|
toggleMute: () => void;
|
|
15
|
-
client:
|
|
17
|
+
client: any;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
export { useVoice };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface UseVoiceOptions {
|
|
2
|
+
signalingUrl: string;
|
|
3
|
+
roomId: string;
|
|
4
|
+
userId: string;
|
|
5
|
+
iceServers?: any[];
|
|
4
6
|
autoConnect?: boolean;
|
|
5
7
|
}
|
|
6
8
|
declare function useVoice(options: UseVoiceOptions): {
|
|
7
9
|
isConnected: boolean;
|
|
8
10
|
isMuted: boolean;
|
|
9
|
-
remoteStream:
|
|
11
|
+
remoteStream: any;
|
|
10
12
|
peers: string[];
|
|
11
13
|
speakingUsers: Set<string>;
|
|
12
14
|
connect: () => void;
|
|
13
15
|
disconnect: () => void;
|
|
14
16
|
toggleMute: () => void;
|
|
15
|
-
client:
|
|
17
|
+
client: any;
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
export { useVoice };
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voicemaster/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "React hooks for VoiceMaster voice communication",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/react": "^18.0.0",
|
|
34
|
+
"@types/simple-peer": "^9.11.9",
|
|
34
35
|
"tsup": "^8.0.0",
|
|
35
36
|
"typescript": "^5.3.0"
|
|
36
37
|
}
|
package/src/useVoice.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { useEffect, useState, useRef, useCallback } from 'react';
|
|
2
2
|
import { VoiceClient } from '@voicemaster/core';
|
|
3
|
-
import type { VoiceClientConfig } from '@voicemaster/core';
|
|
4
3
|
|
|
5
|
-
interface UseVoiceOptions
|
|
4
|
+
interface UseVoiceOptions {
|
|
5
|
+
signalingUrl: string;
|
|
6
|
+
roomId: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
iceServers?: any[];
|
|
6
9
|
autoConnect?: boolean;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export function useVoice(options: UseVoiceOptions) {
|
|
10
13
|
const [isConnected, setIsConnected] = useState(false);
|
|
11
14
|
const [isMuted, setIsMuted] = useState(false);
|
|
12
|
-
const [remoteStream, setRemoteStream] = useState<
|
|
15
|
+
const [remoteStream, setRemoteStream] = useState<any>(null);
|
|
13
16
|
const [speakingUsers, setSpeakingUsers] = useState<Set<string>>(new Set());
|
|
14
17
|
const [peers, setPeers] = useState<string[]>([]);
|
|
15
|
-
const clientRef = useRef<
|
|
18
|
+
const clientRef = useRef<any>(null);
|
|
16
19
|
|
|
17
20
|
useEffect(() => {
|
|
18
21
|
const client = new VoiceClient({
|
|
@@ -24,7 +27,6 @@ export function useVoice(options: UseVoiceOptions) {
|
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
client.on('connected', () => {
|
|
27
|
-
console.log('connected event received'); // Добавь для отладки
|
|
28
30
|
setIsConnected(true);
|
|
29
31
|
});
|
|
30
32
|
|
|
@@ -34,15 +36,15 @@ export function useVoice(options: UseVoiceOptions) {
|
|
|
34
36
|
setRemoteStream(null);
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
client.on('remoteStream', (stream) => {
|
|
39
|
+
client.on('remoteStream', (stream: any) => {
|
|
38
40
|
setRemoteStream(stream);
|
|
39
41
|
});
|
|
40
42
|
|
|
41
|
-
client.on('userJoined', (userId) => {
|
|
43
|
+
client.on('userJoined', (userId: string) => {
|
|
42
44
|
setPeers(prev => [...prev, userId]);
|
|
43
45
|
});
|
|
44
46
|
|
|
45
|
-
client.on('userLeft', (userId) => {
|
|
47
|
+
client.on('userLeft', (userId: string) => {
|
|
46
48
|
setPeers(prev => prev.filter(id => id !== userId));
|
|
47
49
|
setSpeakingUsers(prev => {
|
|
48
50
|
const newSet = new Set(prev);
|
|
@@ -51,11 +53,11 @@ export function useVoice(options: UseVoiceOptions) {
|
|
|
51
53
|
});
|
|
52
54
|
});
|
|
53
55
|
|
|
54
|
-
client.on('speaking', (userId) => {
|
|
56
|
+
client.on('speaking', (userId: string) => {
|
|
55
57
|
setSpeakingUsers(prev => new Set(prev).add(userId));
|
|
56
58
|
});
|
|
57
59
|
|
|
58
|
-
client.on('stoppedSpeaking', (userId) => {
|
|
60
|
+
client.on('stoppedSpeaking', (userId: string) => {
|
|
59
61
|
setSpeakingUsers(prev => {
|
|
60
62
|
const newSet = new Set(prev);
|
|
61
63
|
newSet.delete(userId);
|
|
@@ -63,7 +65,7 @@ export function useVoice(options: UseVoiceOptions) {
|
|
|
63
65
|
});
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
client.on('error', (error) => {
|
|
68
|
+
client.on('error', (error: Error) => {
|
|
67
69
|
console.error('Voice client error:', error);
|
|
68
70
|
});
|
|
69
71
|
|