arnacon-webrtc-service 0.1.0 → 0.1.2

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": "arnacon-webrtc-service",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Arnacon WebRTC core runtime and service modules",
5
5
  "main": "./webRTCservice/core.js",
6
6
  "type": "commonjs",
@@ -5,16 +5,12 @@ const path = require("path");
5
5
  function startServiceProcess({
6
6
  serviceId,
7
7
  deployEnv = process.env.DEPLOY_ENV || "development",
8
- internalApiToken = process.env.INTERNAL_API_TOKEN || "",
9
8
  } = {}) {
10
9
  if (!serviceId) {
11
10
  throw new Error("startServiceProcess requires serviceId");
12
11
  }
13
12
  process.env.DEPLOY_ENV = deployEnv;
14
13
  process.env.SERVICE_ID = serviceId;
15
- if (internalApiToken) {
16
- process.env.INTERNAL_API_TOKEN = internalApiToken;
17
- }
18
14
  return require("./webRTCmanager");
19
15
  }
20
16
 
@@ -63,7 +63,6 @@ function createInternalServer({
63
63
  handlers,
64
64
  sendJsonError,
65
65
  logger = console,
66
- verifyInternalRequest = null,
67
66
  }) {
68
67
  const internalServer = http.createServer(async (req, res) => {
69
68
  logger.log(`[Internal] Incoming request: ${req.method} ${req.url} from ${req.socket.remoteAddress}`);
@@ -71,14 +70,6 @@ function createInternalServer({
71
70
  sendJsonError(res, 404, "Not found");
72
71
  return;
73
72
  }
74
- if (verifyInternalRequest) {
75
- try {
76
- await verifyInternalRequest(req);
77
- } catch (err) {
78
- sendJsonError(res, 401, err.message || "Unauthorized");
79
- return;
80
- }
81
- }
82
73
  if (req.url !== "/inbound-call") {
83
74
  sendJsonError(res, 404, "Not found");
84
75
  return;
@@ -105,7 +96,6 @@ function createHttpServers({
105
96
  sendJsonError,
106
97
  logger = console,
107
98
  verifyExternalRequest = null,
108
- verifyInternalRequest = null,
109
99
  }) {
110
100
  const publicServer = createPublicServer({
111
101
  tlsOptions,
@@ -121,7 +111,6 @@ function createHttpServers({
121
111
  handlers,
122
112
  sendJsonError,
123
113
  logger,
124
- verifyInternalRequest,
125
114
  });
126
115
 
127
116
  function startPublicServer() {
@@ -151,7 +151,21 @@ const { WebSocket: WsWebSocket } = require("ws");
151
151
  // ════════════════════════════════════════════════════════════
152
152
 
153
153
  // ─── Load config from config.json + services/*.json ──────────
154
- const fullConfig = require(path.join(__dirname, "..", "config.json"));
154
+ const PACKAGE_ROOT = path.resolve(__dirname, "..");
155
+ const CONFIG_OVERRIDE = process.env.WEBRTC_CONFIG_PATH || process.env.ARNACON_WEBRTC_CONFIG_PATH || "";
156
+ const CONFIG_PATH = CONFIG_OVERRIDE
157
+ ? (path.isAbsolute(CONFIG_OVERRIDE) ? CONFIG_OVERRIDE : path.resolve(process.cwd(), CONFIG_OVERRIDE))
158
+ : path.join(PACKAGE_ROOT, "config.json");
159
+ const CONFIG_BASE_DIR = path.dirname(CONFIG_PATH);
160
+ const fullConfig = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
161
+
162
+ function resolveRuntimePath(entryPath) {
163
+ if (!entryPath) return "";
164
+ if (path.isAbsolute(entryPath)) return entryPath;
165
+ const fromConfigDir = path.resolve(CONFIG_BASE_DIR, entryPath);
166
+ if (fs.existsSync(fromConfigDir)) return fromConfigDir;
167
+ return path.resolve(PACKAGE_ROOT, entryPath);
168
+ }
155
169
  const deployEnv = process.env.DEPLOY_ENV || "development";
156
170
  const envConfig = fullConfig[deployEnv] || {};
157
171
  const commonConfig = envConfig.common || {};
@@ -159,8 +173,8 @@ const serviceRegistry = envConfig.services || {};
159
173
  const loadedServices = {};
160
174
 
161
175
  for (const [serviceId, serviceEntry] of Object.entries(serviceRegistry)) {
162
- const serviceConfigPath = path.resolve(__dirname, "..", serviceEntry.configPath);
163
- const serviceModulePath = path.resolve(__dirname, "..", serviceEntry.modulePath);
176
+ const serviceConfigPath = resolveRuntimePath(serviceEntry.configPath);
177
+ const serviceModulePath = resolveRuntimePath(serviceEntry.modulePath);
164
178
  const serviceConfigRoot = JSON.parse(fs.readFileSync(serviceConfigPath, "utf8"));
165
179
  const serviceConfig = serviceConfigRoot[deployEnv];
166
180
  if (!serviceConfig) {
@@ -222,7 +236,6 @@ const KAMAILIO_DOMAIN = config.domain;
222
236
  const KAMAILIO_REGISTER_EXPIRES = 300;
223
237
 
224
238
  const INTERNAL_BIND_IP = config.bindIp || "127.0.0.1";
225
- const INTERNAL_AUTH_TOKEN = process.env.INTERNAL_API_TOKEN || "";
226
239
 
227
240
  // ROFL API config
228
241
  const ROFL_BASE_URL = config.roflBaseUrl;
@@ -655,13 +668,6 @@ const tlsOptions = {
655
668
  cert: fs.readFileSync(`${config.tlsCertPath}/fullchain.pem`),
656
669
  key: fs.readFileSync(`${config.tlsCertPath}/privkey.pem`),
657
670
  };
658
- async function verifyInternalRequest(req) {
659
- if (!INTERNAL_AUTH_TOKEN) return;
660
- const token = req.headers["x-internal-token"];
661
- if (!token || token !== INTERNAL_AUTH_TOKEN) {
662
- throw new Error("Missing or invalid internal auth token");
663
- }
664
- }
665
671
  const httpServers = [];
666
672
  for (const serviceRuntime of activeServiceRuntimes) {
667
673
  const handlers = createHandlers({
@@ -681,7 +687,6 @@ for (const serviceRuntime of activeServiceRuntimes) {
681
687
  handlers,
682
688
  sendJsonError,
683
689
  logger: console,
684
- verifyInternalRequest,
685
690
  });
686
691
  serviceServers.startPublicServer();
687
692
  serviceServers.startInternalServer();
package/README.md DELETED
@@ -1,67 +0,0 @@
1
- # test2_kamailio
2
-
3
- This folder contains the Kamailio + WebRTC gateway runtime config and deploy helpers.
4
-
5
- ## Production Config Injector
6
-
7
- The production config injector is:
8
-
9
- - `deploy-config.sh`
10
-
11
- It reads values from `config.json` and writes them into:
12
-
13
- - `ron_kamailio.cfg` (`#!substdef` values at the top)
14
- - `tls.cfg` (`private_key` and `certificate` paths)
15
-
16
- It does **not** restart services by itself.
17
-
18
- ## How To Run (Production)
19
-
20
- From inside this folder:
21
-
22
- ```bash
23
- cd /path/to/test2Server/test2_kamailio
24
- DEPLOY_ENV=production ./deploy-config.sh
25
- ```
26
-
27
- If execute permissions are missing:
28
-
29
- ```bash
30
- chmod +x ./deploy-config.sh
31
- DEPLOY_ENV=production ./deploy-config.sh
32
- ```
33
-
34
- ## What It Injects
35
-
36
- From `config.json -> production`:
37
-
38
- - `domain` -> `MY_DOMAIN`
39
- - `publicIp` -> `MY_PUBLIC_IP`
40
- - `bindIp` -> `MY_BIND_IP`
41
- - `providers.secnum.outboundSbcAddress` -> `MY_SBC_IP`
42
- - first `providers.*.trustedIngressIps[0]` -> `MY_TRUSTED_PEER_1`
43
- - second `providers.*.trustedIngressIps[1]` -> `MY_TRUSTED_PEER_2`
44
- - `kamailioWssPort` -> `MY_WSS_PORT`
45
- - `tlsCertPath` -> `tls.cfg` certificate/private key paths
46
-
47
- ## Safe Deploy Sequence
48
-
49
- ```bash
50
- cd /path/to/test2Server/test2_kamailio
51
- DEPLOY_ENV=production ./deploy-config.sh
52
- kamailio -c -f /path/to/test2Server/test2_kamailio/ron_kamailio.cfg
53
- sudo systemctl restart kamailio
54
- sudo systemctl restart webrtcmanager
55
- ```
56
-
57
- Then verify:
58
-
59
- ```bash
60
- sudo systemctl status kamailio --no-pager
61
- curl -sS http://127.0.0.1:8188/health
62
- ```
63
-
64
- ## Notes
65
-
66
- - If `DEPLOY_ENV` is not set, script defaults to `development`.
67
- - Keep `config.json` as the single source of truth for env-specific values.
@@ -1,15 +0,0 @@
1
- {
2
- "name": "webrtcmanager",
3
- "version": "1.0.0",
4
- "description": "WebRTC-to-SIP bridge: translates Arnacon Android WebRTC protocol to SIP for Kamailio",
5
- "main": "webRTCmanager.js",
6
- "scripts": {
7
- "start": "node webRTCmanager.js"
8
- },
9
- "dependencies": {
10
- "ethers": "^5.7.2",
11
- "sip.js": "^0.21.2",
12
- "werift": "*",
13
- "ws": "^8.16.0"
14
- }
15
- }