@voicemaster/react 1.0.8 → 1.1.0
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 +5 -7
- package/dist/index.d.ts +5 -7
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +43 -38
- package/src/index.ts +0 -1
- package/src/useVoice.ts +0 -109
- package/tsconfig.json +0 -21
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
userId: string;
|
|
5
|
-
iceServers?: any[];
|
|
1
|
+
import { VoiceClientConfig, VoiceClient } from '@voicemaster/core';
|
|
2
|
+
|
|
3
|
+
interface UseVoiceOptions extends VoiceClientConfig {
|
|
6
4
|
autoConnect?: boolean;
|
|
7
5
|
}
|
|
8
6
|
declare function useVoice(options: UseVoiceOptions): {
|
|
9
7
|
isConnected: boolean;
|
|
10
8
|
isMuted: boolean;
|
|
11
|
-
remoteStream:
|
|
9
|
+
remoteStream: MediaStream | null;
|
|
12
10
|
peers: string[];
|
|
13
11
|
speakingUsers: Set<string>;
|
|
14
12
|
connect: () => void;
|
|
15
13
|
disconnect: () => void;
|
|
16
14
|
toggleMute: () => void;
|
|
17
|
-
client:
|
|
15
|
+
client: VoiceClient | null;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
export { useVoice };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
userId: string;
|
|
5
|
-
iceServers?: any[];
|
|
1
|
+
import { VoiceClientConfig, VoiceClient } from '@voicemaster/core';
|
|
2
|
+
|
|
3
|
+
interface UseVoiceOptions extends VoiceClientConfig {
|
|
6
4
|
autoConnect?: boolean;
|
|
7
5
|
}
|
|
8
6
|
declare function useVoice(options: UseVoiceOptions): {
|
|
9
7
|
isConnected: boolean;
|
|
10
8
|
isMuted: boolean;
|
|
11
|
-
remoteStream:
|
|
9
|
+
remoteStream: MediaStream | null;
|
|
12
10
|
peers: string[];
|
|
13
11
|
speakingUsers: Set<string>;
|
|
14
12
|
connect: () => void;
|
|
15
13
|
disconnect: () => void;
|
|
16
14
|
toggleMute: () => void;
|
|
17
|
-
client:
|
|
15
|
+
client: VoiceClient | null;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
export { useVoice };
|
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ function useVoice(options) {
|
|
|
54
54
|
setRemoteStream(stream);
|
|
55
55
|
});
|
|
56
56
|
client.on("userJoined", (userId) => {
|
|
57
|
-
setPeers((prev) => [...prev, userId]);
|
|
57
|
+
setPeers((prev) => prev.includes(userId) ? prev : [...prev, userId]);
|
|
58
58
|
});
|
|
59
59
|
client.on("userLeft", (userId) => {
|
|
60
60
|
setPeers((prev) => prev.filter((id) => id !== userId));
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ function useVoice(options) {
|
|
|
28
28
|
setRemoteStream(stream);
|
|
29
29
|
});
|
|
30
30
|
client.on("userJoined", (userId) => {
|
|
31
|
-
setPeers((prev) => [...prev, userId]);
|
|
31
|
+
setPeers((prev) => prev.includes(userId) ? prev : [...prev, userId]);
|
|
32
32
|
});
|
|
33
33
|
client.on("userLeft", (userId) => {
|
|
34
34
|
setPeers((prev) => prev.filter((id) => id !== userId));
|
package/package.json
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@voicemaster/react",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "React hooks for VoiceMaster voice communication",
|
|
5
|
-
"main": "./dist/index.js",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
}
|
|
38
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@voicemaster/react",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "React hooks for VoiceMaster voice communication",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --external react --external @voicemaster/core",
|
|
23
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch --external react --external @voicemaster/core",
|
|
24
|
+
"prepublishOnly": "npm run build"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"react",
|
|
28
|
+
"webrtc",
|
|
29
|
+
"voice",
|
|
30
|
+
"hooks"
|
|
31
|
+
],
|
|
32
|
+
"author": "Sergey Minasyan",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@voicemaster/core": "^1.0.0",
|
|
36
|
+
"react": ">=18.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@types/react": "^18.0.0",
|
|
40
|
+
"tsup": "^8.0.0",
|
|
41
|
+
"typescript": "^5.3.0"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useVoice } from './useVoice';
|
package/src/useVoice.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useRef, useCallback } from 'react';
|
|
2
|
-
import { VoiceClient } from '@voicemaster/core';
|
|
3
|
-
|
|
4
|
-
interface UseVoiceOptions {
|
|
5
|
-
signalingUrl: string;
|
|
6
|
-
roomId: string;
|
|
7
|
-
userId: string;
|
|
8
|
-
iceServers?: any[];
|
|
9
|
-
autoConnect?: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function useVoice(options: UseVoiceOptions) {
|
|
13
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
14
|
-
const [isMuted, setIsMuted] = useState(false);
|
|
15
|
-
const [remoteStream, setRemoteStream] = useState<any>(null);
|
|
16
|
-
const [speakingUsers, setSpeakingUsers] = useState<Set<string>>(new Set());
|
|
17
|
-
const [peers, setPeers] = useState<string[]>([]);
|
|
18
|
-
const clientRef = useRef<any>(null);
|
|
19
|
-
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const client = new VoiceClient({
|
|
22
|
-
signalingUrl: options.signalingUrl,
|
|
23
|
-
roomId: options.roomId,
|
|
24
|
-
userId: options.userId,
|
|
25
|
-
iceServers: options.iceServers,
|
|
26
|
-
autoConnect: false
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
client.on('connected', () => {
|
|
30
|
-
setIsConnected(true);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
client.on('disconnected', () => {
|
|
34
|
-
setIsConnected(false);
|
|
35
|
-
setPeers([]);
|
|
36
|
-
setRemoteStream(null);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
client.on('remoteStream', (stream: any) => {
|
|
40
|
-
setRemoteStream(stream);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
client.on('userJoined', (userId: string) => {
|
|
44
|
-
setPeers(prev => [...prev, userId]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
client.on('userLeft', (userId: string) => {
|
|
48
|
-
setPeers(prev => prev.filter(id => id !== userId));
|
|
49
|
-
setSpeakingUsers(prev => {
|
|
50
|
-
const newSet = new Set(prev);
|
|
51
|
-
newSet.delete(userId);
|
|
52
|
-
return newSet;
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
client.on('speaking', (userId: string) => {
|
|
57
|
-
setSpeakingUsers(prev => new Set(prev).add(userId));
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
client.on('stoppedSpeaking', (userId: string) => {
|
|
61
|
-
setSpeakingUsers(prev => {
|
|
62
|
-
const newSet = new Set(prev);
|
|
63
|
-
newSet.delete(userId);
|
|
64
|
-
return newSet;
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
client.on('error', (error: Error) => {
|
|
69
|
-
console.error('Voice client error:', error);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
clientRef.current = client;
|
|
73
|
-
|
|
74
|
-
if (options.autoConnect !== false) {
|
|
75
|
-
client.connect();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return () => {
|
|
79
|
-
client.disconnect();
|
|
80
|
-
};
|
|
81
|
-
}, [options.signalingUrl, options.roomId, options.userId, options.iceServers]);
|
|
82
|
-
|
|
83
|
-
const connect = useCallback(() => {
|
|
84
|
-
clientRef.current?.connect();
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
const disconnect = useCallback(() => {
|
|
88
|
-
clientRef.current?.disconnect();
|
|
89
|
-
}, []);
|
|
90
|
-
|
|
91
|
-
const toggleMute = useCallback(() => {
|
|
92
|
-
if (clientRef.current) {
|
|
93
|
-
clientRef.current.toggleMute();
|
|
94
|
-
setIsMuted(prev => !prev);
|
|
95
|
-
}
|
|
96
|
-
}, []);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
isConnected,
|
|
100
|
-
isMuted,
|
|
101
|
-
remoteStream,
|
|
102
|
-
peers,
|
|
103
|
-
speakingUsers,
|
|
104
|
-
connect,
|
|
105
|
-
disconnect,
|
|
106
|
-
toggleMute,
|
|
107
|
-
client: clientRef.current
|
|
108
|
-
};
|
|
109
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"lib": ["ES2020", "DOM"],
|
|
6
|
-
"moduleResolution": "bundler",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"jsx": "react-jsx",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"esModuleInterop": true,
|
|
12
|
-
"skipLibCheck": true,
|
|
13
|
-
"forceConsistentCasingInFileNames": true,
|
|
14
|
-
"noEmit": true,
|
|
15
|
-
"paths": {
|
|
16
|
-
"@voiceflow/core": ["../core/src"]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"include": ["src/**/*"],
|
|
20
|
-
"exclude": ["node_modules", "dist"]
|
|
21
|
-
}
|