@fonoster/voice 0.22.7 → 0.23.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.
@@ -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
- yield handler(request, response);
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/types.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  * See the License for the specific language governing permissions and
17
17
  * limitations under the License.
18
18
  */
19
- import { VoiceRequest } from "@fonoster/common";
19
+ import { Amd, AmdStatus, VoiceRequest } from "@fonoster/common";
20
20
  import { VoiceResponse } from "./VoiceResponse";
21
21
  type VoiceHandler = (req: VoiceRequest, res: VoiceResponse) => Promise<void>;
22
22
  type ServerConfig = {
@@ -25,4 +25,4 @@ type ServerConfig = {
25
25
  identityAddress?: string;
26
26
  skipIdentity?: boolean;
27
27
  };
28
- export { ServerConfig, VoiceHandler, VoiceRequest };
28
+ export { Amd, AmdStatus, ServerConfig, VoiceHandler, VoiceRequest };
package/dist/types.js CHANGED
@@ -1,2 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AmdStatus = void 0;
4
+ /**
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
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("@fonoster/common");
23
+ Object.defineProperty(exports, "AmdStatus", { enumerable: true, get: function () { return common_1.AmdStatus; } });
@@ -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.7",
3
+ "version": "0.23.0",
4
4
  "description": "Voice Server for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -22,9 +22,9 @@
22
22
  "fonoster": "./dist/index.js"
23
23
  },
24
24
  "dependencies": {
25
- "@fonoster/common": "^0.22.3",
26
- "@fonoster/identity": "^0.22.7",
27
- "@fonoster/logger": "^0.22.0",
25
+ "@fonoster/common": "^0.23.0",
26
+ "@fonoster/identity": "^0.23.0",
27
+ "@fonoster/logger": "^0.23.0",
28
28
  "@grpc/grpc-js": "~1.10.6",
29
29
  "deepmerge": "^4.3.1",
30
30
  "grpc-health-check": "^2.0.2",
@@ -45,5 +45,5 @@
45
45
  "bugs": {
46
46
  "url": "https://github.com/fonoster/fonoster/issues"
47
47
  },
48
- "gitHead": "af2404e51a423e45e59515282495ecdec27e0eed"
48
+ "gitHead": "acdd199a840d56419e25dae015d3b74892fe86cc"
49
49
  }