Explorar el Código

Merge pull request #6 from zhouqunan/master

get ws addr
Wallace Gao hace 5 años
padre
commit
837c27027f
Se han modificado 3 ficheros con 19 adiciones y 0 borrados
  1. 11 0
      app/controller/v1/example.js
  2. 2 0
      app/router/example.js
  3. 6 0
      app/service/socket.js

+ 11 - 0
app/controller/v1/example.js

@@ -64,6 +64,17 @@ class ExampleController extends BaseController {
 
     self.sendData(uploadRes);
   }
+
+  async getWsUrl() {
+    const self = this;
+    const { service } = this;
+    const data = {};
+
+    const addr = await service.socket.getWsUrl();
+    data.url = addr;
+
+    self.sendSuccess(data);
+  }
 }
 
 module.exports = ExampleController;

+ 2 - 0
app/router/example.js

@@ -9,4 +9,6 @@ module.exports = app => {
   router.post('/api/v1/example/openLocalDir', controller.v1.example.openLocalDir);
   // upload file
   router.post('/api/v1/example/uploadFile', controller.v1.example.uploadFile);
+  // get ws url
+  router.post('/api/v1/example/getWsUrl', controller.v1.example.getWsUrl);
 };

+ 6 - 0
app/service/socket.js

@@ -25,6 +25,12 @@ class SocketService extends BaseService {
     });
   }
 
+  async getWsUrl () {
+    const port = this.service.storage.getElectronIPCPort();
+    const url  = 'http://localhost:' + port;
+
+    return url;
+  }
 }
 
 module.exports = SocketService;