@leofcoin/peernet 0.15.2 → 0.16.0

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.
@@ -1,839 +0,0 @@
1
- (self["webpackChunk_leofcoin_peernet"] = self["webpackChunk_leofcoin_peernet"] || []).push([[629],{
2
-
3
- /***/ 96:
4
- /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5
-
6
- // ESM COMPAT FLAG
7
- __webpack_require__.r(__webpack_exports__);
8
-
9
- // EXPORTS
10
- __webpack_require__.d(__webpack_exports__, {
11
- "default": function() { return /* binding */ Client; }
12
- });
13
-
14
- ;// CONCATENATED MODULE: ./node_modules/socket-request-client/dist/es/index.js
15
- /* provided dependency */ var process = __webpack_require__(155);
16
- /* socket-request-client version 1.6.3 */
17
- const ENVIRONMENT = {version: '1.6.3', production: true};
18
-
19
- class LittlePubSub {
20
- constructor(verbose = true) {
21
- this.subscribers = {};
22
- this.verbose = verbose;
23
- }
24
- subscribe(event, handler, context) {
25
- if (typeof context === 'undefined') {
26
- context = handler;
27
- }
28
- this.subscribers[event] = this.subscribers[event] || { handlers: [], value: null};
29
- this.subscribers[event].handlers.push(handler.bind(context));
30
- }
31
- unsubscribe(event, handler, context) {
32
- if (typeof context === 'undefined') {
33
- context = handler;
34
- }
35
- if (this.subscribers[event]) {
36
- const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
37
- this.subscribers[event].handlers.splice(index);
38
- if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
39
- }
40
- }
41
- publish(event, change) {
42
- if (this.subscribers[event]) {
43
- if (this.verbose || this.subscribers[event].value !== change) {
44
- this.subscribers[event].value = change;
45
- this.subscribers[event].handlers.forEach(handler => {
46
- handler(change, this.subscribers[event].value);
47
- });
48
- }
49
- }
50
- }
51
- }
52
-
53
- var clientApi = _pubsub => {
54
- const subscribe = (topic, cb) => {
55
- _pubsub.subscribe(topic, cb);
56
- };
57
- const unsubscribe = (topic, cb) => {
58
- _pubsub.unsubscribe(topic, cb);
59
- };
60
- const publish = (topic, value) => {
61
- _pubsub.publish(topic, value);
62
- };
63
- const _connectionState = (state) => {
64
- switch (state) {
65
- case 0:
66
- return 'connecting'
67
- case 1:
68
- return 'open'
69
- case 2:
70
- return 'closing'
71
- case 3:
72
- return 'closed'
73
- }
74
- };
75
- const request = (client, request) => {
76
- return new Promise((resolve, reject) => {
77
- const state = _connectionState(client.readyState);
78
- if (state !== 'open') return reject(`coudn't send request to ${client.id}, no open connection found.`)
79
- request.id = Math.random().toString(36).slice(-12);
80
- const handler = result => {
81
- if (result && result.error) return reject(result.error)
82
- resolve({result, id: request.id, handler});
83
- unsubscribe(request.id, handler);
84
- };
85
- subscribe(request.id, handler);
86
- send(client, request);
87
- });
88
- };
89
- const send = async (client, request) => {
90
- return client.send(JSON.stringify(request))
91
- };
92
- const pubsub = client => {
93
- return {
94
- publish: (topic = 'pubsub', value) => {
95
- return send(client, {url: 'pubsub', params: { topic, value }})
96
- },
97
- subscribe: (topic = 'pubsub', cb) => {
98
- subscribe(topic, cb);
99
- return send(client, {url: 'pubsub', params: { topic, subscribe: true }})
100
- },
101
- unsubscribe: (topic = 'pubsub', cb) => {
102
- unsubscribe(topic, cb);
103
- return send(client, {url: 'pubsub', params: { topic, unsubscribe: true }})
104
- },
105
- subscribers: _pubsub.subscribers
106
- }
107
- };
108
- const server = (client) => {
109
- return {
110
- uptime: async () => {
111
- try {
112
- const { result, id, handler } = await request(client, {url: 'uptime'});
113
- unsubscribe(id, handler);
114
- return result
115
- } catch (e) {
116
- throw e
117
- }
118
- },
119
- ping: async () => {
120
- try {
121
- const now = new Date().getTime();
122
- const { result, id, handler } = await request(client, {url: 'ping'});
123
- unsubscribe(id, handler);
124
- return (Number(result) - now)
125
- } catch (e) {
126
- throw e
127
- }
128
- }
129
- }
130
- };
131
- const peernet = (client) => {
132
- return {
133
- join: async (params) => {
134
- try {
135
- params.join = true;
136
- const requested = { url: 'peernet', params };
137
- const { result, id, handler } = await request(client, requested);
138
- unsubscribe(id, handler);
139
- return result
140
- } catch (e) {
141
- throw e
142
- }
143
- },
144
- leave: async (params) => {
145
- try {
146
- params.join = false;
147
- const requested = { url: 'peernet', params };
148
- const { result, id, handler } = await request(client, requested);
149
- unsubscribe(id, handler);
150
- return result
151
- } catch (e) {
152
- throw e
153
- }
154
- }
155
- }
156
- };
157
- return { send, request, pubsub, server, subscribe, unsubscribe, publish, peernet }
158
- };
159
-
160
- if (!globalThis.PubSub) globalThis.PubSub = LittlePubSub;
161
- if (!globalThis.pubsub) globalThis.pubsub = new LittlePubSub({verbose: false});
162
- const socketRequestClient = (url, protocols = 'echo-protocol', options = { retry: false }) => {
163
- const { retry } = options;
164
- const api = clientApi(pubsub);
165
- let tries = 0;
166
- const onerror = error => {
167
- if (pubsub.subscribers['error']) {
168
- pubsub.publish('error', error);
169
- } else {
170
- console.error(error);
171
- }
172
- };
173
- const onmessage = message => {
174
- const {value, url, status, id} = JSON.parse(message.data.toString());
175
- const publisher = id ? id : url;
176
- if (status === 200) {
177
- pubsub.publish(publisher, value);
178
- } else {
179
- pubsub.publish(publisher, {error: value});
180
- }
181
- };
182
- const clientConnection = client => {
183
- const startTime = new Date().getTime();
184
- return {
185
- client,
186
- request: async req => {
187
- const { result, id, handler } = await api.request(client, req);
188
- pubsub.unsubscribe(id, handler);
189
- return result
190
- },
191
- send: req => api.send(client, req),
192
- subscribe: api.subscribe,
193
- unsubscribe: api.unsubscribe,
194
- subscribers: api.subscribers,
195
- publish: api.publish,
196
- pubsub: api.pubsub(client),
197
- uptime: () => {
198
- const now = new Date().getTime();
199
- return (now - startTime)
200
- },
201
- peernet: api.peernet(client),
202
- server: api.server(client),
203
- close: exit => {
204
- client.close();
205
- }
206
- }
207
- };
208
- return new Promise((resolve, reject) => {
209
- const init = () => {
210
- let ws;
211
- if (typeof process === 'object' && !globalThis.WebSocket) {
212
- ws = (__webpack_require__(840).w3cwebsocket);
213
- } else {
214
- ws = WebSocket;
215
- }
216
- const client = new ws(url, protocols);
217
- client.onmessage = onmessage;
218
- client.onerror = onerror;
219
- client.onopen = () => {
220
- tries = 0;
221
- resolve(clientConnection(client));
222
- };
223
- client.onclose = message => {
224
- tries++;
225
- if (!retry) return reject(options)
226
- if (tries > 5) {
227
- console.log(`${protocols} Client Closed`);
228
- console.error(`could not connect to - ${url}/`);
229
- return resolve(clientConnection(client))
230
- }
231
- if (message.code === 1006) {
232
- console.log('Retrying in 10 seconds');
233
- setTimeout(() => {
234
- return init();
235
- }, retry);
236
- }
237
- };
238
- };
239
- return init();
240
- });
241
- };
242
-
243
-
244
-
245
- // EXTERNAL MODULE: ./node_modules/@vandeurenglenn/debug/debug.js
246
- var debug_debug = __webpack_require__(307);
247
- ;// CONCATENATED MODULE: ./node_modules/@leofcoin/peernet-swarm/src/client/peer.js
248
-
249
-
250
- class Peer {
251
- #connection
252
- #connected = false
253
- #messageQue = []
254
- #chunksQue = {}
255
- #channel
256
- #peerId
257
- #channelName
258
- #chunkSize = 16 * 1024 // 16384
259
- #queRunning = false
260
- #MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024
261
-
262
- get connection() {
263
- return this.#connection
264
- }
265
-
266
- get connected() {
267
- return this.#connected
268
- }
269
-
270
- get readyState() {
271
- return this.#channel?.readyState
272
- }
273
-
274
- /**
275
- * @params {Object} options
276
- * @params {string} options.channelName - this peerid : otherpeer id
277
- */
278
- constructor(options = {}) {
279
- this._in = this._in.bind(this);
280
- this.offerOptions = options.offerOptions
281
- this.initiator = options.initiator
282
- this.streams = options.streams
283
- this.socketClient = options.socketClient
284
- this.id = options.id
285
- this.to = options.to
286
- this.bw = {
287
- up: 0,
288
- down: 0
289
- }
290
-
291
- this.#channelName = options.channelName
292
-
293
- this.#peerId = options.peerId
294
- this.options = options
295
- return this.#init()
296
- }
297
-
298
- get peerId() {
299
- return this.#peerId
300
- }
301
-
302
- set socketClient(value) {
303
- // this.socketClient?.pubsub.unsubscribe('signal', this._in)
304
- this._socketClient = value
305
- this._socketClient.pubsub.subscribe('signal', this._in)
306
- }
307
-
308
- get socketClient() {
309
- return this._socketClient
310
- }
311
-
312
- splitMessage(message) {
313
- const chunks = []
314
- message = pako.deflate(message)
315
- const size = message.byteLength || message.length
316
- let offset = 0
317
- return new Promise((resolve, reject) => {
318
- const splitMessage = () => {
319
- const chunk = message.slice(offset, offset + this.#chunkSize > size ? size : offset + this.#chunkSize)
320
- offset += this.#chunkSize
321
- chunks.push(chunk)
322
- if (offset < size) return splitMessage()
323
- else resolve({chunks, size})
324
- }
325
-
326
- splitMessage()
327
- })
328
- }
329
-
330
- async #runQue() {
331
- this.#queRunning = true
332
- if (this.#messageQue.length > 0 && this.#channel?.bufferedAmount + this.#messageQue[0]?.length < this.#MAX_BUFFERED_AMOUNT) {
333
- const message = this.#messageQue.shift()
334
-
335
- switch (this.#channel?.readyState) {
336
- case 'open':
337
- await this.#channel.send(message);
338
- if (this.#messageQue.length > 0) return this.#runQue()
339
- else this.#queRunning = false
340
- break;
341
- case 'closed':
342
- case 'closing':
343
- this.#messageQue = []
344
- this.#queRunning = false
345
- debug('channel already closed, this usually means a bad implementation, try checking the readyState or check if the peer is connected before sending');
346
- break;
347
- case undefined:
348
- this.#messageQue = []
349
- this.#queRunning = false
350
- debug(`trying to send before a channel is created`);
351
- break;
352
- }
353
-
354
-
355
- } else {
356
- return setTimeout(() => this.#runQue(), 50)
357
- }
358
- }
359
-
360
- #trySend({ size, id, chunks }) {
361
- let offset = 0
362
-
363
- for (const chunk of chunks) {
364
- const start = offset
365
- const end = offset + chunk.length
366
-
367
- const message = new TextEncoder().encode(JSON.stringify({ size, id, chunk, start, end }));
368
- this.#messageQue.push(message)
369
- }
370
-
371
- if (!this.queRunning) return this.#runQue()
372
- }
373
-
374
- async send(message, id) {
375
- const { chunks, size } = await this.splitMessage(message)
376
- return this.#trySend({ size, id, chunks })
377
- }
378
-
379
- request(data) {
380
- return new Promise((resolve, reject) => {
381
- const id = Math.random().toString(36).slice(-12)
382
-
383
- const _onData = message => {
384
- if (message.id === id) {
385
- resolve(message.data)
386
- pubsub.unsubscribe(`peer:data`, _onData)
387
- }
388
- }
389
-
390
- pubsub.subscribe(`peer:data`, _onData)
391
-
392
- // cleanup subscriptions
393
- // setTimeout(() => {
394
- // pubsub.unsubscribe(`peer:data-request-${id}`, _onData)
395
- // }, 5000);
396
-
397
- this.send(data, id)
398
- })
399
- }
400
-
401
- async #init() {
402
- try {
403
-
404
- if (!globalThis.pako) {
405
- const importee = await __webpack_require__.e(/* import() | pako */ 682).then(__webpack_require__.bind(__webpack_require__, 885))
406
- globalThis.pako = importee.default
407
- }
408
-
409
- const iceServers = [{
410
- urls: 'stun:stun.l.google.com:19302' // Google's public STUN server
411
- }, {
412
- urls: "stun:openrelay.metered.ca:80",
413
- }, {
414
- urls: "turn:openrelay.metered.ca:443",
415
- username: "openrelayproject",
416
- credential: "openrelayproject",
417
- }, {
418
- urls: "turn:openrelay.metered.ca:443?transport=tcp",
419
- username: "openrelayproject",
420
- credential: "openrelayproject",
421
- }]
422
-
423
- this.#connection = new wrtc.RTCPeerConnection({iceServers});
424
-
425
- this.#connection.onicecandidate = ({ candidate }) => {
426
- if (candidate) {
427
- this.address = candidate.address
428
- this.port = candidate.port
429
- this.protocol = candidate.protocol
430
- this.ipFamily = this.address.includes('::') ? 'ipv6': 'ipv4'
431
- this._sendMessage({candidate})
432
- }
433
- }
434
- // if (this.initiator) this.#connection.onnegotiationneeded = () => {
435
- // console.log('create offer');
436
- this.#connection.ondatachannel = (message) => {
437
- message.channel.onopen = () => {
438
- this.#connected = true
439
- debug(`peer:connected ${this}`)
440
- pubsub.publish('peer:connected', this)
441
- }
442
- message.channel.onclose = () => this.close.bind(this)
443
-
444
- message.channel.onmessage = (message) => {
445
- this._handleMessage(this.id, message)
446
- }
447
- this.#channel = message.channel
448
- }
449
- if (this.initiator) {
450
-
451
- this.#channel = this.#connection.createDataChannel('messageChannel')
452
- this.#channel.onopen = () => {
453
- this.#connected = true
454
- pubsub.publish('peer:connected', this)
455
- // this.#channel.send('hi')
456
- }
457
- this.#channel.onclose = () => this.close.bind(this)
458
-
459
- this.#channel.onmessage = (message) => {
460
- this._handleMessage(this.peerId, message)
461
- }
462
-
463
- const offer = await this.#connection.createOffer()
464
- await this.#connection.setLocalDescription(offer)
465
-
466
- this._sendMessage({'sdp': this.#connection.localDescription})
467
- }
468
- } catch (e) {
469
- console.log(e);
470
- }
471
-
472
- return this
473
- }
474
-
475
- _handleMessage(peerId, message) {
476
- debug(`incoming message from ${peerId}`)
477
-
478
- message = JSON.parse(new TextDecoder().decode(message.data))
479
- // allow sharding (multiple peers share data)
480
- pubsub.publish('peernet:shard', message)
481
- const { id } = message
482
-
483
- if (!this.#chunksQue[id]) this.#chunksQue[id] = []
484
-
485
- if (message.size > this.#chunksQue[id].length || message.size === this.#chunksQue[id].length) {
486
- for (const value of Object.values(message.chunk)) {
487
- this.#chunksQue[id].push(value)
488
- }
489
- }
490
-
491
- if (message.size === this.#chunksQue[id].length) {
492
- let data = new Uint8Array(Object.values(this.#chunksQue[id]))
493
- delete this.#chunksQue[id]
494
- data = pako.inflate(data)
495
- pubsub.publish('peer:data', { id, data, from: this.peerId })
496
- }
497
- this.bw.down += message.byteLength || message.length
498
- }
499
-
500
- _sendMessage(message) {
501
- this.socketClient.send({url: 'signal', params: {
502
- to: this.to,
503
- from: this.id,
504
- channelName: this.options.channelName,
505
- ...message
506
- }})
507
- }
508
-
509
- async _in(message, data) {
510
- // message = JSON.parse(message);
511
- if (!this.#connection || message.to !== this.id || message.from !== this.#peerId) return
512
- // if (data.videocall) return this._startStream(true, false); // start video and audio stream
513
- // if (data.call) return this._startStream(true, true); // start audio stream
514
- if (this.#connection?.signalinState === 'stable' && this.#connection?.remoteDescription !== null && this.#connection?.localDescription !== null) return
515
-
516
-
517
- if (message.candidate) {
518
- debug(`incoming candidate ${this.#channelName}`)
519
- // debug(message.candidate.candidate)
520
- this.remoteAddress = message.candidate.address
521
- this.remotePort = message.candidate.port
522
- this.remoteProtocol = message.candidate.protocol
523
- this.remoteIpFamily = this.remoteAddress?.includes('::') ? 'ipv6': 'ipv4'
524
- return this.#connection.addIceCandidate(new wrtc.RTCIceCandidate(message.candidate));
525
- }
526
- try {
527
- if (message.sdp) {
528
- if (message.sdp.type === 'offer') {
529
- debug(`incoming offer ${this.#channelName}`)
530
- await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
531
- const answer = await this.#connection.createAnswer();
532
- await this.#connection.setLocalDescription(answer)
533
- this._sendMessage({'sdp': this.#connection.localDescription})
534
- }
535
- if (message.sdp.type === 'answer') {
536
- debug(`incoming answer ${this.#channelName}`)
537
- await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
538
- }
539
- }
540
- } catch (e) {
541
- console.log(e);
542
- }
543
- }
544
-
545
- close() {
546
- debug(`closing ${this.peerId}`)
547
- this.#connected = false
548
- this.#channel?.close()
549
- this.#connection?.close()
550
-
551
- this.socketClient.pubsub.unsubscribe('signal', this._in)
552
- }
553
- }
554
-
555
- ;// CONCATENATED MODULE: ./node_modules/@leofcoin/peernet-swarm/src/client/client.js
556
-
557
-
558
-
559
-
560
- class Client {
561
- #peerConnection
562
- #connections = {}
563
- #stars = {}
564
-
565
- get connections() {
566
- return { ...this.#connections }
567
- }
568
-
569
- get peers() {
570
- return Object.entries(this.#connections)
571
- }
572
-
573
- constructor(id, network = 'leofcoin:peach', stars = ['wss://peach.leofcoin.org']) {
574
- this.id = id || Math.random().toString(36).slice(-12);
575
- this.peerJoined = this.peerJoined.bind(this)
576
- this.peerLeft = this.peerLeft.bind(this)
577
- this.starLeft = this.starLeft.bind(this)
578
- this.starJoined = this.starJoined.bind(this)
579
-
580
- this._init(network, stars)
581
- }
582
-
583
- async _init(network, stars = []) {
584
- this.network = network
585
- this.starsConfig = stars
586
- // reconnectJob()
587
-
588
- if (!globalThis.RTCPeerConnection) globalThis.wrtc = await __webpack_require__.e(/* import() | wrtc */ 228).then(__webpack_require__.t.bind(__webpack_require__, 347, 19))
589
- else globalThis.wrtc = {
590
- RTCPeerConnection,
591
- RTCSessionDescription,
592
- RTCIceCandidate
593
- }
594
-
595
- for (const star of stars) {
596
- try {
597
- this.socketClient = await socketRequestClient(star, network)
598
- const id = await this.socketClient.request({url: 'id', params: {from: this.id}})
599
- this.socketClient.peerId = id
600
- this.#stars[id] = this.socketClient
601
- } catch (e) {
602
- if (stars.indexOf(star) === stars.length -1 && !this.socketClient) throw new Error(`No star available to connect`);
603
- }
604
- }
605
- const peers = await this.socketClient.peernet.join({id: this.id})
606
- for (const id of peers) {
607
- if (id !== this.id && !this.#connections[id]) this.#connections[id] = await new Peer({channelName: `${id}:${this.id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id})
608
- }
609
- this.setupListeners()
610
- }
611
-
612
- setupListeners() {
613
- this.socketClient.subscribe('peer:joined', this.peerJoined)
614
- this.socketClient.subscribe('peer:left', this.peerLeft)
615
- this.socketClient.subscribe('star:left', this.starLeft)
616
- }
617
-
618
- starJoined(id) {
619
- if (this.#stars[id]) {
620
- this.#stars[id].close()
621
- delete this.#stars[id]
622
- }
623
- console.log(`star ${id} joined`);
624
- }
625
-
626
- async starLeft(id) {
627
- if (this.#stars[id]) {
628
- this.#stars[id].close()
629
- delete this.#stars[id]
630
- }
631
- if (this.socketClient?.peerId === id) {
632
-
633
- this.socketClient.unsubscribe('peer:joined', this.peerJoined)
634
- this.socketClient.unsubscribe('peer:left', this.peerLeft)
635
- this.socketClient.unsubscribe('star:left', this.starLeft)
636
- this.socketClient.close()
637
- this.socketClient = undefined
638
-
639
- for (const star of this.starsConfig) {
640
- try {
641
- this.socketClient = await socketRequestClient(star, this.network)
642
- if (!this.socketClient?.client?._connection.connected) return
643
- const id = await this.socketClient.request({url: 'id', params: {from: this.id}})
644
- this.#stars[id] = this.socketClient
645
-
646
- this.socketClient.peerId = id
647
-
648
- const peers = await this.socketClient.peernet.join({id: this.id})
649
- this.setupListeners()
650
- for (const id of peers) {
651
- if (id !== this.id) {
652
- // close connection
653
- if (this.#connections[id]) {
654
- if (this.#connections[id].connected) await this.#connections[id].close()
655
- delete this.#connections[id]
656
- }
657
- // reconnect
658
- if (id !== this.id) this.#connections[id] = await new Peer({channelName: `${id}:${this.id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id})
659
- }
660
-
661
- }
662
- } catch (e) {
663
- console.log(e);
664
- if (this.starsConfig.indexOf(star) === this.starsConfig.length -1 && !this.socketClient) throw new Error(`No star available to connect`);
665
- }
666
- }
667
- }
668
- debug(`star ${id} left`);
669
- }
670
-
671
- peerLeft(peer) {
672
- const id = peer.peerId || peer
673
- if (this.#connections[id]) {
674
- this.#connections[id].close()
675
- delete this.#connections[id]
676
- }
677
- debug(`peer ${id} left`)
678
- }
679
-
680
- async peerJoined(peer, signal) {
681
- const id = peer.peerId || peer
682
- if (this.#connections[id]) {
683
- if (this.#connections[id].connected) this.#connections[id].close()
684
- delete this.#connections[id]
685
- }
686
- // RTCPeerConnection
687
- this.#connections[id] = await new Peer({initiator: true, channelName: `${this.id}:${id}`, socketClient: this.socketClient, id: this.id, to: id, peerId: id})
688
- debug(`peer ${id} joined`)
689
- }
690
-
691
- removePeer(peer) {
692
- const id = peer.peerId || peer
693
- if (this.#connections[id]) {
694
- this.#connections[id].connected && this.#connections[id].close()
695
- delete this.#connections[id]
696
- }
697
- debug(`peer ${id} removed`)
698
- }
699
-
700
- async close() {
701
-
702
- this.socketClient.unsubscribe('peer:joined', this.peerJoined)
703
- this.socketClient.unsubscribe('peer:left', this.peerLeft)
704
- this.socketClient.unsubscribe('star:left', this.starLeft)
705
-
706
- const promises = [
707
- Object.values(this.#connections).map(connection => connection.close()),
708
- Object.values(this.#stars).map(connection => connection.close()),
709
- this.socketClient.close()
710
- ]
711
-
712
- return Promise.allSettled(promises)
713
-
714
- }
715
-
716
- }
717
-
718
-
719
- /***/ }),
720
-
721
- /***/ 284:
722
- /***/ (function(module) {
723
-
724
- var naiveFallback = function () {
725
- if (typeof self === "object" && self) return self;
726
- if (typeof window === "object" && window) return window;
727
- throw new Error("Unable to resolve global `this`");
728
- };
729
-
730
- module.exports = (function () {
731
- if (this) return this;
732
-
733
- // Unexpected strict mode (may happen if e.g. bundled into ESM module)
734
-
735
- // Fallback to standard globalThis if available
736
- if (typeof globalThis === "object" && globalThis) return globalThis;
737
-
738
- // Thanks @mathiasbynens -> https://mathiasbynens.be/notes/globalthis
739
- // In all ES5+ engines global object inherits from Object.prototype
740
- // (if you approached one that doesn't please report)
741
- try {
742
- Object.defineProperty(Object.prototype, "__global__", {
743
- get: function () { return this; },
744
- configurable: true
745
- });
746
- } catch (error) {
747
- // Unfortunate case of updates to Object.prototype being restricted
748
- // via preventExtensions, seal or freeze
749
- return naiveFallback();
750
- }
751
- try {
752
- // Safari case (window.__global__ works, but __global__ does not)
753
- if (!__global__) return naiveFallback();
754
- return __global__;
755
- } finally {
756
- delete Object.prototype.__global__;
757
- }
758
- })();
759
-
760
-
761
- /***/ }),
762
-
763
- /***/ 840:
764
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
765
-
766
- var _globalThis;
767
- if (typeof globalThis === 'object') {
768
- _globalThis = globalThis;
769
- } else {
770
- try {
771
- _globalThis = __webpack_require__(284);
772
- } catch (error) {
773
- } finally {
774
- if (!_globalThis && typeof window !== 'undefined') { _globalThis = window; }
775
- if (!_globalThis) { throw new Error('Could not determine global this'); }
776
- }
777
- }
778
-
779
- var NativeWebSocket = _globalThis.WebSocket || _globalThis.MozWebSocket;
780
- var websocket_version = __webpack_require__(387);
781
-
782
-
783
- /**
784
- * Expose a W3C WebSocket class with just one or two arguments.
785
- */
786
- function W3CWebSocket(uri, protocols) {
787
- var native_instance;
788
-
789
- if (protocols) {
790
- native_instance = new NativeWebSocket(uri, protocols);
791
- }
792
- else {
793
- native_instance = new NativeWebSocket(uri);
794
- }
795
-
796
- /**
797
- * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
798
- * class). Since it is an Object it will be returned as it is when creating an
799
- * instance of W3CWebSocket via 'new W3CWebSocket()'.
800
- *
801
- * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
802
- */
803
- return native_instance;
804
- }
805
- if (NativeWebSocket) {
806
- ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function(prop) {
807
- Object.defineProperty(W3CWebSocket, prop, {
808
- get: function() { return NativeWebSocket[prop]; }
809
- });
810
- });
811
- }
812
-
813
- /**
814
- * Module exports.
815
- */
816
- module.exports = {
817
- 'w3cwebsocket' : NativeWebSocket ? W3CWebSocket : null,
818
- 'version' : websocket_version
819
- };
820
-
821
-
822
- /***/ }),
823
-
824
- /***/ 387:
825
- /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
826
-
827
- module.exports = __webpack_require__(794).version;
828
-
829
-
830
- /***/ }),
831
-
832
- /***/ 794:
833
- /***/ (function(module) {
834
-
835
- module.exports = {"version":"1.0.34"};
836
-
837
- /***/ })
838
-
839
- }])