[tor-commits] [pluggable-transports/snowflake-webext] 03/15: refactor: remove global var usage
gitolite role
git at cupani.torproject.org
Wed Nov 9 14:40:52 UTC 2022
This is an automated email from the git hooks/post-receive script.
cohosh pushed a commit to branch main
in repository pluggable-transports/snowflake-webext.
commit 132213e24855fc65b1255828e39fde5fb5f44b54
Author: WofWca <wofwca at protonmail.com>
AuthorDate: Fri Nov 4 14:47:25 2022 +0400
refactor: remove global var usage
---
proxypair.js | 5 +++--
snowflake.js | 7 ++++++-
spec/proxypair.spec.js | 11 +++++++----
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/proxypair.js b/proxypair.js
index 4b7c115..493d9e3 100644
--- a/proxypair.js
+++ b/proxypair.js
@@ -50,9 +50,10 @@ class ProxyPair {
/**
* @param {RTCSessionDescription} offer
+ * @param {(answer: RTCSessionDescription) => void} sendAnswer
* @returns {boolean} `true` on success, `false` on fail.
*/
- receiveWebRTCOffer(offer) {
+ receiveWebRTCOffer(offer, sendAnswer) {
if ('offer' !== offer.type) {
log('Invalid SDP received -- was not an offer.');
return false;
@@ -67,7 +68,7 @@ class ProxyPair {
// Send the answer when ready.
const onceSendAnswer = () => {
- snowflake.broker.sendAnswer(this.id, this.pc.localDescription);
+ sendAnswer(this.pc.localDescription);
this.pc.onicegatheringstatechange = null;
clearTimeout(this.answerTimeoutId);
diff --git a/snowflake.js b/snowflake.js
index abb4c11..7342856 100644
--- a/snowflake.js
+++ b/snowflake.js
@@ -154,7 +154,12 @@ class Snowflake {
const offer = JSON.parse(desc);
dbg('Received:\n\n' + offer.sdp + '\n');
const sdp = new RTCSessionDescription(offer);
- if (pair.receiveWebRTCOffer(sdp)) {
+ if (
+ pair.receiveWebRTCOffer(
+ sdp,
+ answer => this.broker.sendAnswer(pair.id, answer)
+ )
+ ) {
this.sendAnswer(pair);
return true;
} else {
diff --git a/spec/proxypair.spec.js b/spec/proxypair.spec.js
index 6cf71f2..3b8bc0a 100644
--- a/spec/proxypair.spec.js
+++ b/spec/proxypair.spec.js
@@ -80,10 +80,13 @@ describe('ProxyPair', function() {
it('responds with a WebRTC answer correctly', function() {
spyOn(snowflake.broker, 'sendAnswer');
- pp.receiveWebRTCOffer({
- type: 'offer',
- sdp: 'foo'
- });
+ pp.receiveWebRTCOffer(
+ {
+ type: 'offer',
+ sdp: 'foo'
+ },
+ answer => snowflake.broker.sendAnswer(pp.id, answer),
+ );
pp.pc.iceGatheringState = 'complete';
pp.pc.onicegatheringstatechange();
expect(snowflake.broker.sendAnswer).toHaveBeenCalled();
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the tor-commits
mailing list