@voicemaster/core 1.0.2 → 1.0.4

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 CHANGED
@@ -48,7 +48,8 @@ var VoiceClient = class {
48
48
  this.roomId = config.roomId;
49
49
  this.userId = config.userId;
50
50
  this.iceServers = config.iceServers || [
51
- { urls: "stun:stun.l.google.com:19302" }
51
+ { urls: "stun:stun.l.google.com:19302" },
52
+ { urls: "stun:stun1.l.google.com:19302" }
52
53
  ];
53
54
  if (config.autoConnect !== false) {
54
55
  this.connect();
@@ -116,11 +117,14 @@ var VoiceClient = class {
116
117
  }
117
118
  initPeer(initiator) {
118
119
  if (this.peer) return;
120
+ const config = {
121
+ iceServers: this.iceServers
122
+ };
119
123
  this.peer = new import_simple_peer.default({
120
124
  initiator,
121
125
  trickle: true,
122
126
  stream: this.localStream || void 0,
123
- config: { iceServers: this.iceServers }
127
+ config
124
128
  });
125
129
  this.peer.on("signal", (data) => {
126
130
  this.send({
@@ -133,10 +137,16 @@ var VoiceClient = class {
133
137
  this.peer.on("stream", (stream) => {
134
138
  this.remoteStream = stream;
135
139
  this.emit("remoteStream", stream);
140
+ if (!this.isConnectedFlag) {
141
+ this.isConnectedFlag = true;
142
+ this.emit("connected");
143
+ }
136
144
  });
137
145
  this.peer.on("connect", () => {
138
- this.isConnectedFlag = true;
139
- this.emit("connected");
146
+ if (!this.isConnectedFlag) {
147
+ this.isConnectedFlag = true;
148
+ this.emit("connected");
149
+ }
140
150
  });
141
151
  this.peer.on("error", (err) => {
142
152
  console.error("Peer error:", err);
@@ -159,7 +169,9 @@ var VoiceClient = class {
159
169
  this.ws.close();
160
170
  }
161
171
  this.peer?.destroy();
162
- this.localStream?.getTracks().forEach((track) => track.stop());
172
+ if (this.localStream) {
173
+ this.localStream.getTracks().forEach((track) => track.stop());
174
+ }
163
175
  this.isConnectedFlag = false;
164
176
  this.emit("disconnected");
165
177
  }
package/dist/index.mjs CHANGED
@@ -12,7 +12,8 @@ var VoiceClient = class {
12
12
  this.roomId = config.roomId;
13
13
  this.userId = config.userId;
14
14
  this.iceServers = config.iceServers || [
15
- { urls: "stun:stun.l.google.com:19302" }
15
+ { urls: "stun:stun.l.google.com:19302" },
16
+ { urls: "stun:stun1.l.google.com:19302" }
16
17
  ];
17
18
  if (config.autoConnect !== false) {
18
19
  this.connect();
@@ -80,11 +81,14 @@ var VoiceClient = class {
80
81
  }
81
82
  initPeer(initiator) {
82
83
  if (this.peer) return;
84
+ const config = {
85
+ iceServers: this.iceServers
86
+ };
83
87
  this.peer = new Peer({
84
88
  initiator,
85
89
  trickle: true,
86
90
  stream: this.localStream || void 0,
87
- config: { iceServers: this.iceServers }
91
+ config
88
92
  });
89
93
  this.peer.on("signal", (data) => {
90
94
  this.send({
@@ -97,10 +101,16 @@ var VoiceClient = class {
97
101
  this.peer.on("stream", (stream) => {
98
102
  this.remoteStream = stream;
99
103
  this.emit("remoteStream", stream);
104
+ if (!this.isConnectedFlag) {
105
+ this.isConnectedFlag = true;
106
+ this.emit("connected");
107
+ }
100
108
  });
101
109
  this.peer.on("connect", () => {
102
- this.isConnectedFlag = true;
103
- this.emit("connected");
110
+ if (!this.isConnectedFlag) {
111
+ this.isConnectedFlag = true;
112
+ this.emit("connected");
113
+ }
104
114
  });
105
115
  this.peer.on("error", (err) => {
106
116
  console.error("Peer error:", err);
@@ -123,7 +133,9 @@ var VoiceClient = class {
123
133
  this.ws.close();
124
134
  }
125
135
  this.peer?.destroy();
126
- this.localStream?.getTracks().forEach((track) => track.stop());
136
+ if (this.localStream) {
137
+ this.localStream.getTracks().forEach((track) => track.stop());
138
+ }
127
139
  this.isConnectedFlag = false;
128
140
  this.emit("disconnected");
129
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicemaster/core",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "WebRTC voice communication core library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -25,7 +25,8 @@ export class VoiceClient {
25
25
  this.roomId = config.roomId;
26
26
  this.userId = config.userId;
27
27
  this.iceServers = config.iceServers || [
28
- { urls: 'stun:stun.l.google.com:19302' }
28
+ { urls: 'stun:stun.l.google.com:19302' },
29
+ { urls: 'stun:stun1.l.google.com:19302' }
29
30
  ];
30
31
 
31
32
  if (config.autoConnect !== false) {
@@ -105,11 +106,15 @@ export class VoiceClient {
105
106
  private initPeer(initiator: boolean): void {
106
107
  if (this.peer) return;
107
108
 
108
- this.peer = new Peer({
109
+ const config = {
110
+ iceServers: this.iceServers
111
+ };
112
+
113
+ this.peer = new Peer({
109
114
  initiator,
110
115
  trickle: true,
111
116
  stream: this.localStream || undefined,
112
- config: { iceServers: this.iceServers }
117
+ config: config
113
118
  });
114
119
 
115
120
  this.peer.on('signal', (data) => {
@@ -121,20 +126,26 @@ export class VoiceClient {
121
126
  });
122
127
  });
123
128
 
124
- this.peer.on('stream', (stream) => {
125
- this.remoteStream = stream;
126
- this.emit('remoteStream', stream);
127
- });
129
+ this.peer.on('stream', (stream) => {
130
+ this.remoteStream = stream;
131
+ this.emit('remoteStream', stream);
132
+ if (!this.isConnectedFlag) {
133
+ this.isConnectedFlag = true;
134
+ this.emit('connected');
135
+ }
136
+ });
128
137
 
129
- this.peer.on('connect', () => {
130
- this.isConnectedFlag = true;
131
- this.emit('connected');
132
- });
138
+ this.peer.on('connect', () => {
139
+ if (!this.isConnectedFlag) {
140
+ this.isConnectedFlag = true;
141
+ this.emit('connected');
142
+ }
143
+ });
133
144
 
134
- this.peer.on('error', (err) => {
135
- console.error('Peer error:', err);
136
- });
137
- }
145
+ this.peer.on('error', (err) => {
146
+ console.error('Peer error:', err);
147
+ });
148
+ }
138
149
 
139
150
  private handlePeerSignal(targetUserId: string, signal: any): void {
140
151
  if (!this.peer) {
@@ -155,7 +166,9 @@ export class VoiceClient {
155
166
  this.ws.close();
156
167
  }
157
168
  this.peer?.destroy();
158
- this.localStream?.getTracks().forEach(track => track.stop());
169
+ if (this.localStream) {
170
+ this.localStream.getTracks().forEach(track => track.stop());
171
+ }
159
172
  this.isConnectedFlag = false;
160
173
  this.emit('disconnected');
161
174
  }
@@ -177,7 +190,6 @@ export class VoiceClient {
177
190
  return this.userId;
178
191
  }
179
192
  }
180
-
181
193
  export interface VoiceEvents {
182
194
  connected: () => void;
183
195
  disconnected: () => void;