uniwrtc 1.0.1 → 1.0.2

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/README.md CHANGED
@@ -188,22 +188,22 @@ client.on('joined', (data) => {
188
188
  });
189
189
 
190
190
  client.on('peer-joined', (data) => {
191
- console.log('New peer joined:', data.peerId || data.clientId);
191
+ console.log('New peer joined:', data.peerId);
192
192
  // Initiate WebRTC connection with new peer
193
193
  });
194
194
 
195
195
  client.on('offer', (data) => {
196
- console.log('Received offer from:', data.peerId || data.senderId);
196
+ console.log('Received offer from:', data.peerId);
197
197
  // Handle WebRTC offer
198
198
  });
199
199
 
200
200
  client.on('answer', (data) => {
201
- console.log('Received answer from:', data.peerId || data.senderId);
201
+ console.log('Received answer from:', data.peerId);
202
202
  // Handle WebRTC answer
203
203
  });
204
204
 
205
205
  client.on('ice-candidate', (data) => {
206
- console.log('Received ICE candidate from:', data.peerId || data.senderId);
206
+ console.log('Received ICE candidate from:', data.peerId);
207
207
  // Add ICE candidate to peer connection
208
208
  });
209
209
 
@@ -253,7 +253,7 @@ function createPeerConnection(peerId) {
253
253
 
254
254
  // Handle new peer
255
255
  client.on('peer-joined', async (data) => {
256
- const pc = createPeerConnection(data.clientId);
256
+ const pc = createPeerConnection(data.peerId);
257
257
 
258
258
  // Add local tracks
259
259
  const stream = await navigator.mediaDevices.getUserMedia({
@@ -265,22 +265,22 @@ client.on('peer-joined', async (data) => {
265
265
  // Create and send offer
266
266
  const offer = await pc.createOffer();
267
267
  await pc.setLocalDescription(offer);
268
- client.sendOffer(offer, data.clientId);
268
+ client.sendOffer(offer, data.peerId);
269
269
  });
270
270
 
271
271
  // Handle incoming offer
272
272
  client.on('offer', async (data) => {
273
- const pc = createPeerConnection(data.senderId);
273
+ const pc = createPeerConnection(data.peerId);
274
274
 
275
275
  await pc.setRemoteDescription(data.offer);
276
276
  const answer = await pc.createAnswer();
277
277
  await pc.setLocalDescription(answer);
278
- client.sendAnswer(answer, data.senderId);
278
+ client.sendAnswer(answer, data.peerId);
279
279
  });
280
280
 
281
281
  // Handle incoming answer
282
282
  client.on('answer', async (data) => {
283
- const pc = peerConnections.get(data.senderId);
283
+ const pc = peerConnections.get(data.peerId);
284
284
  if (pc) {
285
285
  await pc.setRemoteDescription(data.answer);
286
286
  }
@@ -288,7 +288,7 @@ client.on('answer', async (data) => {
288
288
 
289
289
  // Handle ICE candidates
290
290
  client.on('ice-candidate', async (data) => {
291
- const pc = peerConnections.get(data.senderId);
291
+ const pc = peerConnections.get(data.peerId);
292
292
  if (pc) {
293
293
  await pc.addIceCandidate(data.candidate);
294
294
  }
package/client-browser.js CHANGED
@@ -122,7 +122,7 @@ class UniWRTCClient {
122
122
  }
123
123
  }
124
124
 
125
- sendOffer(targetId, offer) {
125
+ sendOffer(offer, targetId) {
126
126
  this.send({
127
127
  type: 'offer',
128
128
  offer: offer,
@@ -131,7 +131,7 @@ class UniWRTCClient {
131
131
  });
132
132
  }
133
133
 
134
- sendAnswer(targetId, answer) {
134
+ sendAnswer(answer, targetId) {
135
135
  this.send({
136
136
  type: 'answer',
137
137
  answer: answer,
@@ -140,7 +140,7 @@ class UniWRTCClient {
140
140
  });
141
141
  }
142
142
 
143
- sendIceCandidate(targetId, candidate) {
143
+ sendIceCandidate(candidate, targetId) {
144
144
  this.send({
145
145
  type: 'ice-candidate',
146
146
  candidate: candidate,
@@ -197,14 +197,12 @@ class UniWRTCClient {
197
197
  break;
198
198
  case 'peer-joined':
199
199
  this.emit('peer-joined', {
200
- peerId: message.peerId || message.clientId,
201
- clientId: message.clientId
200
+ peerId: message.peerId
202
201
  });
203
202
  break;
204
203
  case 'peer-left':
205
204
  this.emit('peer-left', {
206
- peerId: message.peerId || message.clientId,
207
- clientId: message.clientId
205
+ peerId: message.peerId
208
206
  });
209
207
  break;
210
208
  case 'offer':
@@ -238,7 +236,7 @@ class UniWRTCClient {
238
236
  case 'chat':
239
237
  this.emit('chat', {
240
238
  text: message.text,
241
- senderId: message.senderId,
239
+ peerId: message.peerId,
242
240
  roomId: message.roomId
243
241
  });
244
242
  break;
@@ -247,3 +245,8 @@ class UniWRTCClient {
247
245
  }
248
246
  }
249
247
  }
248
+
249
+ // Attach to window for non-module script usage
250
+ if (typeof window !== 'undefined') {
251
+ window.UniWRTCClient = UniWRTCClient;
252
+ }
package/client.js CHANGED
@@ -159,29 +159,29 @@ class UniWRTCClient {
159
159
  break;
160
160
  case 'peer-joined':
161
161
  this.emit('peer-joined', {
162
- clientId: message.clientId
162
+ peerId: message.peerId
163
163
  });
164
164
  break;
165
165
  case 'peer-left':
166
166
  this.emit('peer-left', {
167
- clientId: message.clientId
167
+ peerId: message.peerId
168
168
  });
169
169
  break;
170
170
  case 'offer':
171
171
  this.emit('offer', {
172
- senderId: message.senderId,
172
+ peerId: message.peerId,
173
173
  offer: message.offer
174
174
  });
175
175
  break;
176
176
  case 'answer':
177
177
  this.emit('answer', {
178
- senderId: message.senderId,
178
+ peerId: message.peerId,
179
179
  answer: message.answer
180
180
  });
181
181
  break;
182
182
  case 'ice-candidate':
183
183
  this.emit('ice-candidate', {
184
- senderId: message.senderId,
184
+ peerId: message.peerId,
185
185
  candidate: message.candidate
186
186
  });
187
187
  break;
package/demo.html CHANGED
@@ -460,7 +460,7 @@
460
460
  updatePeersList(knownPeers);
461
461
 
462
462
  // Update room info with dynamic peer count
463
- updateRoomInfo(data.roomId, data.peerId || client.clientId);
463
+ updateRoomInfo(data.roomId, client.clientId);
464
464
  });
465
465
 
466
466
  client.on('peer-joined', (data) => {
@@ -481,7 +481,7 @@
481
481
  });
482
482
 
483
483
  client.on('peer-left', (data) => {
484
- const peerId = data.peerId || data.clientId;
484
+ const peerId = data.peerId;
485
485
  log(`Peer left: ${peerId}`, 'warning');
486
486
  // Remove from known peers
487
487
  knownPeers = knownPeers.filter(id => id !== peerId);
@@ -511,7 +511,7 @@
511
511
  await pc.setLocalDescription(answer);
512
512
 
513
513
  // Send answer back
514
- client.sendAnswer(data.peerId, answer);
514
+ client.sendAnswer(answer, data.peerId);
515
515
  } catch (e) {
516
516
  log(`Offer error: ${e.message}`, 'error');
517
517
  }
@@ -552,8 +552,8 @@
552
552
  });
553
553
 
554
554
  client.on('chat', (data) => {
555
- displayChatMessage(data.text, `${data.senderId.substring(0, 6)}...`, false);
556
- log(`Chat from ${data.senderId}: ${data.text}`, 'info');
555
+ displayChatMessage(data.text, `${data.peerId.substring(0, 6)}...`, false);
556
+ log(`Chat from ${data.peerId}: ${data.text}`, 'info');
557
557
  });
558
558
 
559
559
  await client.connect();
@@ -635,7 +635,7 @@
635
635
  pc.onicecandidate = (event) => {
636
636
  if (event.candidate) {
637
637
  log(`Sending ICE candidate to ${peerId.substring(0, 6)}...`, 'info');
638
- client.sendIceCandidate(peerId, event.candidate);
638
+ client.sendIceCandidate(event.candidate, peerId);
639
639
  }
640
640
  };
641
641
 
@@ -649,7 +649,7 @@
649
649
 
650
650
  const offer = await pc.createOffer();
651
651
  await pc.setLocalDescription(offer);
652
- client.sendOffer(peerId, offer);
652
+ client.sendOffer(offer, peerId);
653
653
  log(`Sent offer to ${peerId.substring(0, 6)}...`, 'success');
654
654
  }
655
655
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uniwrtc",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A universal WebRTC signaling service",
5
5
  "main": "server.js",
6
6
  "scripts": {
package/server.js CHANGED
@@ -208,8 +208,7 @@ function handleJoin(ws, message) {
208
208
  // Notify other clients in the room
209
209
  broadcastToRoom(roomId, {
210
210
  type: 'peer-joined',
211
- peerId: ws.clientId,
212
- clientId: ws.clientId
211
+ peerId: ws.clientId
213
212
  }, ws);
214
213
  }
215
214
 
@@ -228,7 +227,7 @@ function handleLeave(ws, message) {
228
227
  // Notify other clients
229
228
  broadcastToRoom(roomId, {
230
229
  type: 'peer-left',
231
- clientId: ws.clientId
230
+ peerId: ws.clientId
232
231
  });
233
232
 
234
233
  // Clean up empty rooms
@@ -294,7 +293,7 @@ function handleChat(ws, message) {
294
293
  client.send(JSON.stringify({
295
294
  type: 'chat',
296
295
  text: text,
297
- senderId: ws.clientId,
296
+ peerId: ws.clientId,
298
297
  roomId: roomId
299
298
  }));
300
299
  }
@@ -128,7 +128,7 @@ class UniWRTCClient {
128
128
  }
129
129
  }
130
130
 
131
- sendOffer(targetId, offer) {
131
+ sendOffer(offer, targetId) {
132
132
  this.send({
133
133
  type: 'offer',
134
134
  offer: offer,
@@ -136,7 +136,7 @@ class UniWRTCClient {
136
136
  });
137
137
  }
138
138
 
139
- sendAnswer(targetId, answer) {
139
+ sendAnswer(answer, targetId) {
140
140
  this.send({
141
141
  type: 'answer',
142
142
  answer: answer,
@@ -144,7 +144,7 @@ class UniWRTCClient {
144
144
  });
145
145
  }
146
146
 
147
- sendIceCandidate(targetId, candidate) {
147
+ sendIceCandidate(candidate, targetId) {
148
148
  this.send({
149
149
  type: 'ice-candidate',
150
150
  candidate: candidate,
@@ -197,12 +197,12 @@ class UniWRTCClient {
197
197
  break;
198
198
  case 'peer-joined':
199
199
  this.emit('peer-joined', {
200
- clientId: message.clientId
200
+ peerId: message.peerId
201
201
  });
202
202
  break;
203
203
  case 'peer-left':
204
204
  this.emit('peer-left', {
205
- clientId: message.clientId
205
+ peerId: message.peerId
206
206
  });
207
207
  break;
208
208
  case 'offer':
@@ -236,7 +236,7 @@ class UniWRTCClient {
236
236
  case 'chat':
237
237
  this.emit('chat', {
238
238
  text: message.text,
239
- senderId: message.senderId,
239
+ peerId: message.peerId,
240
240
  roomId: message.roomId
241
241
  });
242
242
  break;
package/src/room.js CHANGED
@@ -89,11 +89,11 @@ export class Room {
89
89
 
90
90
  const client = this.clients.get(clientId);
91
91
  if (client && client.readyState === WebSocket.OPEN) {
92
- // Send joined confirmation
92
+ // Send joined confirmation (align with server schema)
93
93
  client.send(JSON.stringify({
94
94
  type: 'joined',
95
95
  roomId: roomId,
96
- peerId: peerId || clientId,
96
+ clientId: clientId,
97
97
  clients: peers
98
98
  }));
99
99
  }
@@ -101,8 +101,7 @@ export class Room {
101
101
  // Notify other peers
102
102
  this.broadcast({
103
103
  type: 'peer-joined',
104
- peerId: peerId || clientId,
105
- clientId: clientId
104
+ peerId: clientId
106
105
  }, clientId);
107
106
  }
108
107