@fonoster/apiserver 0.22.7 → 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.
@@ -66,9 +66,13 @@ class VoiceDispatcher {
66
66
  }
67
67
  try {
68
68
  const vc = yield createVoiceClient({ ari, event, channel });
69
- // Connect to voice server (must await to ensure speechHandler is initialized)
70
- yield vc.connect();
71
- voiceClients.set(channel.id, vc);
69
+ // Register the verb handlers BEFORE connecting. Connecting opens the session and
70
+ // sends the request that starts the voice application, and an application that
71
+ // replies immediately can have its first verb arrive before this function
72
+ // resumes. `verbsStream` is a plain EventEmitter, so a verb emitted while no
73
+ // listener is attached is discarded silently — the application then waits forever
74
+ // for a response that will never come, and the call hangs with the caller
75
+ // connected and hearing nothing.
72
76
  vc.on(common_1.StreamContent.ANSWER_REQUEST, (0, handlers_1.createAnswerHandler)(ari, vc).bind(this));
73
77
  vc.on(common_1.StreamContent.HANGUP_REQUEST, (0, handlers_1.createHangupHandler)(ari, vc).bind(this));
74
78
  vc.on(common_1.StreamContent.MUTE_REQUEST, (0, handlers_1.createMuteHandler)(ari, vc).bind(this));
@@ -85,6 +89,9 @@ class VoiceDispatcher {
85
89
  vc.stopStreamGather();
86
90
  });
87
91
  vc.on(common_1.StreamContent.START_STREAM_REQUEST, (0, handlers_1.createStreamHandler)(vc).bind(this));
92
+ // Connect to voice server (must await to ensure speechHandler is initialized)
93
+ yield vc.connect();
94
+ voiceClients.set(channel.id, vc);
88
95
  }
89
96
  catch (err) {
90
97
  logger.error("error handling stasis start", { error: err.message });
@@ -71,8 +71,6 @@ class VoiceClientImpl {
71
71
  if (!isAuthorized) {
72
72
  return;
73
73
  }
74
- // Set up GRPC client
75
- yield this.grpcHandler.setupGrpcClient();
76
74
  // Set up audio socket and external media
77
75
  const externalMediaPort = yield (0, pick_port_1.pickPort)({ type: "tcp" });
78
76
  logger.verbose("picked external media port", { port: externalMediaPort });
@@ -92,6 +90,13 @@ class VoiceClientImpl {
92
90
  audioStream: this.audioSocketHandler.getAudioStream(),
93
91
  mediaSessionRef: this.config.mediaSessionRef
94
92
  });
93
+ // Set up the GRPC client LAST. Opening the session immediately writes the request
94
+ // that starts the voice application, so nothing it may depend on can still be
95
+ // pending when that happens — the Say handler needs the speech handler built just
96
+ // above, and the caller attaches the verb listeners before calling connect (see
97
+ // VoiceDispatcher.handleStasisStart). Doing this first let a fast application's
98
+ // opening verbs arrive before the client could serve them.
99
+ yield this.grpcHandler.setupGrpcClient();
95
100
  logger.verbose("voice client setup completed");
96
101
  });
97
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/apiserver",
3
- "version": "0.22.7",
3
+ "version": "0.22.10",
4
4
  "description": "APIServer 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
  "dependencies": {
24
24
  "@deepgram/sdk": "^3.5.1",
25
25
  "@fonoster/authz": "^0.22.7",
26
- "@fonoster/autopilot": "^0.22.7",
26
+ "@fonoster/autopilot": "^0.22.10",
27
27
  "@fonoster/common": "^0.22.3",
28
28
  "@fonoster/identity": "^0.22.7",
29
29
  "@fonoster/logger": "^0.22.0",
@@ -76,5 +76,5 @@
76
76
  "@types/uuid": "^10.0.0",
77
77
  "@types/validator": "^13.15.10"
78
78
  },
79
- "gitHead": "af2404e51a423e45e59515282495ecdec27e0eed"
79
+ "gitHead": "a222992b88756fcfe60c2e05bf2bc9a19f65f19d"
80
80
  }