@voicemaster/core 1.0.7 → 1.0.9

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
@@ -116,22 +116,27 @@ var VoiceClient = class {
116
116
  };
117
117
  }
118
118
  async handleSignalingMessage(message) {
119
+ console.log("Received:", message.type, message);
119
120
  switch (message.type) {
120
121
  case "user-joined":
121
122
  if (message.userId !== this.userId) {
123
+ console.log("User joined, creating offer...");
122
124
  this.targetUserId = message.userId;
123
125
  await this.createOffer();
124
126
  this.emit("userJoined", message.userId);
125
127
  }
126
128
  break;
127
129
  case "offer":
130
+ console.log("Received offer, handling...");
128
131
  this.targetUserId = message.userId;
129
132
  await this.handleOffer(message);
130
133
  break;
131
134
  case "answer":
135
+ console.log("Received answer, handling...");
132
136
  await this.handleAnswer(message);
133
137
  break;
134
138
  case "candidate":
139
+ console.log("Received candidate, handling...");
135
140
  await this.handleCandidate(message);
136
141
  break;
137
142
  case "user-left":
@@ -148,23 +153,36 @@ var VoiceClient = class {
148
153
  });
149
154
  }
150
155
  async handleOffer(message) {
151
- const offer = new RTCSessionDescription(message.sdp);
152
- await this.pc.setRemoteDescription(offer);
153
- const answer = await this.pc.createAnswer();
154
- await this.pc.setLocalDescription(answer);
155
- this.send({
156
- type: "answer",
157
- sdp: this.pc.localDescription
158
- });
156
+ try {
157
+ console.log("Handling offer", message);
158
+ const offer = new RTCSessionDescription(message.sdp);
159
+ await this.pc.setRemoteDescription(offer);
160
+ console.log("Remote description set");
161
+ const answer = await this.pc.createAnswer();
162
+ console.log("Answer created");
163
+ await this.pc.setLocalDescription(answer);
164
+ console.log("Local description set");
165
+ this.send({
166
+ type: "answer",
167
+ sdp: this.pc.localDescription
168
+ });
169
+ } catch (err) {
170
+ console.error("Offer handling error:", err);
171
+ }
159
172
  }
160
173
  async handleAnswer(message) {
161
174
  const answer = new RTCSessionDescription(message.sdp);
162
175
  await this.pc.setRemoteDescription(answer);
163
176
  }
