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

Remove acknowledgements for data channel messages. #342

Merged
merged 1 commit into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sdk/base/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export function sysInfo() {
continualIceGathering: false,
unifiedPlan: true,
streamRemovable: info.runtime.name !== 'Firefox',
ignoreDataChannelAcks: true,
};
return info;
}
37 changes: 24 additions & 13 deletions src/sdk/p2p/peerconnection-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class P2PPeerConnectionChannel extends EventDispatcher {
this._remoteSideSupportsRemoveStream = true;
this._remoteSideSupportsPlanB = true;
this._remoteSideSupportsUnifiedPlan = true;
this._remoteSideIgnoresDataChannelAcks = false;
this._remoteIceCandidates = [];
this._dataChannels = new Map(); // Key is data channel's label, value is a RTCDataChannel.
this._pendingMessages = [];
Expand Down Expand Up @@ -151,24 +152,25 @@ class P2PPeerConnectionChannel extends EventDispatcher {
id: this._dataSeq++,
data: message,
};
const promise = new Promise((resolve, reject) => {
this._sendDataPromises.set(data.id, {
resolve: resolve,
reject: reject,
});
});
if (!this._dataChannels.has(DataChannelLabel.MESSAGE)) {
this._createDataChannel(DataChannelLabel.MESSAGE);
}

const dc = this._dataChannels.get(DataChannelLabel.MESSAGE);
if (dc.readyState === 'open') {
this._dataChannels.get(DataChannelLabel.MESSAGE).send(
JSON.stringify(data));
this._dataChannels.get(DataChannelLabel.MESSAGE)
.send(JSON.stringify(data));
return Promise.resolve();
} else {
this._pendingMessages.push(data);
const promise = new Promise((resolve, reject) => {
this._sendDataPromises.set(data.id, {
resolve: resolve,
reject: reject,
});
});
return promise;
}
return promise;
}

/**
Expand Down Expand Up @@ -601,8 +603,9 @@ class P2PPeerConnectionChannel extends EventDispatcher {

_onDataChannelMessage(event) {
const message=JSON.parse(event.data);
Logger.debug('Data channel message received: '+message.data);
this._sendSignalingMessage(SignalingType.DATA_RECEIVED, message.id);
if (!this._remoteSideIgnoresDataChannelAcks) {
this._sendSignalingMessage(SignalingType.DATA_RECEIVED, message.id);
}
const messageEvent = new MessageEvent('messagereceived', {
message: message.data,
origin: this._remoteId,
Expand Down Expand Up @@ -763,9 +766,13 @@ class P2PPeerConnectionChannel extends EventDispatcher {
const dc = this._dataChannels.get(DataChannelLabel.MESSAGE);
if (dc && dc.readyState === 'open') {
for (let i = 0; i < this._pendingMessages.length; i++) {
Logger.debug('Sending message via data channel: ' +
this._pendingMessages[i]);
Logger.debug(
'Sending message via data channel: ' + this._pendingMessages[i]);
dc.send(JSON.stringify(this._pendingMessages[i]));
const messageId = this._pendingMessages[i].id;
if (this._sendDataPromises.has(messageId)) {
this._sendDataPromises.get(messageId).resolve();
}
}
this._pendingMessages.length = 0;
} else if (this._pc && !dc) {
Expand Down Expand Up @@ -809,6 +816,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
this._remoteSideSupportsPlanB = true;
this._remoteSideSupportsUnifiedPlan = false;
}
if (ua.capabilities) {
this._remoteSideIgnoresDataChannelAcks =
ua.capabilities.ignoreDataChannelAcks;
}
}

_doNegotiate() {
Expand Down