@voicemaster/core 1.0.1 → 1.0.3
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 +11 -3
- package/dist/index.mjs +11 -3
- package/package.json +10 -3
- package/src/VoiceClient.ts +23 -14
package/dist/index.js
CHANGED
|
@@ -133,10 +133,16 @@ var VoiceClient = class {
|
|
|
133
133
|
this.peer.on("stream", (stream) => {
|
|
134
134
|
this.remoteStream = stream;
|
|
135
135
|
this.emit("remoteStream", stream);
|
|
136
|
+
if (!this.isConnectedFlag) {
|
|
137
|
+
this.isConnectedFlag = true;
|
|
138
|
+
this.emit("connected");
|
|
139
|
+
}
|
|
136
140
|
});
|
|
137
141
|
this.peer.on("connect", () => {
|
|
138
|
-
this.isConnectedFlag
|
|
139
|
-
|
|
142
|
+
if (!this.isConnectedFlag) {
|
|
143
|
+
this.isConnectedFlag = true;
|
|
144
|
+
this.emit("connected");
|
|
145
|
+
}
|
|
140
146
|
});
|
|
141
147
|
this.peer.on("error", (err) => {
|
|
142
148
|
console.error("Peer error:", err);
|
|
@@ -159,7 +165,9 @@ var VoiceClient = class {
|
|
|
159
165
|
this.ws.close();
|
|
160
166
|
}
|
|
161
167
|
this.peer?.destroy();
|
|
162
|
-
this.localStream
|
|
168
|
+
if (this.localStream) {
|
|
169
|
+
this.localStream.getTracks().forEach((track) => track.stop());
|
|
170
|
+
}
|
|
163
171
|
this.isConnectedFlag = false;
|
|
164
172
|
this.emit("disconnected");
|
|
165
173
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -97,10 +97,16 @@ var VoiceClient = class {
|
|
|
97
97
|
this.peer.on("stream", (stream) => {
|
|
98
98
|
this.remoteStream = stream;
|
|
99
99
|
this.emit("remoteStream", stream);
|
|
100
|
+
if (!this.isConnectedFlag) {
|
|
101
|
+
this.isConnectedFlag = true;
|
|
102
|
+
this.emit("connected");
|
|
103
|
+
}
|
|
100
104
|
});
|
|
101
105
|
this.peer.on("connect", () => {
|
|
102
|
-
this.isConnectedFlag
|
|
103
|
-
|
|
106
|
+
if (!this.isConnectedFlag) {
|
|
107
|
+
this.isConnectedFlag = true;
|
|
108
|
+
this.emit("connected");
|
|
109
|
+
}
|
|
104
110
|
});
|
|
105
111
|
this.peer.on("error", (err) => {
|
|
106
112
|
console.error("Peer error:", err);
|
|
@@ -123,7 +129,9 @@ var VoiceClient = class {
|
|
|
123
129
|
this.ws.close();
|
|
124
130
|
}
|
|
125
131
|
this.peer?.destroy();
|
|
126
|
-
this.localStream
|
|
132
|
+
if (this.localStream) {
|
|
133
|
+
this.localStream.getTracks().forEach((track) => track.stop());
|
|
134
|
+
}
|
|
127
135
|
this.isConnectedFlag = false;
|
|
128
136
|
this.emit("disconnected");
|
|
129
137
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voicemaster/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "WebRTC voice communication core library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -17,10 +17,17 @@
|
|
|
17
17
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
|
-
"keywords": [
|
|
20
|
+
"keywords": [
|
|
21
|
+
"webrtc",
|
|
22
|
+
"voice",
|
|
23
|
+
"audio",
|
|
24
|
+
"p2p",
|
|
25
|
+
"typescript"
|
|
26
|
+
],
|
|
21
27
|
"author": "Sergey Minasyan",
|
|
22
28
|
"license": "MIT",
|
|
23
29
|
"dependencies": {
|
|
30
|
+
"@voicemaster/core": "^1.0.1",
|
|
24
31
|
"simple-peer": "^9.11.1"
|
|
25
32
|
},
|
|
26
33
|
"devDependencies": {
|
|
@@ -28,4 +35,4 @@
|
|
|
28
35
|
"tsup": "^8.0.0",
|
|
29
36
|
"typescript": "^5.3.0"
|
|
30
37
|
}
|
|
31
|
-
}
|
|
38
|
+
}
|
package/src/VoiceClient.ts
CHANGED
|
@@ -105,7 +105,7 @@ export class VoiceClient {
|
|
|
105
105
|
private initPeer(initiator: boolean): void {
|
|
106
106
|
if (this.peer) return;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
this.peer = new Peer({
|
|
109
109
|
initiator,
|
|
110
110
|
trickle: true,
|
|
111
111
|
stream: this.localStream || undefined,
|
|
@@ -121,20 +121,27 @@ export class VoiceClient {
|
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
124
|
+
this.peer.on('stream', (stream) => {
|
|
125
|
+
this.remoteStream = stream;
|
|
126
|
+
this.emit('remoteStream', stream);
|
|
127
|
+
// Когда получили удалённый поток — значит соединение установлено
|
|
128
|
+
if (!this.isConnectedFlag) {
|
|
129
|
+
this.isConnectedFlag = true;
|
|
130
|
+
this.emit('connected');
|
|
131
|
+
}
|
|
132
|
+
});
|
|
128
133
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
this.peer.on('connect', () => {
|
|
135
|
+
if (!this.isConnectedFlag) {
|
|
136
|
+
this.isConnectedFlag = true;
|
|
137
|
+
this.emit('connected');
|
|
138
|
+
}
|
|
139
|
+
});
|
|
133
140
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
141
|
+
this.peer.on('error', (err) => {
|
|
142
|
+
console.error('Peer error:', err);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
138
145
|
|
|
139
146
|
private handlePeerSignal(targetUserId: string, signal: any): void {
|
|
140
147
|
if (!this.peer) {
|
|
@@ -155,7 +162,9 @@ export class VoiceClient {
|
|
|
155
162
|
this.ws.close();
|
|
156
163
|
}
|
|
157
164
|
this.peer?.destroy();
|
|
158
|
-
this.localStream
|
|
165
|
+
if (this.localStream) {
|
|
166
|
+
this.localStream.getTracks().forEach(track => track.stop());
|
|
167
|
+
}
|
|
159
168
|
this.isConnectedFlag = false;
|
|
160
169
|
this.emit('disconnected');
|
|
161
170
|
}
|