@leofcoin/peernet 0.14.16 → 0.14.17
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/dist/browser/peernet.js +25 -28
- package/package.json +1 -1
package/dist/browser/peernet.js
CHANGED
|
@@ -6637,23 +6637,12 @@ var debug_debug = __webpack_require__(307);
|
|
|
6637
6637
|
|
|
6638
6638
|
class Peer {
|
|
6639
6639
|
#connection
|
|
6640
|
-
#connecting = false
|
|
6641
6640
|
#connected = false
|
|
6642
|
-
#channelReady = false
|
|
6643
|
-
#destroying = false
|
|
6644
|
-
#destroyed = false
|
|
6645
|
-
#isNegotiating = false
|
|
6646
|
-
#firstNegotiation = true
|
|
6647
|
-
#iceComplete = false
|
|
6648
|
-
#remoteTracks = []
|
|
6649
|
-
#remoteStreams = []
|
|
6650
|
-
#pendingCandidates = []
|
|
6651
|
-
#senderMap = new Map()
|
|
6652
6641
|
#messageQue = []
|
|
6653
6642
|
#chunksQue = {}
|
|
6654
|
-
#iceCompleteTimer
|
|
6655
6643
|
#channel
|
|
6656
6644
|
#peerId
|
|
6645
|
+
#channelName
|
|
6657
6646
|
#chunkSize = 16 * 1024 // 16384
|
|
6658
6647
|
#queRunning = false
|
|
6659
6648
|
#MAX_BUFFERED_AMOUNT = 16 * 1024 * 1024
|
|
@@ -6667,7 +6656,7 @@ class Peer {
|
|
|
6667
6656
|
}
|
|
6668
6657
|
|
|
6669
6658
|
get readyState() {
|
|
6670
|
-
return this
|
|
6659
|
+
return this.#channel?.readyState
|
|
6671
6660
|
}
|
|
6672
6661
|
|
|
6673
6662
|
/**
|
|
@@ -6687,7 +6676,7 @@ class Peer {
|
|
|
6687
6676
|
down: 0
|
|
6688
6677
|
}
|
|
6689
6678
|
|
|
6690
|
-
this
|
|
6679
|
+
this.#channelName = options.channelName
|
|
6691
6680
|
|
|
6692
6681
|
this.#peerId = options.peerId
|
|
6693
6682
|
this.options = options
|
|
@@ -6728,12 +6717,12 @@ class Peer {
|
|
|
6728
6717
|
|
|
6729
6718
|
async #runQue() {
|
|
6730
6719
|
this.#queRunning = true
|
|
6731
|
-
if (this.#messageQue.length > 0 && this
|
|
6720
|
+
if (this.#messageQue.length > 0 && this.#channel?.bufferedAmount + this.#messageQue[0]?.length < this.#MAX_BUFFERED_AMOUNT) {
|
|
6732
6721
|
const message = this.#messageQue.shift()
|
|
6733
6722
|
|
|
6734
|
-
switch (this
|
|
6723
|
+
switch (this.#channel?.readyState) {
|
|
6735
6724
|
case 'open':
|
|
6736
|
-
await this
|
|
6725
|
+
await this.#channel.send(message);
|
|
6737
6726
|
if (this.#messageQue.length > 0) return this.#runQue()
|
|
6738
6727
|
else this.#queRunning = false
|
|
6739
6728
|
break;
|
|
@@ -6842,19 +6831,19 @@ class Peer {
|
|
|
6842
6831
|
message.channel.onmessage = (message) => {
|
|
6843
6832
|
this._handleMessage(this.id, message)
|
|
6844
6833
|
}
|
|
6845
|
-
this
|
|
6834
|
+
this.#channel = message.channel
|
|
6846
6835
|
}
|
|
6847
6836
|
if (this.initiator) {
|
|
6848
6837
|
|
|
6849
|
-
this
|
|
6850
|
-
this
|
|
6838
|
+
this.#channel = this.#connection.createDataChannel('messageChannel')
|
|
6839
|
+
this.#channel.onopen = () => {
|
|
6851
6840
|
this.#connected = true
|
|
6852
6841
|
pubsub.publish('peer:connected', this)
|
|
6853
|
-
// this
|
|
6842
|
+
// this.#channel.send('hi')
|
|
6854
6843
|
}
|
|
6855
|
-
this
|
|
6844
|
+
this.#channel.onclose = () => this.close.bind(this)
|
|
6856
6845
|
|
|
6857
|
-
this
|
|
6846
|
+
this.#channel.onmessage = (message) => {
|
|
6858
6847
|
this._handleMessage(this.peerId, message)
|
|
6859
6848
|
}
|
|
6860
6849
|
|
|
@@ -6904,31 +6893,39 @@ class Peer {
|
|
|
6904
6893
|
}})
|
|
6905
6894
|
}
|
|
6906
6895
|
|
|
6896
|
+
isReallyStable(signalinState) {
|
|
6897
|
+
if (signalinState !== 'stable') return false
|
|
6898
|
+
// remoteDescription & localDescription are null when the connection is just made
|
|
6899
|
+
if (this.#connection.remoteDescription === null && this.#connection.localDescription === null) return false
|
|
6900
|
+
return true
|
|
6901
|
+
}
|
|
6902
|
+
|
|
6907
6903
|
async _in(message, data) {
|
|
6908
6904
|
// message = JSON.parse(message);
|
|
6909
6905
|
if (message.to !== this.id) return
|
|
6910
6906
|
// if (data.videocall) return this._startStream(true, false); // start video and audio stream
|
|
6911
6907
|
// if (data.call) return this._startStream(true, true); // start audio stream
|
|
6912
6908
|
if (message.candidate) {
|
|
6913
|
-
debug(`incoming candidate ${this
|
|
6909
|
+
debug(`incoming candidate ${this.#channelName}`)
|
|
6914
6910
|
debug(message.candidate.candidate)
|
|
6915
6911
|
this.remoteAddress = message.candidate.address
|
|
6916
6912
|
this.remotePort = message.candidate.port
|
|
6917
6913
|
this.remoteProtocol = message.candidate.protocol
|
|
6918
6914
|
this.remoteIpFamily = this.remoteAddress?.includes('::') ? 'ipv6': 'ipv4'
|
|
6919
|
-
|
|
6915
|
+
const signalinState = this.#connection.signalinState
|
|
6916
|
+
if (signalinState !== 'closed' && this.isReallyStable(signalinState)) return this.#connection.addIceCandidate(new wrtc.RTCIceCandidate(message.candidate));
|
|
6920
6917
|
}
|
|
6921
6918
|
try {
|
|
6922
6919
|
if (message.sdp) {
|
|
6923
6920
|
if (message.sdp.type === 'offer') {
|
|
6924
|
-
debug(`incoming offer ${this
|
|
6921
|
+
debug(`incoming offer ${this.#channelName}`)
|
|
6925
6922
|
await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
|
|
6926
6923
|
const answer = await this.#connection.createAnswer();
|
|
6927
6924
|
await this.#connection.setLocalDescription(answer)
|
|
6928
6925
|
this._sendMessage({'sdp': this.#connection.localDescription})
|
|
6929
6926
|
}
|
|
6930
6927
|
if (message.sdp.type === 'answer') {
|
|
6931
|
-
debug(`incoming answer ${this
|
|
6928
|
+
debug(`incoming answer ${this.#channelName}`)
|
|
6932
6929
|
await this.#connection.setRemoteDescription(new wrtc.RTCSessionDescription(message.sdp))
|
|
6933
6930
|
}
|
|
6934
6931
|
}
|
|
@@ -6940,7 +6937,7 @@ class Peer {
|
|
|
6940
6937
|
close() {
|
|
6941
6938
|
debug(`closing ${this.peerId}`)
|
|
6942
6939
|
this.#connected = false
|
|
6943
|
-
this
|
|
6940
|
+
this.#channel?.close()
|
|
6944
6941
|
this.#connection?.close()
|
|
6945
6942
|
|
|
6946
6943
|
this.socketClient.pubsub.unsubscribe('signal', this._in)
|