@fonoster/voice 0.22.4 → 0.22.10
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/createSession.js +14 -1
- package/dist/verbs/Verb.js +40 -12
- package/package.json +3 -3
package/dist/createSession.js
CHANGED
|
@@ -40,7 +40,20 @@ function createSession(handler) {
|
|
|
40
40
|
if (request) {
|
|
41
41
|
mediaSessionRef = request.mediaSessionRef;
|
|
42
42
|
const response = new VoiceResponse_1.VoiceResponse(request, voice);
|
|
43
|
-
|
|
43
|
+
// EventEmitter ignores the promise this callback returns, so an error
|
|
44
|
+
// escaping the handler becomes an unhandled rejection and, under Node's
|
|
45
|
+
// default policy, takes the whole voice server down with it. Verbs now
|
|
46
|
+
// reject when the session ends mid-call, which makes reaching here an
|
|
47
|
+
// ordinary occurrence rather than a defect in the application.
|
|
48
|
+
try {
|
|
49
|
+
yield handler(request, response);
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
logger.warn("voice handler did not complete", {
|
|
53
|
+
mediaSessionRef,
|
|
54
|
+
error: e instanceof Error ? e.message : e
|
|
55
|
+
});
|
|
56
|
+
}
|
|
44
57
|
resolve();
|
|
45
58
|
}
|
|
46
59
|
}));
|
package/dist/verbs/Verb.js
CHANGED
|
@@ -46,26 +46,54 @@ class Verb {
|
|
|
46
46
|
mediaSessionRef
|
|
47
47
|
});
|
|
48
48
|
return new Promise((resolve, reject) => {
|
|
49
|
+
// Every exit path must remove all three listeners. A verb shares the session
|
|
50
|
+
// stream with every other verb in the call, so anything left attached
|
|
51
|
+
// accumulates for the lifetime of the session.
|
|
52
|
+
const cleanup = () => {
|
|
53
|
+
voice.removeListener(common_1.StreamEvent.DATA, dataListener);
|
|
54
|
+
voice.removeListener(common_1.StreamEvent.END, endListener);
|
|
55
|
+
voice.removeListener(common_1.StreamEvent.ERROR, errorListener);
|
|
56
|
+
};
|
|
57
|
+
const dataListener = (result) => {
|
|
58
|
+
const expectedContent = (0, getExpectedContent_1.getExpectedContent)(this.constructor.name);
|
|
59
|
+
if (expectedContent !== result.content) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
logger.verbose(`received ${this.constructor.name} response`, {
|
|
63
|
+
mediaSessionRef
|
|
64
|
+
});
|
|
65
|
+
cleanup();
|
|
66
|
+
resolve(result);
|
|
67
|
+
};
|
|
68
|
+
// Without these the promise has exactly one exit: a matching response. When the
|
|
69
|
+
// session dies first — the caller hangs up mid-verb, or the transport fails —
|
|
70
|
+
// it is left pending forever, neither resolved nor rejected. The application
|
|
71
|
+
// then awaits a verb that can never complete and the call is stranded rather
|
|
72
|
+
// than failed.
|
|
73
|
+
const endListener = () => {
|
|
74
|
+
cleanup();
|
|
75
|
+
reject(new Error(`voice session ended before the ${this.constructor.name} verb completed`));
|
|
76
|
+
};
|
|
77
|
+
const errorListener = (error) => {
|
|
78
|
+
cleanup();
|
|
79
|
+
reject(error instanceof Error
|
|
80
|
+
? error
|
|
81
|
+
: new Error(`voice session failed during the ${this.constructor.name} verb: ${error}`));
|
|
82
|
+
};
|
|
49
83
|
try {
|
|
50
84
|
const fullRequest = Object.assign(Object.assign({}, params), { mediaSessionRef });
|
|
51
85
|
(0, validateRequest_1.validateRequest)(this.getValidationSchema(), fullRequest);
|
|
86
|
+
// Listen before writing: a response cannot be delivered to a listener that
|
|
87
|
+
// does not exist yet.
|
|
88
|
+
voice.on(common_1.StreamEvent.DATA, dataListener);
|
|
89
|
+
voice.on(common_1.StreamEvent.END, endListener);
|
|
90
|
+
voice.on(common_1.StreamEvent.ERROR, errorListener);
|
|
52
91
|
voice.write({
|
|
53
92
|
[`${(0, common_1.toCamelCase)(this.constructor.name)}Request`]: fullRequest
|
|
54
93
|
});
|
|
55
|
-
const dataListener = (result) => {
|
|
56
|
-
const expectedContent = (0, getExpectedContent_1.getExpectedContent)(this.constructor.name);
|
|
57
|
-
if (expectedContent !== result.content) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
logger.verbose(`received ${this.constructor.name} response`, {
|
|
61
|
-
mediaSessionRef
|
|
62
|
-
});
|
|
63
|
-
resolve(result);
|
|
64
|
-
voice.removeListener(common_1.StreamEvent.DATA, dataListener);
|
|
65
|
-
};
|
|
66
|
-
voice.on(common_1.StreamEvent.DATA, dataListener);
|
|
67
94
|
}
|
|
68
95
|
catch (e) {
|
|
96
|
+
cleanup();
|
|
69
97
|
reject(e);
|
|
70
98
|
}
|
|
71
99
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/voice",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.10",
|
|
4
4
|
"description": "Voice Server for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@fonoster/common": "^0.22.3",
|
|
26
|
-
"@fonoster/identity": "^0.22.
|
|
26
|
+
"@fonoster/identity": "^0.22.7",
|
|
27
27
|
"@fonoster/logger": "^0.22.0",
|
|
28
28
|
"@grpc/grpc-js": "~1.10.6",
|
|
29
29
|
"deepmerge": "^4.3.1",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"bugs": {
|
|
46
46
|
"url": "https://github.com/fonoster/fonoster/issues"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "a222992b88756fcfe60c2e05bf2bc9a19f65f19d"
|
|
49
49
|
}
|