@fonoster/voice 0.7.0 → 0.7.3

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.
@@ -163,7 +163,6 @@ declare class VoiceResponse {
163
163
  * @param {StreamOptions} options - Options to control the stream operation
164
164
  * @param {StreamDirection} options.direction - The direction to stream the audio (IN, OUT, BOTH). Default is BOTH
165
165
  * @param {StreamAudioFormat} options.format - The audio format to stream (WAV). Default is WAV
166
- * @param {boolean} options.enableVad - Enable voice activity detection. Default is false
167
166
  * @return {Promise<Stream>} The stream object
168
167
  * @example
169
168
  *
@@ -171,9 +170,7 @@ declare class VoiceResponse {
171
170
  * await response.answer();
172
171
  *
173
172
  * const stream = await response.stream({
174
- * direction: StreamDirection.BOTH,
175
- * format: StreamAudioFormat.WAV,
176
- * enableVad: true
173
+ * direction: StreamDirection.BOTH
177
174
  * });
178
175
  *
179
176
  * stream.onPayload((payload) => {
@@ -184,7 +181,7 @@ declare class VoiceResponse {
184
181
  * // stream.write({ type: StreamMessageType.AUDIO_OUT, payload: "\x00\x01\x02" });
185
182
  * }
186
183
  */
187
- stream(options: StreamOptions): Promise<Stream>;
184
+ stream(options?: StreamOptions): Promise<Stream>;
188
185
  /**
189
186
  * Starts a server-side stream gather operation which sends transcription data to the voice server.
190
187
  *
@@ -257,7 +257,6 @@ class VoiceResponse {
257
257
  * @param {StreamOptions} options - Options to control the stream operation
258
258
  * @param {StreamDirection} options.direction - The direction to stream the audio (IN, OUT, BOTH). Default is BOTH
259
259
  * @param {StreamAudioFormat} options.format - The audio format to stream (WAV). Default is WAV
260
- * @param {boolean} options.enableVad - Enable voice activity detection. Default is false
261
260
  * @return {Promise<Stream>} The stream object
262
261
  * @example
263
262
  *
@@ -265,9 +264,7 @@ class VoiceResponse {
265
264
  * await response.answer();
266
265
  *
267
266
  * const stream = await response.stream({
268
- * direction: StreamDirection.BOTH,
269
- * format: StreamAudioFormat.WAV,
270
- * enableVad: true
267
+ * direction: StreamDirection.BOTH
271
268
  * });
272
269
  *
273
270
  * stream.onPayload((payload) => {
@@ -54,7 +54,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
54
54
  * limitations under the License.
55
55
  */
56
56
  const common_1 = require("@fonoster/common");
57
- const identity_1 = require("@fonoster/identity");
58
57
  const logger_1 = require("@fonoster/logger");
59
58
  const grpc = __importStar(require("@grpc/grpc-js"));
60
59
  const deepmerge_1 = __importDefault(require("deepmerge"));
@@ -72,20 +71,20 @@ class VoiceServer {
72
71
  try {
73
72
  const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
74
73
  const credentials = yield (0, common_1.getServerCredentials)({});
75
- let server;
76
- if (this.config.skipIdentity) {
77
- server = new grpc.Server();
78
- }
79
- else {
80
- // Get the public key from the identity service
81
- const response = yield (0, identity_1.getPublicKeyClient)(this.config.identityAddress);
82
- const authorization = (0, identity_1.createAuthInterceptor)(response.publicKey, [
83
- "/grpc.health.v1.Health/Check"
84
- ]);
85
- server = new grpc.Server({
86
- interceptors: [authorization]
87
- });
88
- }
74
+ const server = new grpc.Server();
75
+ // FIXME: Must re-implement without dependency on identity package
76
+ // if (this.config.skipIdentity) {
77
+ // server = new grpc.Server();
78
+ // } else {
79
+ // // Get the public key from the identity service
80
+ // const response = await getPublicKeyClient(this.config.identityAddress);
81
+ // const authorization = createAuthInterceptor(response.publicKey, [
82
+ // "/grpc.health.v1.Health/Check"
83
+ // ]);
84
+ // server = new grpc.Server({
85
+ // interceptors: [authorization]
86
+ // });
87
+ // }
89
88
  server.addService(serviceDefinition_1.serviceDefinition, {
90
89
  createSession: (0, createSession_1.createSession)(handler)
91
90
  });
package/dist/demo.js CHANGED
@@ -34,8 +34,9 @@ const common_1 = require("@fonoster/common");
34
34
  const logger_1 = require("@fonoster/logger");
35
35
  const VoiceServer_1 = __importDefault(require("./VoiceServer"));
36
36
  const logger = (0, logger_1.getLogger)({ service: "voice", filePath: __filename });
37
+ const skipIdentity = process.env.NODE_ENV === "dev";
37
38
  // Only skip identity for local development
38
- new VoiceServer_1.default({ skipIdentity: true }).listen((req, res) => __awaiter(void 0, void 0, void 0, function* () {
39
+ new VoiceServer_1.default({ skipIdentity }).listen((req, res) => __awaiter(void 0, void 0, void 0, function* () {
39
40
  const { ingressNumber, sessionRef, appRef } = req;
40
41
  logger.verbose("voice request", { ingressNumber, sessionRef, appRef });
41
42
  yield res.answer();
@@ -26,9 +26,8 @@ const Verb_1 = require("./Verb");
26
26
  class StartStream extends Verb_1.Verb {
27
27
  getValidationSchema() {
28
28
  return zod_1.z.object({
29
- direction: zod_1.z.nativeEnum(common_1.StreamDirection),
30
- format: zod_1.z.nativeEnum(common_1.StreamAudioFormat),
31
- enableVad: zod_1.z.boolean()
29
+ direction: zod_1.z.nativeEnum(common_1.StreamDirection).optional().nullable(),
30
+ format: zod_1.z.nativeEnum(common_1.StreamAudioFormat).optional().nullable()
32
31
  });
33
32
  }
34
33
  }
@@ -30,6 +30,7 @@ exports.Verb = void 0;
30
30
  */
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
+ const getExpectedContent_1 = require("./getExpectedContent");
33
34
  const validateRequest_1 = require("./validateRequest");
34
35
  const logger = (0, logger_1.getLogger)({ service: "voice", filePath: __filename });
35
36
  class Verb {
@@ -52,6 +53,10 @@ class Verb {
52
53
  [`${(0, common_1.toCamelCase)(this.constructor.name)}Request`]: fullRequest
53
54
  });
54
55
  const dataListener = (result) => {
56
+ const expectedContent = (0, getExpectedContent_1.getExpectedContent)(this.constructor.name);
57
+ if (expectedContent !== result.content) {
58
+ return;
59
+ }
55
60
  logger.verbose(`received ${this.constructor.name} response`, {
56
61
  sessionRef
57
62
  });
@@ -0,0 +1,2 @@
1
+ declare function getExpectedContent(name: string): string;
2
+ export { getExpectedContent };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExpectedContent = getExpectedContent;
4
+ /*
5
+ * Copyright (C) 2024 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
+ function getExpectedContent(name) {
24
+ switch (name) {
25
+ case "StartStreamGather":
26
+ return "startStreamGatherResponse";
27
+ case "StartStream":
28
+ return "startStreamResponse";
29
+ default:
30
+ return `${(0, common_1.toCamelCase)(name)}Response`;
31
+ }
32
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/voice",
3
- "version": "0.7.0",
3
+ "version": "0.7.3",
4
4
  "description": "Voice Server for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -20,9 +20,8 @@
20
20
  "fonoster": "./dist/index.js"
21
21
  },
22
22
  "dependencies": {
23
- "@fonoster/common": "^0.7.0",
24
- "@fonoster/identity": "^0.7.0",
25
- "@fonoster/logger": "^0.7.0",
23
+ "@fonoster/common": "^0.7.3",
24
+ "@fonoster/logger": "^0.7.2",
26
25
  "@grpc/grpc-js": "~1.10.6",
27
26
  "deepmerge": "^4.3.1",
28
27
  "grpc-health-check": "^2.0.2",
@@ -43,5 +42,5 @@
43
42
  "bugs": {
44
43
  "url": "https://github.com/fonoster/fonoster/issues"
45
44
  },
46
- "gitHead": "afa950ace3b1d022b6dc8be0c3b87a6b8a5ba3c5"
45
+ "gitHead": "97aa6649691819fe8a704b96bc62b1b142162393"
47
46
  }