浏览代码

Register relayed data task in client instance

Danilo Bargen 7 年之前
父节点
当前提交
1d8edc3a93
共有 3 个文件被更改,包括 18 次插入7 次删除
  1. 3 3
      package-lock.json
  2. 1 1
      package.json
  3. 14 3
      src/services/webclient.ts

+ 3 - 3
package-lock.json

@@ -15,9 +15,9 @@
       "integrity": "sha512-7FDHXIqjOfJbo4o7d43yHQpb10x2y4Btpr0aVkUaB/NerK2+bU2cbXZKR/98ET4Sz6a8mKHl9eJOnEd4Rk51TA=="
     },
     "@saltyrtc/task-relayed-data": {
-      "version": "0.1.2",
-      "resolved": "https://registry.npmjs.org/@saltyrtc/task-relayed-data/-/task-relayed-data-0.1.2.tgz",
-      "integrity": "sha512-+a/tiIA3bDNkCgnJYQz/Om6T+oeMpEabOL808/1/GF776D1XWkN0lVPv1boHTjb/nT+9haJEzdU0qAnZzduIiQ=="
+      "version": "0.1.3",
+      "resolved": "https://registry.npmjs.org/@saltyrtc/task-relayed-data/-/task-relayed-data-0.1.3.tgz",
+      "integrity": "sha512-8TpwKlua1whP+LDZGvxMK44blT5J9YqdgpbJFZDVIpPXc4+BHijHIzKU6HwdSHSqfefftFi/eSNIrJiQctcVWg=="
     },
     "@saltyrtc/task-webrtc": {
       "version": "0.10.0",

+ 1 - 1
package.json

@@ -28,7 +28,7 @@
   "dependencies": {
     "@saltyrtc/client": "^0.10.1",
     "@saltyrtc/task-webrtc": "^0.10.0",
-    "@saltyrtc/task-relayed-data": "^0.1.2",
+    "@saltyrtc/task-relayed-data": "^0.1.3",
     "@types/angular": "^1.6.43",
     "@types/angular-material": "^1.1.58",
     "@types/angular-sanitize": "^1.3.7",

+ 14 - 3
src/services/webclient.ts

@@ -352,13 +352,18 @@ export class WebClientService {
             .connectTo(this.saltyRtcHost, this.config.SALTYRTC_PORT)
             .withServerKey(this.config.SALTYRTC_SERVER_KEY)
             .withKeyStore(keyStore)
-            .usingTasks([this.webrtcTask])
+            .usingTasks([this.webrtcTask, this.relayedDataTask])
             .withPingInterval(30);
         if (keyStore !== undefined && peerTrustedKey !== undefined) {
             builder = builder.withTrustedPeerKey(peerTrustedKey);
         }
         this.salty = builder.asInitiator();
 
+        if (this.config.DEBUG) {
+            this.$log.debug('Public key:', this.salty.permanentKeyHex);
+            this.$log.debug('Auth token:', this.salty.authTokenHex);
+        }
+
         // We want to know about new responders.
         this.salty.on('new-responder', () => {
             if (!this.startupDone) {
@@ -404,9 +409,14 @@ export class WebClientService {
             }, 0);
         });
 
-        // Once the connection is established, initiate the peer connection
-        // and start the handover.
+        // Once the connection is established, if this is a WebRTC connection,
+        // initiate the peer connection and start the handover.
         this.salty.once('state-change:task', () => {
+            if (this.salty.getTask().getName().indexOf('webrtc.tasks.saltyrtc.org') === -1) {
+                // This is not a WebRTC task, so no handover!
+                return;
+            }
+
             // Firefox <53 does not yet support TLS. Skip it, to save allocations.
             const browser = this.browserService.getBrowser();
             if (browser.firefox && parseFloat(browser.version) < 53) {
@@ -428,6 +438,7 @@ export class WebClientService {
         });
 
         // Handle a disconnect request
+        // TODO: Handle this from the relayed data task too!
         this.salty.on('application', (applicationData: any) => {
             if (applicationData.data.type === 'disconnect') {
                 this.$log.debug(this.logTag, 'Disconnecting requested');