@voicemaster/react 1.0.0 → 1.0.1
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.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +43 -37
- package/src/index.ts +0 -1
- package/src/useVoice.ts +0 -106
- package/tsconfig.json +0 -21
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,37 +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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@voicemaster/react",
|
|
3
|
+
"version": "1.0.1",
|
|
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,106 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState, useRef, useCallback } from 'react';
|
|
2
|
-
import { VoiceClient } from '@voicemaster/core';
|
|
3
|
-
import type { VoiceClientConfig } from '@voicemaster/core';
|
|
4
|
-
|
|
5
|
-
interface UseVoiceOptions extends VoiceClientConfig {
|
|
6
|
-
autoConnect?: boolean;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function useVoice(options: UseVoiceOptions) {
|
|
10
|
-
const [isConnected, setIsConnected] = useState(false);
|
|
11
|
-
const [isMuted, setIsMuted] = useState(false);
|
|
12
|
-
const [remoteStream, setRemoteStream] = useState<MediaStream | null>(null);
|
|
13
|
-
const [speakingUsers, setSpeakingUsers] = useState<Set<string>>(new Set());
|
|
14
|
-
const [peers, setPeers] = useState<string[]>([]);
|
|
15
|
-
const clientRef = useRef<VoiceClient | null>(null);
|
|
16
|
-
|
|
17
|
-
useEffect(() => {
|
|
18
|
-
const client = new VoiceClient({
|
|
19
|
-
signalingUrl: options.signalingUrl,
|
|
20
|
-
roomId: options.roomId,
|
|
21
|
-
userId: options.userId,
|
|
22
|
-
iceServers: options.iceServers,
|
|
23
|
-
autoConnect: false
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
client.on('connected', () => {
|
|
27
|
-
setIsConnected(true);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
client.on('disconnected', () => {
|
|
31
|
-
setIsConnected(false);
|
|
32
|
-
setPeers([]);
|
|
33
|
-
setRemoteStream(null);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
client.on('remoteStream', (stream) => {
|
|
37
|
-
setRemoteStream(stream);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
client.on('userJoined', (userId) => {
|
|
41
|
-
setPeers(prev => [...prev, userId]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
client.on('userLeft', (userId) => {
|
|
45
|
-
setPeers(prev => prev.filter(id => id !== userId));
|
|
46
|
-
setSpeakingUsers(prev => {
|
|
47
|
-
const newSet = new Set(prev);
|
|
48
|
-
newSet.delete(userId);
|
|
49
|
-
return newSet;
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
client.on('speaking', (userId) => {
|
|
54
|
-
setSpeakingUsers(prev => new Set(prev).add(userId));
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
client.on('stoppedSpeaking', (userId) => {
|
|
58
|
-
setSpeakingUsers(prev => {
|
|
59
|
-
const newSet = new Set(prev);
|
|
60
|
-
newSet.delete(userId);
|
|
61
|
-
return newSet;
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
client.on('error', (error) => {
|
|
66
|
-
console.error('Voice client error:', error);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
clientRef.current = client;
|
|
70
|
-
|
|
71
|
-
if (options.autoConnect !== false) {
|
|
72
|
-
client.connect();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return () => {
|
|
76
|
-
client.disconnect();
|
|
77
|
-
};
|
|
78
|
-
}, [options.signalingUrl, options.roomId, options.userId, options.iceServers]);
|
|
79
|
-
|
|
80
|
-
const connect = useCallback(() => {
|
|
81
|
-
clientRef.current?.connect();
|
|
82
|
-
}, []);
|
|
83
|
-
|
|
84
|
-
const disconnect = useCallback(() => {
|
|
85
|
-
clientRef.current?.disconnect();
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
const toggleMute = useCallback(() => {
|
|
89
|
-
if (clientRef.current) {
|
|
90
|
-
clientRef.current.toggleMute();
|
|
91
|
-
setIsMuted(prev => !prev);
|
|
92
|
-
}
|
|
93
|
-
}, []);
|
|
94
|
-
|
|
95
|
-
return {
|
|
96
|
-
isConnected,
|
|
97
|
-
isMuted,
|
|
98
|
-
remoteStream,
|
|
99
|
-
peers,
|
|
100
|
-
speakingUsers,
|
|
101
|
-
connect,
|
|
102
|
-
disconnect,
|
|
103
|
-
toggleMute,
|
|
104
|
-
client: clientRef.current
|
|
105
|
-
};
|
|
106
|
-
}
|
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
|
-
}
|