peerpigeon 1.0.0 → 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/README.md CHANGED
@@ -8,6 +8,11 @@
8
8
 
9
9
  PeerPigeon is a production-ready library for building decentralized applications with true mesh networking, encrypted distributed storage, and selective media streaming. It handles peer discovery, connection management, and message routing automatically.
10
10
 
11
+ > **⚠️ IMPORTANT: Local Testing Requirement**
12
+ > When testing on `localhost`, WebRTC connections require **media permissions** (microphone/camera) due to browser security.
13
+ > **Solution**: Click the "Media" tab in the browser example and grant permissions, or see [docs/LOCAL_TESTING.md](docs/LOCAL_TESTING.md) for details.
14
+ > This is **NOT required** for production HTTPS deployments.
15
+
11
16
  ## ✨ Key Features
12
17
 
13
18
  - **🕸️ True Mesh Networking** - Gossip protocol + XOR distance routing (Kademlia-inspired)
@@ -49,16 +54,28 @@ mesh.on('messageReceived', ({ from, content }) => {
49
54
  ### Run Signaling Server
50
55
 
51
56
  ```bash
52
- # Option 1: Use npm script
53
- npm start
57
+ # Start both hub and HTTP server for testing
58
+ npm run dev
54
59
 
55
- # Option 2: Custom port
56
- PORT=8080 npm start
60
+ # Or run them separately:
61
+ npm run dev:hub # Just the signaling hub
62
+ npm run dev:http # Just the HTTP server
57
63
 
58
- # Option 3: Run as a hub (multi-server mesh)
59
- npm run hub
64
+ # Custom port
65
+ PORT=8080 npm run hub
60
66
  ```
61
67
 
68
+ ### Local Testing
69
+
70
+ For localhost testing, you need to grant media permissions:
71
+
72
+ 1. Open browser example: `http://localhost:8080/`
73
+ 2. Go to **Media** tab
74
+ 3. Click **Start Media** button
75
+ 4. Allow microphone/camera access
76
+
77
+ See [docs/LOCAL_TESTING.md](docs/LOCAL_TESTING.md) for full details.
78
+
62
79
  ## 📚 Examples
63
80
 
64
81
  ### Distributed Storage
@@ -3155,31 +3155,8 @@ ${b64.match(/.{1,64}/g).join("\n")}
3155
3155
  }
3156
3156
  });
3157
3157
 
3158
- // node_modules/@koush/wrtc/lib/browser.js
3159
- var require_browser = __commonJS({
3160
- "node_modules/@koush/wrtc/lib/browser.js"(exports) {
3161
- "use strict";
3162
- exports.MediaStream = window.MediaStream;
3163
- exports.MediaStreamTrack = window.MediaStreamTrack;
3164
- exports.RTCDataChannel = window.RTCDataChannel;
3165
- exports.RTCDataChannelEvent = window.RTCDataChannelEvent;
3166
- exports.RTCDtlsTransport = window.RTCDtlsTransport;
3167
- exports.RTCIceCandidate = window.RTCIceCandidate;
3168
- exports.RTCIceTransport = window.RTCIceTransport;
3169
- exports.RTCPeerConnection = window.RTCPeerConnection;
3170
- exports.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
3171
- exports.RTCRtpReceiver = window.RTCRtpReceiver;
3172
- exports.RTCRtpSender = window.RTCRtpSender;
3173
- exports.RTCRtpTransceiver = window.RTCRtpTransceiver;
3174
- exports.RTCSctpTransport = window.RTCSctpTransport;
3175
- exports.RTCSessionDescription = window.RTCSessionDescription;
3176
- exports.getUserMedia = window.getUserMedia;
3177
- exports.mediaDevices = navigator.mediaDevices;
3178
- }
3179
- });
3180
-
3181
3158
  // node_modules/ws/browser.js
