@ircam/comote-helpers 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ircam/comote-helpers",
3
- "version": "0.0.0",
3
+ "version": "0.2.0",
4
4
  "description": "Server component & utilities for the CoMo.te application",
5
5
  "authors": [
6
6
  "Benjamin.Matuszewski@ircam.fr",
package/qrcode.js CHANGED
@@ -15,7 +15,7 @@ function formatConfigToLink(config) {
15
15
  let link = `comote://settings?`;
16
16
  const query = [];
17
17
 
18
- if (Number.isFinite(config.id) && config.id >= 0) {
18
+ if ('id' in config) {
19
19
  query.push(`id=${config.id}`);
20
20
  }
21
21
 
@@ -25,15 +25,30 @@ function formatConfigToLink(config) {
25
25
 
26
26
  if (config.ws) {
27
27
  const {
28
+ protocol,
28
29
  hostname,
29
- port
30
- } = config.ws;
30
+ port,
31
+ pathname
32
+ } = config.ws; // build valid url
33
+ // only hostname is required
31
34
 
32
- if (!hostname || !Number.isInteger(port)) {
35
+ if (!hostname) {
33
36
  throw new Error(`Invalid WebSocket config: ${config.ws}`);
34
37
  }
35
38
 
36
- query.push(`ws-url=ws://${hostname}:${port}`);
39
+ let url = `ws-url=`;
40
+ url += protocol == 'ws' || protocol == 'wss' ? `${protocol}://` : `ws://`;
41
+ url += hostname;
42
+
43
+ if (port) {
44
+ url += `:${port}`;
45
+ }
46
+
47
+ if (pathname) {
48
+ url += pathname;
49
+ }
50
+
51
+ query.push(url); // autostart
37
52
 
38
53
  if (config.ws.autostart === true) {
39
54
  query.push(`ws-enable=1`);
package/server.js CHANGED
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Server = void 0;
7
- exports.getWifiInfos = getWifiInfos;
8
-
9
- var _systeminformation = _interopRequireDefault(require("systeminformation"));
10
7
 
11
8
  var _ws = _interopRequireDefault(require("ws"));
12
9
 
@@ -20,12 +17,6 @@ var _assignDeep = _interopRequireDefault(require("assign-deep"));
20
17
 
21
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
19
 
23
- /**
24
- * @typedef {Object} WifiInfos
25
- * @property {number} ssid - SSID of the WiFi connection
26
- * @property {number} ip - Related IP (IPV4)
27
- */
28
-
29
20
  /**
30
21
  * @typedef {Object} CoMoteConfig
31
22
  * @property {String} id - id of the client CoMo.te
@@ -41,30 +32,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
41
32
  * @property {Boolean} autostart - enable streaming on CoMo.te application
42
33
  */
43
34
 
44
- /**
45
- * Retrieve the SSID and related IP of the first WiFi connection found, return
46
- * `null` if no WiFi connection found.
47
- *
48
- * @async
49
- * @return {WiFiInfos|null}
50
- */
51
- async function getWifiInfos() {
52
- // find first wifi connection
53
- const wifiConnections = await _systeminformation.default.wifiConnections();
54
- const conn = wifiConnections[0];
55
-
56
- if (!conn) {
57
- return null;
58
- } // find related interface
59
-
60
-
61
- const interfaces = await _systeminformation.default.networkInterfaces();
62
- const int = interfaces.find(int => int.iface === conn.iface);
63
- return {
64
- ssid: conn.ssid,
65
- ip: int.ip4
66
- };
67
- }
68
35
  /**
69
36
  * Launch WebSocket and/or OSC server according to given `CoMoteConfig` object
70
37
  *
@@ -72,8 +39,6 @@ async function getWifiInfos() {
72
39
  * @param {Object} options - options
73
40
  * @param {Object} [options.verbose=false] - logs debug informations
74
41
  */
75
-
76
-
77
42
  class Server {
78
43
  constructor(config, options) {
79
44
  /**
package/wifi-infos.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getWifiInfos = getWifiInfos;
7
+
8
+ var _systeminformation = _interopRequireDefault(require("systeminformation"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ /**
13
+ * @typedef {Object} WifiInfos
14
+ * @property {number} ssid - SSID of the WiFi connection
15
+ * @property {number} ip - Related IP (IPV4)
16
+ */
17
+
18
+ /**
19
+ * Retrieve the SSID and related IP of the first WiFi connection found, return
20
+ * `null` if no WiFi connection found.
21
+ *
22
+ * @async
23
+ * @return {WiFiInfos|null}
24
+ */
25
+ async function getWifiInfos() {
26
+ // find first wifi connection
27
+ const wifiConnections = await _systeminformation.default.wifiConnections();
28
+ const conn = wifiConnections[0];
29
+
30
+ if (!conn) {
31
+ return null;
32
+ } // find related interface
33
+
34
+
35
+ const interfaces = await _systeminformation.default.networkInterfaces();
36
+ const int = interfaces.find(int => int.iface === conn.iface);
37
+ return {
38
+ ssid: conn.ssid,
39
+ ip: int.ip4
40
+ };
41
+ }