peerpigeon 1.0.0 → 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.
@@ -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" },
@@ -8088,7 +8229,12 @@ ${b64.match(/.{1,64}/g).join("\n")}
8088
8229
  if (!video && !audio) {
8089
8230
  throw new Error("At least one of video or audio must be enabled");
8090
8231
  }
8091
- this.localStream = await navigator.mediaDevices.getUserMedia(constraints);
8232
+ const pigeonRTC = environmentDetector.getPigeonRTC();
8233
+ if (pigeonRTC) {
8234
+ this.localStream = await pigeonRTC.getUserMedia(constraints);
8235
+ } else {
8236
+ this.localStream = await navigator.mediaDevices.getUserMedia(constraints);
8237
+ }
8092
8238
  this.isVideoEnabled = video;
8093
8239
  this.isAudioEnabled = audio;
8094
8240
  this.markStreamAsLocal(this.localStream);
@@ -8178,10 +8324,11 @@ ${b64.match(/.{1,64}/g).join("\n")}
8178
8324
  * Check if browser supports required APIs
8179
8325
  */
8180
8326
  static checkSupport() {
8327
+ const pigeonRTC = environmentDetector.getPigeonRTC();
8181
8328
  const support = {
8182
8329
  getUserMedia: !!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia),
8183
8330
  enumerateDevices: !!(navigator.mediaDevices && navigator.mediaDevices.enumerateDevices),
8184
- webRTC: !!window.RTCPeerConnection
8331
+ webRTC: pigeonRTC ? pigeonRTC.isSupported() : !!window.RTCPeerConnection
8185
8332
  };
8186
8333
  support.fullSupport = support.getUserMedia && support.enumerateDevices && support.webRTC;
8187
8334
  return support;
@@ -10964,15 +11111,14 @@ ${b64.match(/.{1,64}/g).join("\n")}
10964
11111
  }
10965
11112
  async init() {
10966
11113
  try {
10967
- if (this.runtimeInfo?.isNodeJS) {
10968
- try {
10969
- const webrtcInitialized = await environmentDetector.initWebRTCAsync();
10970
- if (webrtcInitialized) {
10971
- this.debug.log("\u{1F310} WebRTC polyfill initialized successfully for Node.js environment");
10972
- }
10973
- } catch (error) {
10974
- this.debug.warn("WebRTC polyfill initialization failed:", error.message);
11114
+ try {
11115
+ const webrtcInitialized = await environmentDetector.initWebRTCAsync();
11116
+ if (webrtcInitialized) {
11117
+ const adapterName = environmentDetector.getPigeonRTC()?.getAdapterName();
11118
+ this.debug.log(`\u{1F310} PigeonRTC initialized successfully (${adapterName})`);
10975
11119
  }
11120
+ } catch (error) {
11121
+ this.debug.warn("PigeonRTC initialization failed:", error.message);
10976
11122
  }
10977
11123
  if (this.providedPeerId) {
10978
11124
  if (_PeerPigeonMesh.validatePeerId(this.providedPeerId)) {
@@ -12274,11 +12420,25 @@ ${b64.match(/.{1,64}/g).join("\n")}
12274
12420
  // src/browser-entry.js
12275
12421
  if (typeof globalThis !== "undefined") {
12276
12422
  globalThis.__PEERPIGEON_UNSEA__ = unsea_exports;
12423
+ globalThis.__PEERPIGEON_PIGEONRTC__ = {
12424
+ createPigeonRTC,
12425
+ PigeonRTC,
12426
+ BrowserRTCAdapter,
12427
+ RTCAdapter,
12428
+ default: createPigeonRTC
12429
+ };
12277
12430
  }
12278
12431
  if (typeof window !== "undefined") {
12279
12432
  window.__PEERPIGEON_UNSEA__ = unsea_exports;
12433
+ window.__PEERPIGEON_PIGEONRTC__ = {
12434
+ createPigeonRTC,
12435
+ PigeonRTC,
12436
+ BrowserRTCAdapter,
12437
+ RTCAdapter,
12438
+ default: createPigeonRTC
12439
+ };
12280
12440
  }
12281
- console.log("\u{1F510} PeerPigeon browser bundle loaded with embedded UnSEA crypto");
12441
+ console.log("\u{1F510} PeerPigeon browser bundle loaded with embedded UnSEA crypto and PigeonRTC");
12282
12442
  return __toCommonJS(browser_entry_exports);
12283
12443
  })();
12284
12444
  /*! Bundled license information: