@routr/location 2.0.8-alpha.10 → 2.0.8-alpha.12
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.d.ts +1 -2
- package/dist/client.js +1 -2
- package/dist/config/schema.js +1 -1
- package/dist/location.d.ts +0 -1
- package/dist/location.js +25 -13
- package/dist/types.d.ts +2 -1
- package/package.json +4 -4
package/dist/client.d.ts
CHANGED
|
@@ -31,8 +31,7 @@ export default class Location implements ILocationService {
|
|
|
31
31
|
*
|
|
32
32
|
* @param {FindRoutesResponse} request - Request to find routes
|
|
33
33
|
* @param {string} request.aor - AOR of the route
|
|
34
|
-
* @param {Map<string, string>} request.labels - Optional Route labels
|
|
35
|
-
* @param {string} request.sessionAffinityRef - Optiona session affinity ref
|
|
34
|
+
* @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
|
|
36
35
|
* @return {Promise<void>}
|
|
37
36
|
*/
|
|
38
37
|
findRoutes(request: FindRoutesRequest): Promise<Route[]>;
|
package/dist/client.js
CHANGED
|
@@ -75,8 +75,7 @@ class Location {
|
|
|
75
75
|
*
|
|
76
76
|
* @param {FindRoutesResponse} request - Request to find routes
|
|
77
77
|
* @param {string} request.aor - AOR of the route
|
|
78
|
-
* @param {Map<string, string>} request.labels - Optional Route labels
|
|
79
|
-
* @param {string} request.sessionAffinityRef - Optiona session affinity ref
|
|
78
|
+
* @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
|
|
80
79
|
* @return {Promise<void>}
|
|
81
80
|
*/
|
|
82
81
|
findRoutes(request) {
|
package/dist/config/schema.js
CHANGED
package/dist/location.d.ts
CHANGED
package/dist/location.js
CHANGED
|
@@ -49,8 +49,7 @@ class Location {
|
|
|
49
49
|
this.store = store;
|
|
50
50
|
this.backends = backends;
|
|
51
51
|
this.rrCount = new Map();
|
|
52
|
-
this.
|
|
53
|
-
this.backends.forEach((value, key) => this.rrCount.set(key, 0));
|
|
52
|
+
this.backends.forEach((_, key) => this.rrCount.set(key, 0));
|
|
54
53
|
}
|
|
55
54
|
/** @inheritdoc */
|
|
56
55
|
addRoute(request) {
|
|
@@ -64,10 +63,16 @@ class Location {
|
|
|
64
63
|
findRoutes(request) {
|
|
65
64
|
var _a;
|
|
66
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
|
|
66
|
+
let routes = yield this.store.get(request.callId);
|
|
67
|
+
if (routes.length > 0) {
|
|
68
|
+
return routes;
|
|
69
|
+
}
|
|
70
|
+
routes = request.labels
|
|
68
71
|
? (yield this.store.get(request.aor)).filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
|
|
69
72
|
: (_a = (yield this.store.get(request.aor))) !== null && _a !== void 0 ? _a : [];
|
|
70
73
|
if (request.aor.startsWith(AOR_SCHEME.SIP)) {
|
|
74
|
+
// Set call to the last route
|
|
75
|
+
this.store.put(request.callId, routes[0]);
|
|
71
76
|
return routes;
|
|
72
77
|
}
|
|
73
78
|
else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
|
|
@@ -76,9 +81,14 @@ class Location {
|
|
|
76
81
|
throw new errors_1.NotRoutesFoundForAOR(request.aor);
|
|
77
82
|
}
|
|
78
83
|
// If it has not affinity sesssion then get next
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
const r =
|
|
85
|
+
// Falls back to round-robin if no session affinity ref is provided
|
|
86
|
+
backend.withSessionAffinity && request.sessionAffinityRef
|
|
87
|
+
? [yield this.nextWithAffinity(routes, request.sessionAffinityRef)]
|
|
81
88
|
: [this.next(routes, backend)];
|
|
89
|
+
// Next time we will get the route with callId
|
|
90
|
+
this.store.put(request.callId, r[0]);
|
|
91
|
+
return r;
|
|
82
92
|
}
|
|
83
93
|
throw new errors_1.UnsupportedSchema(request.aor);
|
|
84
94
|
});
|
|
@@ -106,14 +116,16 @@ class Location {
|
|
|
106
116
|
}
|
|
107
117
|
// Backend with session affinity does not support round-robin
|
|
108
118
|
// eslint-disable-next-line require-jsdoc
|
|
109
|
-
nextWithAffinity(routes,
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
nextWithAffinity(routes, sessionAffinityHeader) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const route = yield this.store.get(sessionAffinityHeader);
|
|
122
|
+
if (route.length > 0) {
|
|
123
|
+
return route[0];
|
|
124
|
+
}
|
|
125
|
+
const r = routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
|
|
126
|
+
this.store.put(sessionAffinityHeader, r);
|
|
127
|
+
return r;
|
|
128
|
+
});
|
|
117
129
|
}
|
|
118
130
|
}
|
|
119
131
|
exports.default = Location;
|
package/dist/types.d.ts
CHANGED
|
@@ -23,8 +23,9 @@ export interface AddRouteRequest {
|
|
|
23
23
|
}
|
|
24
24
|
export interface FindRoutesRequest {
|
|
25
25
|
aor: string;
|
|
26
|
-
|
|
26
|
+
callId: string;
|
|
27
27
|
sessionAffinityRef?: string;
|
|
28
|
+
labels?: Map<string, string>;
|
|
28
29
|
}
|
|
29
30
|
export interface FindRoutesResponse {
|
|
30
31
|
routes: Array<Route>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/location",
|
|
3
|
-
"version": "2.0.8-alpha.
|
|
3
|
+
"version": "2.0.8-alpha.12",
|
|
4
4
|
"description": "Creates and maintains a list of routes to all registered endpoints",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
36
36
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
37
37
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
38
|
-
"@routr/common": "^2.0.8-alpha.
|
|
39
|
-
"@routr/processor": "^2.0.8-alpha.
|
|
38
|
+
"@routr/common": "^2.0.8-alpha.12",
|
|
39
|
+
"@routr/processor": "^2.0.8-alpha.12",
|
|
40
40
|
"ajv": "^6.12.6",
|
|
41
41
|
"fp-ts": "^2.11.8",
|
|
42
42
|
"redis": "^4.0.4"
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"bugs": {
|
|
49
49
|
"url": "https://github.com/fonoster/routr/issues"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "57f6f94ceeba177909e209222d5ad0a1bc375896"
|
|
52
52
|
}
|