浏览代码

Add ICE debugging configuration option

This allows the user to disable ICE candidate censoring.
Danilo Bargen 8 年之前
父节点
当前提交
075c24f90b
共有 4 个文件被更改,包括 23 次插入12 次删除
  1. 2 1
      src/config.ts
  2. 18 10
      src/services/peerconnection.ts
  3. 2 1
      src/services/webclient.ts
  4. 1 0
      src/threema.d.ts

+ 2 - 1
src/config.ts

@@ -29,7 +29,8 @@ export default {
     // Push
     PUSH_URL: 'https://push-web.threema.ch/push',
 
-    // Message debugging
+    // Debugging options
     MSG_DEBUGGING: false,
+    ICE_DEBUGGING: false,
 
 } as threema.Config;

+ 18 - 10
src/services/peerconnection.ts

@@ -44,10 +44,14 @@ export class PeerConnectionHelper {
     // Internal callback when connection closes
     private onConnectionClosed: () => void = null;
 
+    // Debugging
+    private censorCandidates: boolean;
+
     constructor($log: ng.ILogService, $q: ng.IQService,
                 $timeout: ng.ITimeoutService, $rootScope: ng.IRootScopeService,
                 webrtcTask: saltyrtc.tasks.webrtc.WebRTCTask,
-                iceServers: RTCIceServer[]) {
+                iceServers: RTCIceServer[],
+                censorCandidates: boolean = true) {
         this.$log = $log;
         this.$log.info(this.logTag, 'Initialize WebRTC PeerConnection');
         this.$log.debug(this.logTag, 'ICE servers used:', [].concat(...iceServers.map((c) => c.urls)).join(', '));
@@ -57,6 +61,8 @@ export class PeerConnectionHelper {
 
         this.webrtcTask = webrtcTask;
 
+        this.censorCandidates = censorCandidates;
+
         // Set up peer connection
         this.pc = new RTCPeerConnection({iceServers: iceServers});
         this.pc.onnegotiationneeded = (e: Event) => {
@@ -98,7 +104,7 @@ export class PeerConnectionHelper {
         this.pc.onicecandidate = (e: RTCPeerConnectionIceEvent) => {
             if (e.candidate) {
                 this.$log.debug(this.logTag, 'Gathered local ICE candidate:',
-                    PeerConnectionHelper.censorCandidate(e.candidate.candidate));
+                    this.censorCandidate(e.candidate.candidate));
                 this.webrtcTask.sendCandidate({
                     candidate: e.candidate.candidate,
                     sdpMid: e.candidate.sdpMid,
@@ -143,7 +149,7 @@ export class PeerConnectionHelper {
             for (let candidateInit of e.data) {
                 if (candidateInit) {
                     this.$log.debug(this.logTag, 'Adding remote ICE candidate:',
-                        PeerConnectionHelper.censorCandidate(candidateInit.candidate));
+                        this.censorCandidate(candidateInit.candidate));
                 } else {
                     this.$log.debug(this.logTag, 'No more remote ICE candidates');
                 }
@@ -247,18 +253,20 @@ export class PeerConnectionHelper {
     }
 
     /**
-     * Censor an ICE candidate's address and port.
+     * Censor an ICE candidate's address and port (unless censoring is disabled).
      *
      * Return the censored ICE candidate.
      */
-    private static censorCandidate(candidateInit: string): string {
+    private censorCandidate(candidateInit: string): string {
         let candidate = SDPUtils.parseCandidate(candidateInit);
-        if (candidate.type !== 'relay') {
-            candidate.ip = '***';
-            candidate.port = 1;
+        if (this.censorCandidates) {
+            if (candidate.type !== 'relay') {
+                candidate.ip = '***';
+                candidate.port = 1;
+            }
+            candidate.relatedAddress = '***';
+            candidate.relatedPort = 2;
         }
-        candidate.relatedAddress = '***';
-        candidate.relatedPort = 2;
         return SDPUtils.writeCandidate(candidate);
     }
 }

+ 2 - 1
src/services/webclient.ts

@@ -404,7 +404,8 @@ export class WebClientService {
 
             this.pcHelper = new PeerConnectionHelper(this.$log, this.$q, this.$timeout,
                                                      this.$rootScope, this.webrtcTask,
-                                                     this.config.ICE_SERVERS);
+                                                     this.config.ICE_SERVERS,
+                                                     !this.config.ICE_DEBUGGING);
 
             // On state changes in the PeerConnectionHelper class, let state service know about it
             this.pcHelper.onConnectionStateChange = (state: threema.RTCConnectionState) => {

+ 1 - 0
src/threema.d.ts

@@ -392,6 +392,7 @@ declare namespace threema {
         ICE_SERVERS: RTCIceServer[];
         PUSH_URL: string;
         MSG_DEBUGGING: boolean;
+        ICE_DEBUGGING: boolean;
     }
 
     interface InitialConversationData {