3182
- var require_browser2 = __commonJS({
3159
+ var require_browser = __commonJS({
3183
3160
  "node_modules/ws/browser.js"(exports, module) {
3184
3161
  "use strict";
3185
3162
  module.exports = function() {
@@ -3204,12 +3181,185 @@ ${b64.match(/.{1,64}/g).join("\n")}
3204
3181
  getEnvironmentReport: () => getEnvironmentReport,
3205
3182
  hasWebRTC: () => hasWebRTC,
3206
3183
  hasWebSocket: () => hasWebSocket,
3184
+ initWebRTCAsync: () => initWebRTCAsync,
3207
3185
  isBrowser: () => isBrowser2,
3208
3186
  isNodeJS: () => isNodeJS,
3209
3187
  isWorker: () => isWorker
3210
3188
  });
3211
3189
  init_unsea();
3212
3190
 
3191
+ // src/PigeonRTC-browser.js
3192
+ var RTCAdapter = class {
3193
+ getRTCPeerConnection() {
3194
+ throw new Error("getRTCPeerConnection must be implemented by adapter");
3195
+ }
3196
+ getRTCSessionDescription() {
3197
+ throw new Error("getRTCSessionDescription must be implemented by adapter");
3198
+ }
3199
+ getRTCIceCandidate() {
3200
+ throw new Error("getRTCIceCandidate must be implemented by adapter");
3201
+ }
3202
+ getMediaStream() {
3203
+ return null;
3204
+ }
3205
+ isSupported() {
3206
+ throw new Error("isSupported must be implemented by adapter");
3207
+ }
3208
+ getName() {
3209
+ throw new Error("getName must be implemented by adapter");
3210
+ }
3211
+ async initialize() {
3212
+ }
3213
+ async getUserMedia(_constraints) {
3214
+ throw new Error("getUserMedia not supported by this adapter");
3215
+ }
3216
+ async getDisplayMedia(_constraints) {
3217
+ throw new Error("getDisplayMedia not supported by this adapter");
3218
+ }
3219
+ };
3220
+ var BrowserRTCAdapter = class extends RTCAdapter {
3221
+ constructor() {
3222
+ super();
3223
+ this._checkSupport();
3224
+ }
3225
+ _checkSupport() {
3226
+ if (typeof window === "undefined" || typeof navigator === "undefined") {
3227
+ return;
3228
+ }
3229
+ this.hasRTCPeerConnection = !!(window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection);
3230
+ this.hasGetUserMedia = !!(navigator.mediaDevices?.getUserMedia || navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia);
3231
+ this.hasGetDisplayMedia = !!navigator.mediaDevices?.getDisplayMedia;
3232
+ }
3233
+ getRTCPeerConnection() {
3234
+ if (typeof window === "undefined") {
3235
+ throw new Error("BrowserRTCAdapter requires a browser environment");
3236
+ }
3237
+ return window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
3238
+ }
3239
+ getRTCSessionDescription() {
3240
+ if (typeof window === "undefined") {
3241
+ throw new Error("BrowserRTCAdapter requires a browser environment");
3242
+ }
3243
+ return window.RTCSessionDescription || window.mozRTCSessionDescription;
3244
+ }
3245
+ getRTCIceCandidate() {
3246
+ if (typeof window === "undefined") {
3247
+ throw new Error("BrowserRTCAdapter requires a browser environment");
3248
+ }
3249
+ return window.RTCIceCandidate || window.mozRTCIceCandidate;
3250
+ }
3251
+ getMediaStream() {
3252
+ if (typeof window === "undefined") {
3253
+ return null;
3254
+ }
3255
+ return window.MediaStream || window.webkitMediaStream;
3256
+ }
3257
+ isSupported() {
3258
+ return typeof window !== "undefined" && this.hasRTCPeerConnection;
3259
+ }
3260
+ getName() {
3261
+ return "BrowserRTCAdapter";
3262
+ }
3263
+ async getUserMedia(constraints) {
3264
+ if (typeof navigator === "undefined") {
3265
+ throw new Error("getUserMedia requires a browser environment");
3266
+ }
3267
+ if (navigator.mediaDevices?.getUserMedia) {
3268
+ return await navigator.mediaDevices.getUserMedia(constraints);
3269
+ }
3270
+ const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
3271
+ if (!getUserMedia) {
3272
+ throw new Error("getUserMedia is not supported in this browser");
3273
+ }
3274
+ return new Promise((resolve, reject) => {
3275
+ getUserMedia.call(navigator, constraints, resolve, reject);
3276
+ });
3277
+ }
3278
+ async getDisplayMedia(constraints) {
3279
+ if (typeof navigator === "undefined") {
3280
+ throw new Error("getDisplayMedia requires a browser environment");
3281
+ }
3282
+ if (!navigator.mediaDevices?.getDisplayMedia) {
3283
+ throw new Error("getDisplayMedia is not supported in this browser");
3284
+ }
3285
+ return await navigator.mediaDevices.getDisplayMedia(constraints);
3286
+ }
3287
+ };
3288
+ var PigeonRTC = class {
3289
+ constructor(options = {}) {
3290
+ this.adapter = options.adapter || null;
3291
+ this.initialized = false;
3292
+ }
3293
+ async initialize(options = {}) {
3294
+ if (this.initialized) {
3295
+ return;
3296
+ }
3297
+ if (options.adapter) {
3298
+ this.adapter = options.adapter;
3299
+ }
3300
+ if (!this.adapter) {
3301
+ this.adapter = new BrowserRTCAdapter();
3302
+ }
3303
+ await this.adapter.initialize();
3304
+ this.initialized = true;
3305
+ }
3306
+ _ensureInitialized() {
3307
+ if (!this.initialized || !this.adapter) {
3308
+ throw new Error("PigeonRTC not initialized. Call initialize() first.");
3309
+ }
3310
+ }
3311
+ getRTCPeerConnection() {
3312
+ this._ensureInitialized();
3313
+ return this.adapter.getRTCPeerConnection();
3314
+ }
3315
+ getRTCSessionDescription() {
3316
+ this._ensureInitialized();
3317
+ return this.adapter.getRTCSessionDescription();
3318
+ }
3319
+ getRTCIceCandidate() {
3320
+ this._ensureInitialized();
3321
+ return this.adapter.getRTCIceCandidate();
3322
+ }
3323
+ getMediaStream() {
3324
+ this._ensureInitialized();
3325
+ return this.adapter.getMediaStream();
3326
+ }
3327
+ createPeerConnection(config) {
3328
+ this._ensureInitialized();
3329
+ const RTCPeerConnection2 = this.adapter.getRTCPeerConnection();
3330
+ return new RTCPeerConnection2(config);
3331
+ }
3332
+ createSessionDescription(init) {
3333
+ this._ensureInitialized();
3334
+ const RTCSessionDescription = this.adapter.getRTCSessionDescription();
3335
+ return new RTCSessionDescription(init);
3336
+ }
3337
+ createIceCandidate(init) {
3338
+ this._ensureInitialized();
3339
+ const RTCIceCandidate = this.adapter.getRTCIceCandidate();
3340
+ return new RTCIceCandidate(init);
3341
+ }
3342
+ async getUserMedia(constraints) {
3343
+ this._ensureInitialized();
3344
+ return await this.adapter.getUserMedia(constraints);
3345
+ }
3346
+ async getDisplayMedia(constraints) {
3347
+ this._ensureInitialized();
3348
+ return await this.adapter.getDisplayMedia(constraints);
3349
+ }
3350
+ isSupported() {
3351
+ return this.adapter ? this.adapter.isSupported() : false;
3352
+ }
3353
+ getAdapterName() {
3354
+ return this.adapter ? this.adapter.getName() : "None";
3355
+ }
3356
+ };
3357
+ async function createPigeonRTC(options = {}) {
3358
+ const rtc = new PigeonRTC(options);
3359
+ await rtc.initialize(options);
3360
+ return rtc;
3361
+ }
3362
+
3213
3363
  // src/EventEmitter.js
3214
3364
  var EventEmitter = class {
3215
3365
  constructor() {
@@ -3311,6 +3461,7 @@ ${b64.match(/.{1,64}/g).join("\n")}
3311
3461
  var EnvironmentDetector = class _EnvironmentDetector {
3312
3462
  constructor() {
3313
3463
  this._cache = /* @__PURE__ */ new Map();
3464
+ this._pigeonRTC = null;
3314
3465
  this._init();
3315
3466
  }
3316
3467
  _init() {
@@ -3323,45 +3474,26 @@ ${b64.match(/.{1,64}/g).join("\n")}
3323
3474
  this._cache.set("isDeno", this._detectDeno());
3324
3475
  this._cache.set("isBun", this._detectBun());
3325
3476
  this._cache.set("isNativeScript", this._detectNativeScript());
3326
- if (this._cache.get("isNodeJS")) {
3327
- this._initNodeWebRTC();
3328
- }
3477
+ this._initPigeonRTC();
3329
3478
  }
3330
3479
  /**
3331
- * Initialize WebRTC polyfill for Node.js environment
3332
- * Attempts to load @koush/wrtc and set up WebRTC globals
3480
+ * Initialize PigeonRTC for cross-platform WebRTC support
3481
+ * PigeonRTC provides a unified WebRTC interface across browser and Node.js
3333
3482
  * @private
3334
3483
  */
3335
- _initNodeWebRTC() {
3484
+ _initPigeonRTC() {
3336
3485
  try {
3337
- if (typeof globalThis !== "undefined" && typeof globalThis.RTCPeerConnection !== "undefined") {
3338
- return;
3339
- }
3340
- let wrtc;
3341
- if (typeof __require !== "undefined") {
3342
- try {
3343
- wrtc = require_browser();
3344
- } catch (e) {
3345
- try {
3346
- wrtc = __require("node-webrtc");
3347
- } catch (e2) {
3348
- return;
3349
- }
3350
- }
3351
- } else {
3352
- return;
3353
- }
3354
- if (wrtc && typeof globalThis !== "undefined") {
3355
- globalThis.RTCPeerConnection = wrtc.RTCPeerConnection;
3356
- globalThis.RTCSessionDescription = wrtc.RTCSessionDescription;
3357
- globalThis.RTCIceCandidate = wrtc.RTCIceCandidate;
3358
- globalThis.MediaStream = wrtc.MediaStream || globalThis.MediaStream;
3359
- globalThis.MediaStreamTrack = wrtc.MediaStreamTrack || globalThis.MediaStreamTrack;
3360
- this._webrtcPolyfilled = true;
3361
- }
3486
+ this._webrtcPolyfilled = false;
3362
3487
  } catch (error) {
3363
3488
  }
3364
3489
  }
3490
+ /**
3491
+ * Get the PigeonRTC instance
3492
+ * @returns {PigeonRTC|null} The PigeonRTC instance or null if not initialized
3493
+ */
3494
+ getPigeonRTC() {
3495
+ return this._pigeonRTC;
3496
+ }
3365
3497
  // Primary environment detection
3366
3498
  _detectBrowser() {
3367
3499
  return typeof window !== "undefined" && typeof document !== "undefined" && typeof navigator !== "undefined";
@@ -3426,6 +3558,9 @@ ${b64.match(/.{1,64}/g).join("\n")}
3426
3558
  }
3427
3559
  // WebRTC capability detection
3428
3560
  get hasWebRTC() {
3561
+ if (this._pigeonRTC) {
3562
+ return this._pigeonRTC.isSupported();
3563
+ }
3429
3564
  if (this.isBrowser) {
3430
3565
  return typeof RTCPeerConnection !== "undefined" || typeof webkitRTCPeerConnection !== "undefined" || typeof mozRTCPeerConnection !== "undefined";
3431
3566
  }
@@ -3718,40 +3853,39 @@ ${b64.match(/.{1,64}/g).join("\n")}
3718
3853
  };
3719
3854
  }
3720
3855
  /**
3721
- * Asynchronously initialize WebRTC polyfill for Node.js environment
3722
- * This method is useful for ES module environments where dynamic imports are preferred
3856
+ * Asynchronously initialize WebRTC using PigeonRTC
3857
+ * This method initializes PigeonRTC for cross-platform WebRTC support
3723
3858
  * @returns {Promise<boolean>} True if WebRTC was successfully initialized
3724
3859
  */
3725
3860
  async initWebRTCAsync() {
3726
- if (!this.isNodeJS) {
3727
- return false;
3728
- }
3729
3861
  try {
3730
- if (typeof globalThis !== "undefined" && typeof globalThis.RTCPeerConnection !== "undefined") {
3862
+ if (this._pigeonRTC) {
3731
3863
  return true;
3732
3864
  }
3733
- let wrtc;
3734
- try {
3735
- wrtc = await Promise.resolve().then(() => __toESM(require_browser(), 1));
3736
- } catch (e) {
3865
+ let createPigeonRTC2;
3866
+ if (typeof globalThis !== "undefined" && globalThis.__PEERPIGEON_PIGEONRTC__) {
3867
+ createPigeonRTC2 = globalThis.__PEERPIGEON_PIGEONRTC__.createPigeonRTC || globalThis.__PEERPIGEON_PIGEONRTC__.default;
3868
+ } else if (typeof window !== "undefined" && window.__PEERPIGEON_PIGEONRTC__) {
3869
+ createPigeonRTC2 = window.__PEERPIGEON_PIGEONRTC__.createPigeonRTC || window.__PEERPIGEON_PIGEONRTC__.default;
3870
+ }
3871
+ if (!createPigeonRTC2 && this.isNodeJS) {
3737
3872
  try {
3738
- wrtc = await import("node-webrtc");
3739
- } catch (e2) {
3740
- return false;
3873
+ const pigeonRTCModule = await import("pigeonrtc");
3874
+ createPigeonRTC2 = pigeonRTCModule.createPigeonRTC || pigeonRTCModule.default;
3875
+ } catch (error) {
3876
+ console.error("Failed to dynamically import PigeonRTC:", error);
3741
3877
  }
3742
3878
  }
3743
- if (wrtc && typeof globalThis !== "undefined") {
3744
- globalThis.RTCPeerConnection = wrtc.RTCPeerConnection || wrtc.default?.RTCPeerConnection;
3745
- globalThis.RTCSessionDescription = wrtc.RTCSessionDescription || wrtc.default?.RTCSessionDescription;
3746
- globalThis.RTCIceCandidate = wrtc.RTCIceCandidate || wrtc.default?.RTCIceCandidate;
3747
- globalThis.MediaStream = wrtc.MediaStream || wrtc.default?.MediaStream || globalThis.MediaStream;
3748
- globalThis.MediaStreamTrack = wrtc.MediaStreamTrack || wrtc.default?.MediaStreamTrack || globalThis.MediaStreamTrack;
3749
- this._webrtcPolyfilled = true;
3750
- return true;
3879
+ if (!createPigeonRTC2) {
3880
+ throw new Error("PigeonRTC createPigeonRTC function not found");
3751
3881
  }
3882
+ this._pigeonRTC = await createPigeonRTC2();
3883
+ this._webrtcPolyfilled = true;
3884
+ return this._pigeonRTC.isSupported();
3752
3885
  } catch (error) {
3886
+ console.error("Failed to initialize PigeonRTC:", error);
3887
+ return false;
3753
3888
  }
3754
- return false;
3755
3889
  }
3756
3890
  // Static method for quick environment check
3757
3891
  static detect() {
@@ -3770,6 +3904,7 @@ ${b64.match(/.{1,64}/g).join("\n")}
3770
3904
  var hasWebRTC = () => environmentDetector.hasWebRTC;
3771
3905
  var hasWebSocket = () => environmentDetector.hasWebSocket;
3772
3906
  var getEnvironmentReport = () => environmentDetector.getEnvironmentReport();
3907
+ var initWebRTCAsync = () => environmentDetector.initWebRTCAsync();
3773
3908
 
3774
3909
  // src/DebugLogger.js
3775
3910
  var DebugLogger = class {
@@ -3968,7 +4103,7 @@ ${b64.match(/.{1,64}/g).join("\n")}
3968
4103
  }
3969
4104
  try {
3970
4105
  if (typeof __require !== "undefined") {
3971
- const WebSocket2 = require_browser2();
4106
+ const WebSocket2 = require_browser();
3972
4107
  return new WebSocket2(url);
3973
4108
  } else {
3974
4109
  this.debug.warn('WebSocket package detection not available in ES modules. Ensure "ws" is installed.');
@@ -4501,7 +4636,13 @@ ${b64.match(/.{1,64}/g).join("\n")}
4501
4636
  this.emit("connectionFailed", { peerId: this.peerId, reason: error.message });
4502
4637
  throw error;
4503
4638
  }
4504
- this.connection = new RTCPeerConnection({
4639
+ const pigeonRTC = environmentDetector.getPigeonRTC();
4640
+ if (!pigeonRTC) {
4641
+ const error = new Error("PigeonRTC not initialized - call initWebRTCAsync() first");
4642
+ this.emit("connectionFailed", { peerId: this.peerId, reason: error.message });
4643
+ throw error;
4644
+ }
4645
+ this.connection = pigeonRTC.createPeerConnection({
4505
4646
  iceServers: [
4506
4647
  { urls: "stun:stun.l.google.com:19302" },
4507
4648
  { urls: "stun:stun1.l.google.com:19302" },
@@ -6362,13 +6503,18 @@ ${b64.match(/.{1,64}/g).join("\n")}
6362
6503
  for (const [peerId, peerConnection] of this.peers) {
6363
6504
  if (peerConnection.connection?.signalingState === "have-local-offer") {
6364
6505
  const connectionAge = Date.now() - peerConnection.connectionStartTime;
6365
- if (connectionAge > 2e3) {
6506
+ if (connectionAge > 1e4) {
6366
6507
  stuckConnections.push(peerId);
6367
6508
  }
6368
6509
  }
6369
6510
  }
6370
6511
  if (stuckConnections.length > 0) {
6371
6512
  this.debug.log(`\u{1F6A8} STUCK MONITOR: Found ${stuckConnections.length} stuck connections - forcing recovery`);
6513
+ if (typeof window !== "undefined" && window.location?.hostname === "localhost") {
6514
+ console.warn("\u26A0\uFE0F LOCAL TESTING: WebRTC connections on localhost require media permissions!");
6515
+ console.warn(' Go to the Media tab and click "Start Media" to grant permissions.');
6516
+ console.warn(" See docs/LOCAL_TESTING.md for details.");
6517
+ }
6372
6518
  for (const peerId of stuckConnections) {
6373
6519
  this.forceConnectionRecovery(peerId).catch((error) => {
6374
6520
  this.debug.error(`Failed to recover stuck connection for ${peerId}:`, error);
@@ -6785,9 +6931,15 @@ ${b64.match(/.{1,64}/g).join("\n")}
6785
6931
  }
6786
6932
  const peerConnection = this.connectionManager.getPeer(fromPeerId);
6787
6933
  this.debug.log(`\u{1F504} ANSWER RECEIVE DEBUG: Found peer connection: ${!!peerConnection}`);
6934
+ const allPeerIds = Array.from(this.connectionManager.peers.keys());
6935
+ this.debug.log(`\u{1F504} ANSWER RECEIVE DEBUG: All current peers (${allPeerIds.length}): ${allPeerIds.map((p) => p.substring(0, 8)).join(", ")}`);
6788
6936
  if (peerConnection) {
6789
6937
  this.debug.log(`\u{1F504} ANSWER RECEIVE DEBUG: Peer connection state: ${peerConnection.connection?.signalingState}`);
6790
6938
  this.debug.log(`\u{1F504} ANSWER RECEIVE DEBUG: Is initiator: ${peerConnection.isInitiator}`);
6939
+ this.debug.log(`\u{1F504} ANSWER RECEIVE DEBUG: Connection age: ${Date.now() - peerConnection.connectionStartTime}ms`);
6940
+ } else {
6941
+ this.debug.error(`\u{1F504} ANSWER RECEIVE DEBUG: NO PEER CONNECTION - Was expecting peer ${fromPeerId.substring(0, 8)}...`);
6942
+ this.debug.error(`\u{1F504} ANSWER RECEIVE DEBUG: This means the peer connection was cleaned up or never created!`);
6791
6943
  }
6792
6944
  if (peerConnection) {
6793
6945
  try {
@@ -6805,7 +6957,8 @@ ${b64.match(/.{1,64}/g).join("\n")}
6805
6957
  }
6806
6958
  }
6807
6959
  } else {
6808
- this.debug.log("\u274C ANSWER RECEIVE DEBUG: No peer connection found for answer from", fromPeerId);
6960
+ this.debug.error("\u274C ANSWER RECEIVE DEBUG: No peer connection found for answer from", fromPeerId);
6961
+ this.debug.error("\u274C ANSWER RECEIVE DEBUG: Peer connection may have been cleaned up prematurely - check connection timeout/cleanup logic");
6809
6962
  }
6810
6963
  }
6811
6964
  handleConnectionRejected(data, fromPeerId) {
@@ -8088,7 +8241,12 @@ ${b64.match(/.{1,64}/g).join("\n")}
8088
8241
  if (!video && !audio) {
8089
8242
  throw new Error("At least one of video or audio must be enabled");
8090
8243
  }
8091
- this.localStream = await navigator.mediaDevices.getUserMedia(constraints);
8244
+ const pigeonRTC = environmentDetector.getPigeonRTC();
8245
+ if (pigeonRTC) {
8246
+ this.localStream = await pigeonRTC.getUserMedia(constraints);
8247
+ } else {
8248
+ this.localStream = await navigator.mediaDevices.getUserMedia(constraints);
8249
+ }
8092
8250
  this.isVideoEnabled = video;
8093
8251
  this.isAudioEnabled = audio;
8094
8252
  this.markStreamAsLocal(this.localStream);
@@ -8178,10 +8336,11 @@ ${b64.match(/.{1,64}/g).join("\n")}
8178
8336
  * Check if browser supports required APIs
8179
8337
  */
8180
8338
  static checkSupport() {
8339
+ const pigeonRTC = environmentDetector.getPigeonRTC();
8181
8340
  const support = {
8182
8341
  getUserMedia: !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia),
8183
8342
  enumerateDevices: !!(navigator.mediaDevices && navigator.mediaDevices.enumerateDevices),
8184
- webRTC: !!window.RTCPeerConnection
8343
+ webRTC: pigeonRTC ? pigeonRTC.isSupported() : !!window.RTCPeerConnection
8185
8344
  };
8186
8345
  support.fullSupport = support.getUserMedia && support.enumerateDevices && support.webRTC;
8187
8346
  return support;
@@ -10964,14 +11123,34 @@ ${b64.match(/.{1,64}/g).join("\n")}
10964
11123
  }
10965
11124
  async init() {
10966
11125
  try {
10967
- if (this.runtimeInfo?.isNodeJS) {
11126
+ try {
11127
+ const webrtcInitialized = await environmentDetector.initWebRTCAsync();
11128
+ if (webrtcInitialized) {
11129
+ const adapterName = environmentDetector.getPigeonRTC()?.getAdapterName();
11130
+ this.debug.log(`\u{1F310} PigeonRTC initialized successfully (${adapterName})`);
11131
+ }
11132
+ } catch (error) {
11133
+ this.debug.warn("PigeonRTC initialization failed:", error.message);
11134
+ }
11135
+ if (environmentDetector.isBrowser) {
10968
11136
  try {
10969
- const webrtcInitialized = await environmentDetector.initWebRTCAsync();
10970
- if (webrtcInitialized) {
10971
- this.debug.log("\u{1F310} WebRTC polyfill initialized successfully for Node.js environment");
11137
+ const isLocalhost = window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "";
11138
+ if (isLocalhost && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
11139
+ this.debug.log("\u{1F3A4} Requesting media permissions for localhost WebRTC...");
11140
+ const stream = await navigator.mediaDevices.getUserMedia({
11141
+ audio: true,
11142
+ video: false
11143
+ }).catch((err) => {
11144
+ this.debug.warn("Media permission denied - connections may fail on localhost:", err.message);
11145
+ return null;
11146
+ });
11147
+ if (stream) {
11148
+ stream.getTracks().forEach((track) => track.stop());
11149
+ this.debug.log("\u2705 Media permissions granted - localhost connections will work");
11150
+ }
10972
11151
  }
10973
11152
  } catch (error) {
10974
- this.debug.warn("WebRTC polyfill initialization failed:", error.message);
11153
+ this.debug.warn("Could not request media permissions:", error.message);
10975
11154
  }
10976
11155
  }
10977
11156
  if (this.providedPeerId) {
@@ -12274,11 +12453,25 @@ ${b64.match(/.{1,64}/g).join("\n")}
12274
12453
  // src/browser-entry.js
12275
12454
  if (typeof globalThis !== "undefined") {
12276
12455
  globalThis.__PEERPIGEON_UNSEA__ = unsea_exports;
12456
+ globalThis.__PEERPIGEON_PIGEONRTC__ = {
12457
+ createPigeonRTC,
12458
+ PigeonRTC,
12459
+ BrowserRTCAdapter,
12460
+ RTCAdapter,
12461
+ default: createPigeonRTC
12462
+ };
12277
12463
  }
12278
12464
  if (typeof window !== "undefined") {
12279
12465
  window.__PEERPIGEON_UNSEA__ = unsea_exports;
12466
+ window.__PEERPIGEON_PIGEONRTC__ = {
12467
+ createPigeonRTC,
12468
+ PigeonRTC,
12469
+ BrowserRTCAdapter,
12470
+ RTCAdapter,
12471
+ default: createPigeonRTC
12472
+ };
12280
12473
  }
12281
- console.log("\u{1F510} PeerPigeon browser bundle loaded with embedded UnSEA crypto");
12474
+ console.log("\u{1F510} PeerPigeon browser bundle loaded with embedded UnSEA crypto and PigeonRTC");
12282
12475
  return __toCommonJS(browser_entry_exports);
12283
12476
  })();
12284
12477
  /*! Bundled license information: