@routr/rtprelay 2.20.0 → 2.22.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/dist/client.js CHANGED
@@ -28,14 +28,14 @@ function query(config) {
28
28
  function offer(config, invertTags = false) {
29
29
  return (request) => __awaiter(this, void 0, void 0, function* () {
30
30
  const direction = (0, utils_1.getDirectionFromRequest)(request);
31
- const sdpModifiers = (0, utils_1.getRTPEParamsByDirection)(direction);
31
+ const sdpModifiers = (0, utils_1.getRTPEParams)(request, direction);
32
32
  return yield rtpe.offer(config, Object.assign(Object.assign({}, sdpModifiers), { sdp: request.message.body, "call-id": request.message.callId.callId, "from-tag": invertTags ? request.message.to.tag : request.message.from.tag }));
33
33
  });
34
34
  }
35
35
  function answer(config, invertTags = false) {
36
36
  return (request) => __awaiter(this, void 0, void 0, function* () {
37
37
  const direction = (0, utils_1.getDirectionFromResponse)(request);
38
- const sdpModifiers = (0, utils_1.getRTPEParamsByDirection)(direction);
38
+ const sdpModifiers = (0, utils_1.getRTPEParams)(request, direction);
39
39
  return yield rtpe.answer(config, Object.assign(Object.assign({}, sdpModifiers), { sdp: request.message.body, "call-id": request.message.callId.callId, "from-tag": invertTags
40
40
  ? request.message.to.tag
41
41
  : request.message.from.tag, "to-tag": invertTags ? request.message.from.tag : request.message.to.tag }));
package/dist/utils.d.ts CHANGED
@@ -3,7 +3,34 @@ import { Direction } from "./types";
3
3
  export declare function getDirectionFromResponse(request: MessageRequest): Direction;
4
4
  export declare function getDirectionFromRequest(request: MessageRequest): Direction;
5
5
  export declare function getDirection(srcTransport: CT.Transport, dstTransport: CT.Transport): Direction;
6
- export declare function getRTPEParamsByDirection(dir: Direction): {
6
+ export declare const isSecurePhone: (transport: CT.Transport) => boolean;
7
+ export declare const getDestinationTransport: (request: MessageRequest) => CT.Transport;
8
+ export declare function getRTPEParamsByDirection(dir: Direction, secureCallee?: boolean): {
9
+ ICE: string;
10
+ SDES: string[];
11
+ flags: string[];
12
+ "transport-protocol"?: undefined;
13
+ DTLS?: undefined;
14
+ "rtcp-mux"?: undefined;
15
+ replace?: undefined;
16
+ } | {
17
+ "transport-protocol": string;
18
+ DTLS: string;
19
+ ICE: string;
20
+ "rtcp-mux": string[];
21
+ replace: string[];
22
+ flags: string[];
23
+ SDES?: undefined;
24
+ } | {
25
+ "transport-protocol": string;
26
+ "rtcp-mux": string;
27
+ ICE: string;
28
+ flags: string[];
29
+ SDES?: undefined;
30
+ DTLS?: undefined;
31
+ replace?: undefined;
32
+ };
33
+ export declare const getRTPEParams: (request: MessageRequest, direction: Direction) => {
7
34
  ICE: string;
8
35
  SDES: string[];
9
36
  flags: string[];
package/dist/utils.js CHANGED
@@ -1,10 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldNotHandleRequest = exports.callInvolvesWebRTC = void 0;
3
+ exports.shouldNotHandleRequest = exports.callInvolvesWebRTC = exports.getRTPEParams = exports.getDestinationTransport = exports.isSecurePhone = void 0;
4
4
  exports.getDirectionFromResponse = getDirectionFromResponse;
5
5
  exports.getDirectionFromRequest = getDirectionFromRequest;
6
6
  exports.getDirection = getDirection;
7
7
  exports.getRTPEParamsByDirection = getRTPEParamsByDirection;
8
+ /*
9
+ * Copyright (C) 2026 by Fonoster Inc (https://fonoster.com)
10
+ * http://github.com/fonoster/routr
11
+ *
12
+ * This file is part of Routr.
13
+ *
14
+ * Licensed under the MIT License (the "License");
15
+ * you may not use this file except in compliance with
16
+ * the License. You may obtain a copy of the License at
17
+ *
18
+ * https://opensource.org/licenses/MIT
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ /* eslint-disable require-jsdoc */
27
+ const common_1 = require("@routr/common");
8
28
  const processor_1 = require("@routr/processor");
9
29
  const types_1 = require("./types");
10
30
  function getDirectionFromResponse(request) {
@@ -31,7 +51,19 @@ function getDirection(srcTransport, dstTransport) {
31
51
  }
32
52
  return types_1.Direction.PHONE_TO_PHONE;
33
53
  }
34
- function getRTPEParamsByDirection(dir) {
54
+ // A phone leg reached over TLS, which is how a carrier that requires secure
55
+ // trunking is configured. SRTP follows the transport: such a leg gets SDES-SRTP.
56
+ const isSecurePhone = (transport) => (transport === null || transport === void 0 ? void 0 : transport.toUpperCase()) === common_1.CommonTypes.Transport.TLS;
57
+ exports.isSecurePhone = isSecurePhone;
58
+ // The leg a message is being sent to. For a request the EdgePort has already
59
+ // put its own Via on top, facing the next hop; for a response the top Via is
60
+ // the party the response goes back to.
61
+ const getDestinationTransport = (request) => { var _a; return (_a = request.message.via[0]) === null || _a === void 0 ? void 0 : _a.transport; };
62
+ exports.getDestinationTransport = getDestinationTransport;
63
+ // The RTPEngine parameters for the leg the message is sent to. With
64
+ // secureCallee the phone leg negotiates SDES-SRTP (RTP/SAVP) instead of plain
65
+ // RTP; RTPEngine then encrypts toward the carrier and bridges to the other leg.
66
+ function getRTPEParamsByDirection(dir, secureCallee = false) {
35
67
  switch (dir) {
36
68
  case types_1.Direction.WEB_TO_WEB:
37
69
  return {
@@ -41,12 +73,12 @@ function getRTPEParamsByDirection(dir) {
41
73
  };
42
74
  case types_1.Direction.WEB_TO_PHONE:
43
75
  return {
44
- "transport-protocol": "RTP/AVP",
76
+ "transport-protocol": secureCallee ? "RTP/SAVP" : "RTP/AVP",
45
77
  DTLS: "off",
46
78
  ICE: "remove",
47
79
  "rtcp-mux": ["demux"],
48
80
  replace: ["origin", "session-connection"],
49
- flags: ["trust-address", "SDES-no"]
81
+ flags: secureCallee ? ["trust-address"] : ["trust-address", "SDES-no"]
50
82
  };
51
83
  case types_1.Direction.PHONE_TO_WEB:
52
84
  return {
@@ -59,13 +91,17 @@ function getRTPEParamsByDirection(dir) {
59
91
  };
60
92
  case types_1.Direction.PHONE_TO_PHONE:
61
93
  return {
62
- "transport-protocol": "RTP/AVP",
94
+ "transport-protocol": secureCallee ? "RTP/SAVP" : "RTP/AVP",
63
95
  "rtcp-mux": "demux",
64
96
  ICE: "remove",
65
97
  flags: ["trust-address", "replace-origin", "replace-session-connection"]
66
98
  };
67
99
  }
68
100
  }
101
+ // The RTPEngine parameters for a message, from its direction and the transport
102
+ // of the leg it is sent to.
103
+ const getRTPEParams = (request, direction) => getRTPEParamsByDirection(direction, (0, exports.isSecurePhone)((0, exports.getDestinationTransport)(request)));
104
+ exports.getRTPEParams = getRTPEParams;
69
105
  const callInvolvesWebRTC = (direction) => direction == types_1.Direction.WEB_TO_PHONE || direction == types_1.Direction.PHONE_TO_WEB;
70
106
  exports.callInvolvesWebRTC = callInvolvesWebRTC;
71
107
  const shouldNotHandleRequest = (req) => !(processor_1.Helper.isInviteOrAckWithSDP(req) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/rtprelay",
3
- "version": "2.20.0",
3
+ "version": "2.22.0",
4
4
  "description": "Media Relay for Routr using RTPengine",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -21,8 +21,8 @@
21
21
  "dependencies": {
22
22
  "@fonoster/logger": "0.6.0",
23
23
  "@grpc/grpc-js": "~1.14.6",
24
- "@routr/common": "^2.20.0",
25
- "@routr/processor": "^2.20.0",
24
+ "@routr/common": "^2.22.0",
25
+ "@routr/processor": "^2.22.0",
26
26
  "rtpengine-client": "^0.4.11"
27
27
  },
28
28
  "files": [
@@ -38,5 +38,5 @@
38
38
  "bugs": {
39
39
  "url": "https://github.com/fonoster/routr/issues"
40
40
  },
41
- "gitHead": "3705573eb10fd828b0b736702eee5a5d036d7cdc"
41
+ "gitHead": "43868fbe7fb81a31b7eadd88d6847778d10f1754"
42
42
  }