@routr/rtprelay 2.0.8-alpha.28
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/client.d.ts +5 -0
- package/dist/client.js +42 -0
- package/dist/envs.d.ts +3 -0
- package/dist/envs.js +27 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +112 -0
- package/dist/tracer.d.ts +7 -0
- package/dist/tracer.js +53 -0
- package/dist/types.d.ts +33 -0
- package/dist/types.js +28 -0
- package/dist/utils.d.ts +26 -0
- package/dist/utils.js +71 -0
- package/package.json +49 -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/client.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MessageRequest } from "@routr/common";
|
|
2
|
+
import { RTPEConfig, RTPEFunctionResult } from "./types";
|
|
3
|
+
export declare function offer(config: RTPEConfig): (request: MessageRequest) => Promise<RTPEFunctionResult>;
|
|
4
|
+
export declare function answer(config: RTPEConfig): (request: MessageRequest) => Promise<RTPEFunctionResult>;
|
|
5
|
+
export declare function del(config: RTPEConfig): (request: MessageRequest) => Promise<RTPEFunctionResult>;
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.del = exports.answer = exports.offer = void 0;
|
|
13
|
+
const envs_1 = require("./envs");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
16
|
+
const Client = require("rtpengine-client").Client;
|
|
17
|
+
const rtpe = new Client({ timeout: envs_1.RTPENGINE_TIMEOUT });
|
|
18
|
+
function offer(config) {
|
|
19
|
+
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const direction = (0, utils_1.getDirectionFromRequest)(request);
|
|
21
|
+
const sdpModifiers = (0, utils_1.getRTPEParamsByDirection)(direction);
|
|
22
|
+
return yield rtpe.offer(config, Object.assign(Object.assign({}, sdpModifiers), { sdp: request.message.body, "call-id": request.message.callId.callId, "from-tag": request.message.from.tag, "to-tag": request.message.to.tag }));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
exports.offer = offer;
|
|
26
|
+
function answer(config) {
|
|
27
|
+
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const direction = (0, utils_1.getDirectionFromResponse)(request);
|
|
29
|
+
const sdpModifiers = (0, utils_1.getRTPEParamsByDirection)(direction);
|
|
30
|
+
return yield rtpe.answer(config, Object.assign(Object.assign({}, sdpModifiers), { sdp: request.message.body, "call-id": request.message.callId.callId, "from-tag": request.message.from.tag, "to-tag": request.message.to.tag }));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.answer = answer;
|
|
34
|
+
function del(config) {
|
|
35
|
+
return (request) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return yield rtpe.delete(config, {
|
|
37
|
+
"call-id": request.message.callId.callId,
|
|
38
|
+
"from-tag": request.message.from.tag
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
exports.del = del;
|
package/dist/envs.d.ts
ADDED
package/dist/envs.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RTPENGINE_TIMEOUT = exports.RTPENGINE_PORT = exports.RTPENGINE_HOST = void 0;
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
7
|
+
* http://github.com/fonoster
|
|
8
|
+
*
|
|
9
|
+
* This file is part of Routr.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the MIT License (the "License");
|
|
12
|
+
* you may not use this file except in compliance with
|
|
13
|
+
* the License. You may obtain a copy of the License at
|
|
14
|
+
*
|
|
15
|
+
* https://opensource.org/licenses/MIT
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
18
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
19
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
20
|
+
* See the License for the specific language governing permissions and
|
|
21
|
+
* limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
const common_1 = require("@routr/common");
|
|
24
|
+
common_1.Assertions.assertEnvsAreSet(["RTPENGINE_HOST"]);
|
|
25
|
+
exports.RTPENGINE_HOST = process.env.RTPENGINE_HOST;
|
|
26
|
+
exports.RTPENGINE_PORT = parseInt((_a = process.env.RTPENGINE_PORT) !== null && _a !== void 0 ? _a : "22222");
|
|
27
|
+
exports.RTPENGINE_TIMEOUT = parseInt((_b = process.env.RTPENGINE_TIMEOUT) !== null && _b !== void 0 ? _b : "5000");
|
package/dist/runner.d.ts
ADDED
package/dist/runner.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
+
if (mod && mod.__esModule) return mod;
|
|
21
|
+
var result = {};
|
|
22
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
+
__setModuleDefault(result, mod);
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var _a;
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
/*
|
|
38
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
39
|
+
* http://github.com/fonoster/routr
|
|
40
|
+
*
|
|
41
|
+
* This file is part of Routr
|
|
42
|
+
*
|
|
43
|
+
* Licensed under the MIT License (the "License");
|
|
44
|
+
* you may not use this file except in compliance with
|
|
45
|
+
* the License. You may obtain a copy of the License at
|
|
46
|
+
*
|
|
47
|
+
* https://opensource.org/licenses/MIT
|
|
48
|
+
*
|
|
49
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
50
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
51
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
52
|
+
* See the License for the specific language governing permissions and
|
|
53
|
+
* limitations under the License.
|
|
54
|
+
*/
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
+
require("./tracer").init("dispatcher");
|
|
57
|
+
const processor_1 = __importStar(require("@routr/processor"));
|
|
58
|
+
const client_1 = require("./client");
|
|
59
|
+
const common_1 = require("@routr/common");
|
|
60
|
+
const types_1 = require("./types");
|
|
61
|
+
const logger_1 = require("@fonoster/logger");
|
|
62
|
+
const envs_1 = require("./envs");
|
|
63
|
+
const utils_1 = require("./utils");
|
|
64
|
+
const logger = (0, logger_1.getLogger)({ service: "rtprelay", filePath: __filename });
|
|
65
|
+
const rtpeConfig = { host: envs_1.RTPENGINE_HOST, port: envs_1.RTPENGINE_PORT };
|
|
66
|
+
new processor_1.default({
|
|
67
|
+
bindAddr: (_a = process.env.BIND_ADDR) !== null && _a !== void 0 ? _a : "0.0.0.0:51903",
|
|
68
|
+
name: "rtprelay-middleware"
|
|
69
|
+
}).listen((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
|
+
try {
|
|
71
|
+
if ((0, utils_1.shouldNotHandleRequest)(req)) {
|
|
72
|
+
return res.send(req);
|
|
73
|
+
}
|
|
74
|
+
const direction = processor_1.Helper.isTypeResponse(req)
|
|
75
|
+
? (0, utils_1.getDirectionFromResponse)(req)
|
|
76
|
+
: (0, utils_1.getDirectionFromRequest)(req);
|
|
77
|
+
const sendRequest = (f) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
var _b;
|
|
79
|
+
const r = yield f(rtpeConfig)(req);
|
|
80
|
+
if (r.result === "error") {
|
|
81
|
+
throw new common_1.CommonErrors.BadRequestError(r["error-reason"]);
|
|
82
|
+
}
|
|
83
|
+
if ((0, utils_1.callInvolvesWebRTC)(direction)) {
|
|
84
|
+
req.message.body = (_b = r.sdp) === null || _b === void 0 ? void 0 : _b.replaceAll("a=crypto:", "a=ignore:").replaceAll("a=sendrecv", "a=sendrecv\na=rtcp-mux");
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
req.message.body = r.sdp;
|
|
88
|
+
}
|
|
89
|
+
return res.send(req);
|
|
90
|
+
});
|
|
91
|
+
if (processor_1.Helper.isInviteOrAckWithSDP(req)) {
|
|
92
|
+
return yield sendRequest(client_1.offer);
|
|
93
|
+
}
|
|
94
|
+
else if (processor_1.Helper.isRinging(req) && direction === types_1.Direction.WEB_TO_PHONE) {
|
|
95
|
+
// Fixme: This was added to prevent the ringing message from being sent to the
|
|
96
|
+
// caller while the call is being established. This is a temporary fix
|
|
97
|
+
req.message.body = "";
|
|
98
|
+
return res.send(req);
|
|
99
|
+
}
|
|
100
|
+
else if (processor_1.Helper.isOkOrRingingWithSDP(req)) {
|
|
101
|
+
return yield sendRequest(client_1.answer);
|
|
102
|
+
}
|
|
103
|
+
else if (processor_1.Helper.isBye(req)) {
|
|
104
|
+
return yield sendRequest(client_1.del);
|
|
105
|
+
}
|
|
106
|
+
res.send(req);
|
|
107
|
+
}
|
|
108
|
+
catch (e) {
|
|
109
|
+
logger.error(e);
|
|
110
|
+
res.sendInternalServerError();
|
|
111
|
+
}
|
|
112
|
+
}));
|
package/dist/tracer.d.ts
ADDED
package/dist/tracer.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
exports.init = void 0;
|
|
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 api_1 = __importDefault(require("@opentelemetry/api"));
|
|
26
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
27
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
28
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
29
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
30
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
31
|
+
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
32
|
+
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
|
|
33
|
+
/**
|
|
34
|
+
* This function registers the instrumentations for the service.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} serviceName - The name of the service.
|
|
37
|
+
* @return {Tracer} The tracer object.
|
|
38
|
+
*/
|
|
39
|
+
function init(serviceName) {
|
|
40
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
41
|
+
resource: new resources_1.Resource({
|
|
42
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
const exporter = new exporter_jaeger_1.JaegerExporter();
|
|
46
|
+
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
47
|
+
provider.register();
|
|
48
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
49
|
+
instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
|
|
50
|
+
});
|
|
51
|
+
return api_1.default.trace.getTracer("routr-tracer");
|
|
52
|
+
}
|
|
53
|
+
exports.init = init;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MessageRequest } from "@routr/common";
|
|
2
|
+
export declare enum Direction {
|
|
3
|
+
WEB_TO_WEB = "web-to-web",
|
|
4
|
+
WEB_TO_PHONE = "web-to-phone",
|
|
5
|
+
PHONE_TO_WEB = "phone-to-web",
|
|
6
|
+
PHONE_TO_PHONE = "phone-to-phone"
|
|
7
|
+
}
|
|
8
|
+
export interface RTPERequest {
|
|
9
|
+
"call-id": string;
|
|
10
|
+
"from-tag": string;
|
|
11
|
+
"to-tag"?: string;
|
|
12
|
+
"DTLS-fingerprint"?: string;
|
|
13
|
+
"DTLS-passive"?: boolean;
|
|
14
|
+
"transport-protocol"?: string;
|
|
15
|
+
sdp?: string;
|
|
16
|
+
ICE?: string;
|
|
17
|
+
SDES?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RTPEConfig {
|
|
20
|
+
host: string;
|
|
21
|
+
port: number;
|
|
22
|
+
}
|
|
23
|
+
export type RTPEClient = {
|
|
24
|
+
send: (request: RTPERequest) => Promise<string>;
|
|
25
|
+
};
|
|
26
|
+
export type RTPEFunctionResult = {
|
|
27
|
+
result: "ok";
|
|
28
|
+
sdp: string;
|
|
29
|
+
} | {
|
|
30
|
+
result: "error";
|
|
31
|
+
"error-reason": string;
|
|
32
|
+
};
|
|
33
|
+
export type RTPEFunction = (config: RTPEConfig) => (req: MessageRequest) => Promise<RTPEFunctionResult>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Direction = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster
|
|
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
|
+
var Direction;
|
|
23
|
+
(function (Direction) {
|
|
24
|
+
Direction["WEB_TO_WEB"] = "web-to-web";
|
|
25
|
+
Direction["WEB_TO_PHONE"] = "web-to-phone";
|
|
26
|
+
Direction["PHONE_TO_WEB"] = "phone-to-web";
|
|
27
|
+
Direction["PHONE_TO_PHONE"] = "phone-to-phone";
|
|
28
|
+
})(Direction = exports.Direction || (exports.Direction = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CommonTypes as CT, MessageRequest } from "@routr/common";
|
|
2
|
+
import { Direction } from "./types";
|
|
3
|
+
export declare function getDirectionFromResponse(request: MessageRequest): Direction;
|
|
4
|
+
export declare function getDirectionFromRequest(request: MessageRequest): Direction;
|
|
5
|
+
export declare function getDirection(srcTransport: CT.Transport, dstTransport: CT.Transport): Direction;
|
|
6
|
+
export declare function getRTPEParamsByDirection(dir: Direction): {
|
|
7
|
+
ICE: string;
|
|
8
|
+
SDES: string;
|
|
9
|
+
flags: string;
|
|
10
|
+
"transport-protocol"?: undefined;
|
|
11
|
+
"rtcp-mux"?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
"transport-protocol": string;
|
|
14
|
+
"rtcp-mux": string;
|
|
15
|
+
ICE: string;
|
|
16
|
+
flags: string;
|
|
17
|
+
SDES?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
"transport-protocol": string;
|
|
20
|
+
"rtcp-mux": string;
|
|
21
|
+
ICE: string;
|
|
22
|
+
SDES: string;
|
|
23
|
+
flags: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const callInvolvesWebRTC: (direction: Direction) => boolean;
|
|
26
|
+
export declare const shouldNotHandleRequest: (req: MessageRequest) => boolean;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shouldNotHandleRequest = exports.callInvolvesWebRTC = exports.getRTPEParamsByDirection = exports.getDirection = exports.getDirectionFromRequest = exports.getDirectionFromResponse = void 0;
|
|
4
|
+
const processor_1 = require("@routr/processor");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
function getDirectionFromResponse(request) {
|
|
7
|
+
const srcTransport = request.sender.transport;
|
|
8
|
+
const dstTransport = request.message.via[0].transport;
|
|
9
|
+
return getDirection(srcTransport, dstTransport);
|
|
10
|
+
}
|
|
11
|
+
exports.getDirectionFromResponse = getDirectionFromResponse;
|
|
12
|
+
// Will be able to determine the direction with Request-URI and Route header
|
|
13
|
+
function getDirectionFromRequest(request) {
|
|
14
|
+
const srcTransport = request.sender.transport;
|
|
15
|
+
const dstTransport = request.message.via[0].transport;
|
|
16
|
+
return getDirection(srcTransport, dstTransport);
|
|
17
|
+
}
|
|
18
|
+
exports.getDirectionFromRequest = getDirectionFromRequest;
|
|
19
|
+
function getDirection(srcTransport, dstTransport) {
|
|
20
|
+
if (processor_1.Helper.isWebRTC(srcTransport) && processor_1.Helper.isWebRTC(dstTransport)) {
|
|
21
|
+
return types_1.Direction.WEB_TO_WEB;
|
|
22
|
+
}
|
|
23
|
+
if (processor_1.Helper.isWebRTC(srcTransport) && !processor_1.Helper.isWebRTC(dstTransport)) {
|
|
24
|
+
return types_1.Direction.WEB_TO_PHONE;
|
|
25
|
+
}
|
|
26
|
+
if (!processor_1.Helper.isWebRTC(srcTransport) && processor_1.Helper.isWebRTC(dstTransport)) {
|
|
27
|
+
return types_1.Direction.PHONE_TO_WEB;
|
|
28
|
+
}
|
|
29
|
+
return types_1.Direction.PHONE_TO_PHONE;
|
|
30
|
+
}
|
|
31
|
+
exports.getDirection = getDirection;
|
|
32
|
+
function getRTPEParamsByDirection(dir) {
|
|
33
|
+
switch (dir) {
|
|
34
|
+
case types_1.Direction.WEB_TO_WEB:
|
|
35
|
+
return {
|
|
36
|
+
ICE: "force",
|
|
37
|
+
SDES: "off",
|
|
38
|
+
flags: "trust-address replace-origin replace-session-connection"
|
|
39
|
+
};
|
|
40
|
+
case types_1.Direction.WEB_TO_PHONE:
|
|
41
|
+
return {
|
|
42
|
+
"transport-protocol": "RTP/AVP",
|
|
43
|
+
"rtcp-mux": "demux",
|
|
44
|
+
ICE: "remove",
|
|
45
|
+
flags: "trust-address replace-origin replace-session-connection"
|
|
46
|
+
};
|
|
47
|
+
case types_1.Direction.PHONE_TO_WEB:
|
|
48
|
+
return {
|
|
49
|
+
"transport-protocol": "UDP/TLS/RTP/SAVPF",
|
|
50
|
+
"rtcp-mux": "required",
|
|
51
|
+
ICE: "force",
|
|
52
|
+
SDES: "off",
|
|
53
|
+
flags: "trust-address replace-origin replace-session-connection generate-mid"
|
|
54
|
+
};
|
|
55
|
+
case types_1.Direction.PHONE_TO_PHONE:
|
|
56
|
+
return {
|
|
57
|
+
"transport-protocol": "RTP/AVP",
|
|
58
|
+
"rtcp-mux": "demux",
|
|
59
|
+
ICE: "remove",
|
|
60
|
+
flags: "trust-address replace-origin replace-session-connection"
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.getRTPEParamsByDirection = getRTPEParamsByDirection;
|
|
65
|
+
const callInvolvesWebRTC = (direction) => direction == types_1.Direction.WEB_TO_PHONE || direction == types_1.Direction.PHONE_TO_WEB;
|
|
66
|
+
exports.callInvolvesWebRTC = callInvolvesWebRTC;
|
|
67
|
+
const shouldNotHandleRequest = (req) => !(processor_1.Helper.isInviteOrAckWithSDP(req) ||
|
|
68
|
+
processor_1.Helper.isOkOrRingingWithSDP(req) ||
|
|
69
|
+
processor_1.Helper.isRinging(req) ||
|
|
70
|
+
processor_1.Helper.isBye(req));
|
|
71
|
+
exports.shouldNotHandleRequest = shouldNotHandleRequest;
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@routr/rtprelay",
|
|
3
|
+
"version": "2.0.8-alpha.28",
|
|
4
|
+
"description": "Media Relay for Routr using RTPengine",
|
|
5
|
+
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
|
+
"homepage": "https://github.com/fonoster/routr#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/runner",
|
|
9
|
+
"types": "dist/runner",
|
|
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_rtprelay": "dist/runner.js"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@fonoster/logger": "0.3.18",
|
|
23
|
+
"@opentelemetry/api": "^1.0.4",
|
|
24
|
+
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
25
|
+
"@opentelemetry/instrumentation": "^0.27.0",
|
|
26
|
+
"@opentelemetry/instrumentation-grpc": "^0.27.0",
|
|
27
|
+
"@opentelemetry/resources": "^1.0.4",
|
|
28
|
+
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
29
|
+
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
30
|
+
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
31
|
+
"@routr/common": "^2.0.8-alpha.28",
|
|
32
|
+
"@routr/processor": "^2.0.8-alpha.28",
|
|
33
|
+
"rtpengine-client": "^0.4.11"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/fonoster/routr.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/fonoster/routr/issues"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "d28aabb2fce0600aaae94aa37709e89ed7112c99"
|
|
49
|
+
}
|