@routr/connect 2.0.5-alpha.3
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/LICENSE +21 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +36 -0
- package/dist/service.d.ts +2 -0
- package/dist/service.js +33 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +2 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +79 -0
- package/package.json +40 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Fonoster Inc
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/dist/runner.d.ts
ADDED
package/dist/runner.js
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
"use strict";
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
5
|
+
};
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
+
/*
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
9
|
+
* http://github.com/fonoster/routr
|
10
|
+
*
|
11
|
+
* This file is part of Routr
|
12
|
+
*
|
13
|
+
* Licensed under the MIT License (the "License");
|
14
|
+
* you may not use this file except in compliance with
|
15
|
+
* the License. You may obtain a copy of the License at
|
16
|
+
*
|
17
|
+
* https://opensource.org/licenses/MIT
|
18
|
+
*
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
+
* See the License for the specific language governing permissions and
|
23
|
+
* limitations under the License.
|
24
|
+
*/
|
25
|
+
const logger_1 = __importDefault(require("@fonoster/logger"));
|
26
|
+
const service_1 = __importDefault(require("./service"));
|
27
|
+
if (process.env.LOCATION_ADDR) {
|
28
|
+
service_1.default({
|
29
|
+
bindAddr: process.env.BIND_ADDR || "0.0.0.0:51904",
|
30
|
+
locationAddr: process.env.LOCATION_ADDR
|
31
|
+
});
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
logger_1.default.error("environment variable LOCATION_ADDR is required but was not found");
|
35
|
+
process.exit(1);
|
36
|
+
}
|
package/dist/service.js
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const grpc = require("@grpc/grpc-js");
|
7
|
+
const common_1 = require("@routr/common");
|
8
|
+
const processor_1 = __importDefault(require("@routr/processor"));
|
9
|
+
const logger_1 = __importDefault(require("@fonoster/logger"));
|
10
|
+
const utils_1 = require("./utils");
|
11
|
+
function ConnectProcessor(config) {
|
12
|
+
const { bindAddr, locationAddr } = config;
|
13
|
+
const locator = new common_1.LOCATION_OBJECT_PROTO.Location(locationAddr, grpc.credentials.createInsecure());
|
14
|
+
new processor_1.default({ bindAddr, name: "connect" })
|
15
|
+
.listen((req, res) => {
|
16
|
+
logger_1.default.silly(JSON.stringify(req, null, ' '));
|
17
|
+
switch (req.method.toString()) {
|
18
|
+
case 'PUBLISH':
|
19
|
+
case 'NOTIFY':
|
20
|
+
case 'SUBSCRIBE':
|
21
|
+
res.sendMethodNotAllowed();
|
22
|
+
break;
|
23
|
+
case 'REGISTER':
|
24
|
+
utils_1.createRegisterHandler({ connection: locator, addr: locationAddr })(req, res);
|
25
|
+
break;
|
26
|
+
case 'CANCEL':
|
27
|
+
break;
|
28
|
+
default:
|
29
|
+
res.sendNotImplemented();
|
30
|
+
}
|
31
|
+
});
|
32
|
+
}
|
33
|
+
exports.default = ConnectProcessor;
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
package/dist/utils.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { MessageRequest } from "@routr/common";
|
2
|
+
import { Response } from "@routr/processor";
|
3
|
+
export declare const createRoute: (request: MessageRequest) => {
|
4
|
+
edgePortRef: string;
|
5
|
+
user: any;
|
6
|
+
host: any;
|
7
|
+
port: number;
|
8
|
+
transport: any;
|
9
|
+
registeredOn: number;
|
10
|
+
sessionCount: any;
|
11
|
+
expires: unknown;
|
12
|
+
};
|
13
|
+
export declare const createRegisterHandler: (locator: {
|
14
|
+
addr: string;
|
15
|
+
connection: any;
|
16
|
+
}) => (request: MessageRequest, res: Response) => void;
|
package/dist/utils.js
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.createRegisterHandler = exports.createRoute = void 0;
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
6
|
+
* http://github.com/fonoster/routr
|
7
|
+
*
|
8
|
+
* This file is part of Routr
|
9
|
+
*
|
10
|
+
* Licensed under the MIT License (the "License")
|
11
|
+
* you may not use this file except in compliance with
|
12
|
+
* the License. You may obtain a copy of the License at
|
13
|
+
*
|
14
|
+
* https://opensource.org/licenses/MIT
|
15
|
+
*
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
* See the License for the specific language governing permissions and
|
20
|
+
* limitations under the License.
|
21
|
+
*/
|
22
|
+
const common_1 = require("@routr/common");
|
23
|
+
const grpc = require("@grpc/grpc-js");
|
24
|
+
const getAOR = (uri) => `${uri.secure ? 'sips' : 'sip'}:${uri.user}@${uri.host}`;
|
25
|
+
const getTargetAOR = (request) => getAOR(request.message.to.address.uri);
|
26
|
+
const getTargetUser = (request) => request.message.to.address.uri.user;
|
27
|
+
const getTargetHost = (request) => request.message.to.address.uri.host;
|
28
|
+
const getTargetTransport = (request) => request.message.to.address.uri.transport_param;
|
29
|
+
const getTargetExpires = (request) => {
|
30
|
+
// The expires value in the Contact header takes presendence over the value
|
31
|
+
// on the Expires header
|
32
|
+
const expires = request.message.contact.expires;
|
33
|
+
if (expires > -1)
|
34
|
+
return expires;
|
35
|
+
return request.message.expires;
|
36
|
+
};
|
37
|
+
const getExtensionHeaderValue = (request, name) => request.message.extensions.find((ext) => ext.name.toLowerCase() === name.toLowerCase()).value;
|
38
|
+
const updateExtensionHeader = (request, header) => {
|
39
|
+
const r = Object.assign({}, request);
|
40
|
+
r.message.extensions = r.message.extensions.map((ext) => {
|
41
|
+
return ext.name == header.name ? header : ext;
|
42
|
+
});
|
43
|
+
return r;
|
44
|
+
};
|
45
|
+
// TODO: Before finalizing this, consider using the old approach of saving the rport
|
46
|
+
// and received values (like here:
|
47
|
+
// https://github.com/fonoster/routr/blob/59bc98af86078088aede7e658c0d82a19fa18fa4/mod/registrar/utils.js#L87)
|
48
|
+
const createRoute = (request) => {
|
49
|
+
return {
|
50
|
+
edgePortRef: request.edge_port_ref,
|
51
|
+
user: getTargetUser(request),
|
52
|
+
host: getTargetHost(request),
|
53
|
+
// TODO: Where to get the best port?
|
54
|
+
port: 5060,
|
55
|
+
transport: getTargetTransport(request),
|
56
|
+
registeredOn: Date.now(),
|
57
|
+
sessionCount: getExtensionHeaderValue(request.message, "x-session-count") || -1,
|
58
|
+
expires: getTargetExpires(request),
|
59
|
+
// labels
|
60
|
+
};
|
61
|
+
};
|
62
|
+
exports.createRoute = createRoute;
|
63
|
+
const createRegisterHandler = (locator) => {
|
64
|
+
return (request, res) => {
|
65
|
+
const { user, host } = request.message.to;
|
66
|
+
const addRouteRequest = {
|
67
|
+
aor: getTargetAOR(request),
|
68
|
+
route: exports.createRoute(request)
|
69
|
+
};
|
70
|
+
locator.connection.addRoute(addRouteRequest, (err, response) => {
|
71
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
|
72
|
+
res.sendError(new common_1.ServiceUnavailableError(locator.addr));
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
res.sendOk();
|
76
|
+
});
|
77
|
+
};
|
78
|
+
};
|
79
|
+
exports.createRegisterHandler = createRegisterHandler;
|
package/package.json
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
{
|
2
|
+
"name": "@routr/connect",
|
3
|
+
"version": "2.0.5-alpha.3",
|
4
|
+
"description": "Default processor",
|
5
|
+
"author": "Pedro Sanders <psanders@fonoster.com>",
|
6
|
+
"homepage": "https://github.com/fonoster/routr#readme",
|
7
|
+
"license": "MIT",
|
8
|
+
"main": "dist/connect",
|
9
|
+
"types": "dist/connect",
|
10
|
+
"directories": {
|
11
|
+
"src": "src",
|
12
|
+
"test": "test"
|
13
|
+
},
|
14
|
+
"scripts": {
|
15
|
+
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
16
|
+
"build": "tsc -b tsconfig.json"
|
17
|
+
},
|
18
|
+
"bin": {
|
19
|
+
"run_connect": "dist/runner.js"
|
20
|
+
},
|
21
|
+
"dependencies": {
|
22
|
+
"@fonoster/logger": "^0.3.3",
|
23
|
+
"@routr/common": "^2.0.5-alpha.3",
|
24
|
+
"@routr/processor": "^2.0.5-alpha.3"
|
25
|
+
},
|
26
|
+
"files": [
|
27
|
+
"dist"
|
28
|
+
],
|
29
|
+
"publishConfig": {
|
30
|
+
"access": "public"
|
31
|
+
},
|
32
|
+
"repository": {
|
33
|
+
"type": "git",
|
34
|
+
"url": "git+https://github.com/fonoster/routr.git"
|
35
|
+
},
|
36
|
+
"bugs": {
|
37
|
+
"url": "https://github.com/fonoster/routr/issues"
|
38
|
+
},
|
39
|
+
"gitHead": "7d942466133a03f4bcfe0dc100f1a922b3ed14ad"
|
40
|
+
}
|