Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 9bd49be

Browse files
authored
Remove acknowledgements for data channel messages. (#342)
1 parent 34256ae commit 9bd49be

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/sdk/base/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export function sysInfo() {
122122
continualIceGathering: false,
123123
unifiedPlan: true,
124124
streamRemovable: info.runtime.name !== 'Firefox',
125+
ignoreDataChannelAcks: true,
125126
};
126127
return info;
127128
}

src/sdk/p2p/peerconnection-channel.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class P2PPeerConnectionChannel extends EventDispatcher {
8383
this._remoteSideSupportsRemoveStream = true;
8484
this._remoteSideSupportsPlanB = true;
8585
this._remoteSideSupportsUnifiedPlan = true;
86+
this._remoteSideIgnoresDataChannelAcks = false;
8687
this._remoteIceCandidates = [];
8788
this._dataChannels = new Map(); // Key is data channel's label, value is a RTCDataChannel.
8889
this._pendingMessages = [];
@@ -151,24 +152,25 @@ class P2PPeerConnectionChannel extends EventDispatcher {
151152
id: this._dataSeq++,
152153
data: message,
153154
};
154-
const promise = new Promise((resolve, reject) => {
155-
this._sendDataPromises.set(data.id, {
156-
resolve: resolve,
157-
reject: reject,
158-
});
159-
});
160155
if (!this._dataChannels.has(DataChannelLabel.MESSAGE)) {
161156
this._createDataChannel(DataChannelLabel.MESSAGE);
162157
}
163158

164159
const dc = this._dataChannels.get(DataChannelLabel.MESSAGE);
165160
if (dc.readyState === 'open') {
166-
this._dataChannels.get(DataChannelLabel.MESSAGE).send(
167-
JSON.stringify(data));
161+
this._dataChannels.get(DataChannelLabel.MESSAGE)
162+
.send(JSON.stringify(data));
163+
return Promise.resolve();
168164
} else {
169165
this._pendingMessages.push(data);
166+
const promise = new Promise((resolve, reject) => {
167+
this._sendDataPromises.set(data.id, {
168+
resolve: resolve,
169+
reject: reject,
170+
});
171+
});
172+
return promise;
170173
}
171-
return promise;
172174
}
173175

174176
/**
@@ -601,8 +603,9 @@ class P2PPeerConnectionChannel extends EventDispatcher {
601603

602604
_onDataChannelMessage(event) {
603605
const message=JSON.parse(event.data);
604-
Logger.debug('Data channel message received: '+message.data);
605-
this._sendSignalingMessage(SignalingType.DATA_RECEIVED, message.id);
606+
if (!this._remoteSideIgnoresDataChannelAcks) {
607+
this._sendSignalingMessage(SignalingType.DATA_RECEIVED, message.id);
608+
}
606609
const messageEvent = new MessageEvent('messagereceived', {
607610
message: message.data,
608611
origin: this._remoteId,
@@ -763,9 +766,13 @@ class P2PPeerConnectionChannel extends EventDispatcher {
763766
const dc = this._dataChannels.get(DataChannelLabel.MESSAGE);
764767
if (dc && dc.readyState === 'open') {
765768
for (let i = 0; i < this._pendingMessages.length; i++) {
766-
Logger.debug('Sending message via data channel: ' +
767-
this._pendingMessages[i]);
769+
Logger.debug(
770+
'Sending message via data channel: ' + this._pendingMessages[i]);
768771
dc.send(JSON.stringify(this._pendingMessages[i]));
772+
const messageId = this._pendingMessages[i].id;
773+
if (this._sendDataPromises.has(messageId)) {
774+
this._sendDataPromises.get(messageId).resolve();
775+
}
769776
}
770777
this._pendingMessages.length = 0;
771778
} else if (this._pc && !dc) {
@@ -809,6 +816,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
809816
this._remoteSideSupportsPlanB = true;
810817
this._remoteSideSupportsUnifiedPlan = false;
811818
}
819+
if (ua.capabilities) {
820+
this._remoteSideIgnoresDataChannelAcks =
821+
ua.capabilities.ignoreDataChannelAcks;
822+
}
812823
}
813824

814825
_doNegotiate() {

0 commit comments

Comments
 (0)