164
177
  async handleCandidate(message) {
165
- if (message.candidate) {
166
- const candidate = new RTCIceCandidate(message.candidate);
167
- await this.pc.addIceCandidate(candidate);
178
+ try {
179
+ if (message.candidate) {
180
+ const candidate = new RTCIceCandidate(message.candidate);
181
+ await this.pc.addIceCandidate(candidate);
182
+ console.log("ICE candidate added");
183
+ }
184
+ } catch (err) {
185
+ console.error("Candidate error:", err);
168
186
  }
169
187
  }
170
188
  send(data) {
package/dist/index.mjs CHANGED
@@ -90,22 +90,27 @@ var VoiceClient = class {
90
90
  };
91
91
  }
92
92
  async handleSignalingMessage(message) {
93
+ console.log("Received:", message.type, message);
93
94
  switch (message.type) {
94
95
  case "user-joined":
95
96
  if (message.userId !== this.userId) {
97
+ console.log("User joined, creating offer...");
96
98
  this.targetUserId = message.userId;
97
99
  await this.createOffer();
98
100
  this.emit("userJoined", message.userId);
99
101
  }
100
102
  break;
101
103
  case "offer":
104
+ console.log("Received offer, handling...");
102
105
  this.targetUserId = message.userId;
103
106
  await this.handleOffer(message);
104
107
  break;
105
108
  case "answer":
109
+ console.log("Received answer, handling...");
106
110
  await this.handleAnswer(message);
107
111
  break;
108
112
  case "candidate":
113
+ console.log("Received candidate, handling...");
109
114
  await this.handleCandidate(message);
110
115
  break;
111
116
  case "user-left":
@@ -122,23 +127,36 @@ var VoiceClient = class {
122
127
  });
123
128
  }
124
129
  async handleOffer(message) {
125
- const offer = new RTCSessionDescription(message.sdp);
126
- await this.pc.setRemoteDescription(offer);
127
- const answer = await this.pc.createAnswer();
128
- await this.pc.setLocalDescription(answer);
129
- this.send({
130
- type: "answer",
131
- sdp: this.pc.localDescription
132
- });
130
+ try {
131
+ console.log("Handling offer", message);
132
+ const offer = new RTCSessionDescription(message.sdp);
133
+ await this.pc.setRemoteDescription(offer);
134
+ console.log("Remote description set");
135
+ const answer = await this.pc.createAnswer();
136
+ console.log("Answer created");
137
+ await this.pc.setLocalDescription(answer);
138
+ console.log("Local description set");
139
+ this.send({
140
+ type: "answer",
141
+ sdp: this.pc.localDescription
142
+ });
143
+ } catch (err) {
144
+ console.error("Offer handling error:", err);
145
+ }
133
146
  }
134
147
  async handleAnswer(message) {
135
148
  const answer = new RTCSessionDescription(message.sdp);
136
149
  await this.pc.setRemoteDescription(answer);
137
150
  }
138
151
  async handleCandidate(message) {
139
- if (message.candidate) {
140
- const candidate = new RTCIceCandidate(message.candidate);
141
- await this.pc.addIceCandidate(candidate);
152
+ try {
153
+ if (message.candidate) {
154
+ const candidate = new RTCIceCandidate(message.candidate);
155
+ await this.pc.addIceCandidate(candidate);
156
+ console.log("ICE candidate added");
157
+ }
158
+ } catch (err) {
159
+ console.error("Candidate error:", err);
142
160
  }
143
161
  }
144
162
  send(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicemaster/core",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "WebRTC voice communication core library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -39,6 +39,8 @@ export class VoiceClient {
39
39
  this.eventHandlers.get(event)!.push(callback);
40
40
  }
41
41
 
42
+
43
+
42
44
  private emit(event: string, ...args: any[]): void {
43
45
  const handlers = this.eventHandlers.get(event);
44
46
  if (handlers) {
@@ -117,22 +119,28 @@ export class VoiceClient {
117
119
  }
118
120
 
119
121
  private async handleSignalingMessage(message: any): Promise<void> {
122
+ console.log('Received:', message.type, message);
123
+
120
124
  switch (message.type) {
121
125
  case 'user-joined':
122
126
  if (message.userId !== this.userId) {
127
+ console.log('User joined, creating offer...');
123
128
  this.targetUserId = message.userId;
124
129
  await this.createOffer();
125
130
  this.emit('userJoined', message.userId);
126
131
  }
127
132
  break;
128
133
  case 'offer':
134
+ console.log('Received offer, handling...');
129
135
  this.targetUserId = message.userId;
130
136
  await this.handleOffer(message);
131
137
  break;
132
138
  case 'answer':
139
+ console.log('Received answer, handling...');
133
140
  await this.handleAnswer(message);
134
141
  break;
135
142
  case 'candidate':
143
+ console.log('Received candidate, handling...');
136
144
  await this.handleCandidate(message);
137
145
  break;
138
146
  case 'user-left':
@@ -151,14 +159,25 @@ export class VoiceClient {
151
159
  }
152
160
 
153
161
  private async handleOffer(message: any): Promise<void> {
154
- const offer = new RTCSessionDescription(message.sdp);
155
- await this.pc!.setRemoteDescription(offer);
156
- const answer = await this.pc!.createAnswer();
157
- await this.pc!.setLocalDescription(answer);
158
- this.send({
159
- type: 'answer',
160
- sdp: this.pc!.localDescription
161
- });
162
+ try {
163
+ console.log('Handling offer', message);
164
+ const offer = new RTCSessionDescription(message.sdp);
165
+ await this.pc!.setRemoteDescription(offer);
166
+ console.log('Remote description set');
167
+
168
+ const answer = await this.pc!.createAnswer();
169
+ console.log('Answer created');
170
+
171
+ await this.pc!.setLocalDescription(answer);
172
+ console.log('Local description set');
173
+
174
+ this.send({
175
+ type: 'answer',
176
+ sdp: this.pc!.localDescription
177
+ });
178
+ } catch (err) {
179
+ console.error('Offer handling error:', err);
180
+ }
162
181
  }
163
182
 
164
183
  private async handleAnswer(message: any): Promise<void> {
@@ -167,9 +186,14 @@ export class VoiceClient {
167
186
  }
168
187
 
169
188
  private async handleCandidate(message: any): Promise<void> {
170
- if (message.candidate) {
171
- const candidate = new RTCIceCandidate(message.candidate);
172
- await this.pc!.addIceCandidate(candidate);
189
+ try {
190
+ if (message.candidate) {
191
+ const candidate = new RTCIceCandidate(message.candidate);
192
+ await this.pc!.addIceCandidate(candidate);
193
+ console.log('ICE candidate added');
194
+ }
195
+ } catch (err) {
196
+ console.error('Candidate error:', err);
173
197
  }
174
198
  }
175
199