[tor-commits] [snowflake-webext/main] Stop aliasing global RTC constructors
arlo at torproject.org
arlo at torproject.org
Thu Aug 12 16:02:05 UTC 2021
commit f04d5115722d835d83aa588c61d0c8d4c731412b
Author: Arlo Breault <arlolra at gmail.com>
Date: Fri Aug 6 13:55:27 2021 -0400
Stop aliasing global RTC constructors
`window` isn't defined in service workers
---
proxypair.js | 4 ++--
shims.js | 11 ++---------
snowflake.js | 4 ++--
spec/snowflake.spec.js | 6 +++---
static/index.js | 2 +-
util.js | 6 +++---
6 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/proxypair.js b/proxypair.js
index 7da22b4..0ad4a33 100644
--- a/proxypair.js
+++ b/proxypair.js
@@ -1,4 +1,4 @@
-/* global snowflake, log, dbg, Util, PeerConnection, Parse, WS */
+/* global snowflake, log, dbg, Util, Parse, WS */
/*
Represents a single:
@@ -35,7 +35,7 @@ class ProxyPair {
// Prepare a WebRTC PeerConnection and await for an SDP offer.
begin() {
- this.pc = new PeerConnection(this.pcConfig, {
+ this.pc = new RTCPeerConnection(this.pcConfig, {
optional: [
{
DtlsSrtpKeyAgreement: true
diff --git a/shims.js b/shims.js
index 5d93183..5009084 100644
--- a/shims.js
+++ b/shims.js
@@ -16,16 +16,9 @@ if (typeof module !== "undefined" && module !== null ? module.exports : void 0)
({ URLSearchParams } = require('url'));
if ((typeof TESTING === "undefined" || TESTING === null) || !TESTING) {
webrtc = require('wrtc');
- PeerConnection = webrtc.RTCPeerConnection;
- IceCandidate = webrtc.RTCIceCandidate;
- SessionDescription = webrtc.RTCSessionDescription;
+ RTCPeerConnection = webrtc.RTCPeerConnection;
+ RTCSessionDescription = webrtc.RTCSessionDescription;
WebSocket = require('ws');
({ XMLHttpRequest } = require('xmlhttprequest'));
}
-} else {
- PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
- IceCandidate = window.RTCIceCandidate || window.mozRTCIceCandidate;
- SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription;
- WebSocket = window.WebSocket;
- XMLHttpRequest = window.XMLHttpRequest;
}
diff --git a/snowflake.js b/snowflake.js
index 49c1253..4e9396e 100644
--- a/snowflake.js
+++ b/snowflake.js
@@ -1,4 +1,4 @@
-/* global log, dbg, DummyRateLimit, BucketRateLimit, SessionDescription, ProxyPair */
+/* global log, dbg, DummyRateLimit, BucketRateLimit, ProxyPair */
/*
A JavaScript WebRTC snowflake proxy
@@ -120,7 +120,7 @@ class Snowflake {
try {
offer = JSON.parse(desc);
dbg('Received:\n\n' + offer.sdp + '\n');
- sdp = new SessionDescription(offer);
+ sdp = new RTCSessionDescription(offer);
if (pair.receiveWebRTCOffer(sdp)) {
this.sendAnswer(pair);
return true;
diff --git a/spec/snowflake.spec.js b/spec/snowflake.spec.js
index d9b97e8..812430d 100644
--- a/spec/snowflake.spec.js
+++ b/spec/snowflake.spec.js
@@ -5,15 +5,15 @@ jasmine tests for Snowflake
*/
// Fake browser functionality:
-class PeerConnection {
+class RTCPeerConnection {
setRemoteDescription() {
return true;
}
send() {}
}
-class SessionDescription {}
-SessionDescription.prototype.type = 'offer';
+class RTCSessionDescription {}
+RTCSessionDescription.prototype.type = 'offer';
class WebSocket {
constructor() {
diff --git a/static/index.js b/static/index.js
index b296ae4..d9efc5d 100644
--- a/static/index.js
+++ b/static/index.js
@@ -22,7 +22,7 @@ var getLang = function() {
lang = lang.replace(/-/g, '_');
//prioritize override language
- var url_string = window.location.href; //window.location.href
+ var url_string = window.location.href;
var url = new URL(url_string);
var override_lang = url.searchParams.get("lang");
if (override_lang != null) {
diff --git a/util.js b/util.js
index 35be73c..adaef30 100644
--- a/util.js
+++ b/util.js
@@ -1,5 +1,5 @@
/* exported Util, Params, DummyRateLimit */
-/* global PeerConnection, Config */
+/* global Config */
/*
A JavaScript WebRTC snowflake proxy
@@ -14,7 +14,7 @@ class Util {
}
static hasWebRTC() {
- return typeof PeerConnection === 'function';
+ return typeof RTCPeerConnection === 'function';
}
static hasCookies() {
@@ -28,7 +28,7 @@ class Util {
static checkNATType(timeout) {
return new Promise((fulfill, reject) => {
let open = false;
- let pc = new PeerConnection({iceServers: [
+ let pc = new RTCPeerConnection({iceServers: [
{urls: 'stun:stun1.l.google.com:19302'}
]});
let channel = pc.createDataChannel("NAT test");
More information about the tor-commits
mailing list