mirror of
https://github.com/xtr-dev/rondevu-client.git
synced 2025-12-10 10:53:24 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d7075ccc4 | |||
| db8f0f4ced | |||
| 3a227a21ac | |||
| de1f3eac9c |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@xtr-dev/rondevu-client": "^0.5.1"
|
"@xtr-dev/rondevu-client": "^0.5.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/rondevu-client",
|
"name": "@xtr-dev/rondevu-client",
|
||||||
"version": "0.7.1",
|
"version": "0.7.3",
|
||||||
"description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
|
"description": "TypeScript client for Rondevu topic-based peer discovery and signaling server",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -25,13 +25,17 @@ export class AnsweringState extends PeerState {
|
|||||||
|
|
||||||
// Create answer
|
// Create answer
|
||||||
const answer = await this.peer.pc.createAnswer();
|
const answer = await this.peer.pc.createAnswer();
|
||||||
await this.peer.pc.setLocalDescription(answer);
|
|
||||||
|
|
||||||
// Send answer to server immediately (don't wait for ICE)
|
// Send answer to server BEFORE setLocalDescription
|
||||||
|
// This registers us as the answerer so ICE candidates will be accepted
|
||||||
await this.peer.offersApi.answer(offerId, answer.sdp!);
|
await this.peer.offersApi.answer(offerId, answer.sdp!);
|
||||||
|
|
||||||
// Enable trickle ICE - send candidates as they arrive
|
// Enable trickle ICE - set up handler before ICE gathering starts
|
||||||
this.setupIceCandidateHandler(offerId);
|
this.setupIceCandidateHandler();
|
||||||
|
|
||||||
|
// Set local description - ICE gathering starts here
|
||||||
|
// Server already knows we're the answerer, so candidates will be accepted
|
||||||
|
await this.peer.pc.setLocalDescription(answer);
|
||||||
|
|
||||||
// Transition to exchanging ICE
|
// Transition to exchanging ICE
|
||||||
const { ExchangingIceState } = await import('./exchanging-ice-state.js');
|
const { ExchangingIceState } = await import('./exchanging-ice-state.js');
|
||||||
|
|||||||
@@ -24,9 +24,13 @@ export class CreatingOfferState extends PeerState {
|
|||||||
this.peer.emitEvent('datachannel', channel);
|
this.peer.emitEvent('datachannel', channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable trickle ICE - set up handler before ICE gathering starts
|
||||||
|
// Handler will check this.peer.offerId before sending
|
||||||
|
this.setupIceCandidateHandler();
|
||||||
|
|
||||||
// Create WebRTC offer
|
// Create WebRTC offer
|
||||||
const offer = await this.peer.pc.createOffer();
|
const offer = await this.peer.pc.createOffer();
|
||||||
await this.peer.pc.setLocalDescription(offer);
|
await this.peer.pc.setLocalDescription(offer); // ICE gathering starts here
|
||||||
|
|
||||||
// Send offer to server immediately (don't wait for ICE)
|
// Send offer to server immediately (don't wait for ICE)
|
||||||
const offers = await this.peer.offersApi.create([{
|
const offers = await this.peer.offersApi.create([{
|
||||||
@@ -36,10 +40,7 @@ export class CreatingOfferState extends PeerState {
|
|||||||
}]);
|
}]);
|
||||||
|
|
||||||
const offerId = offers[0].id;
|
const offerId = offers[0].id;
|
||||||
this.peer.offerId = offerId;
|
this.peer.offerId = offerId; // Now handler can send candidates
|
||||||
|
|
||||||
// Enable trickle ICE - send candidates as they arrive
|
|
||||||
this.setupIceCandidateHandler(offerId);
|
|
||||||
|
|
||||||
// Transition to waiting for answer
|
// Transition to waiting for answer
|
||||||
const { WaitingForAnswerState } = await import('./waiting-for-answer-state.js');
|
const { WaitingForAnswerState } = await import('./waiting-for-answer-state.js');
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ export abstract class PeerState {
|
|||||||
* Setup trickle ICE candidate handler
|
* Setup trickle ICE candidate handler
|
||||||
* Sends local ICE candidates to server as they are discovered
|
* Sends local ICE candidates to server as they are discovered
|
||||||
*/
|
*/
|
||||||
protected setupIceCandidateHandler(offerId: string): void {
|
protected setupIceCandidateHandler(): void {
|
||||||
this.iceCandidateHandler = async (event: RTCPeerConnectionIceEvent) => {
|
this.iceCandidateHandler = async (event: RTCPeerConnectionIceEvent) => {
|
||||||
if (event.candidate && offerId) {
|
if (event.candidate && this.peer.offerId) {
|
||||||
const candidateData = event.candidate.toJSON();
|
const candidateData = event.candidate.toJSON();
|
||||||
if (candidateData.candidate && candidateData.candidate !== '') {
|
if (candidateData.candidate && candidateData.candidate !== '') {
|
||||||
try {
|
try {
|
||||||
await this.peer.offersApi.addIceCandidates(offerId, [candidateData]);
|
await this.peer.offersApi.addIceCandidates(this.peer.offerId, [candidateData]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error sending ICE candidate:', err);
|
console.error('Error sending ICE candidate:', err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user