@memberjunction/telephony-adapters 6.2.0-edge.2 → 6.2.0-edge.4

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.
Files changed (161) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +10 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/resolvers/LiveKitSipResolver.d.ts +21 -0
  6. package/dist/resolvers/LiveKitSipResolver.d.ts.map +1 -0
  7. package/dist/resolvers/LiveKitSipResolver.js +87 -0
  8. package/dist/resolvers/LiveKitSipResolver.js.map +1 -0
  9. package/dist/resolvers/RingCentralTelephonyResolver.d.ts.map +1 -1
  10. package/dist/resolvers/RingCentralTelephonyResolver.js +4 -1
  11. package/dist/resolvers/RingCentralTelephonyResolver.js.map +1 -1
  12. package/dist/resolvers/TelephonyResolver.d.ts.map +1 -1
  13. package/dist/resolvers/TelephonyResolver.js +4 -1
  14. package/dist/resolvers/TelephonyResolver.js.map +1 -1
  15. package/dist/resolvers/VonageTelephonyResolver.d.ts.map +1 -1
  16. package/dist/resolvers/VonageTelephonyResolver.js +4 -1
  17. package/dist/resolvers/VonageTelephonyResolver.js.map +1 -1
  18. package/dist/resolvers/index.d.ts +1 -0
  19. package/dist/resolvers/index.d.ts.map +1 -1
  20. package/dist/resolvers/index.js +1 -0
  21. package/dist/resolvers/index.js.map +1 -1
  22. package/dist/server-extensions/LiveKitSipExtension.d.ts +14 -0
  23. package/dist/server-extensions/LiveKitSipExtension.d.ts.map +1 -0
  24. package/dist/server-extensions/LiveKitSipExtension.js +93 -0
  25. package/dist/server-extensions/LiveKitSipExtension.js.map +1 -0
  26. package/dist/server-extensions/RingCentralTelephonyExtension.d.ts.map +1 -1
  27. package/dist/server-extensions/RingCentralTelephonyExtension.js +8 -2
  28. package/dist/server-extensions/RingCentralTelephonyExtension.js.map +1 -1
  29. package/dist/server-extensions/TwilioTelephonyExtension.d.ts.map +1 -1
  30. package/dist/server-extensions/TwilioTelephonyExtension.js +10 -4
  31. package/dist/server-extensions/TwilioTelephonyExtension.js.map +1 -1
  32. package/dist/server-extensions/VonageTelephonyExtension.d.ts.map +1 -1
  33. package/dist/server-extensions/VonageTelephonyExtension.js +8 -4
  34. package/dist/server-extensions/VonageTelephonyExtension.js.map +1 -1
  35. package/dist/telephony/LiveKitSipRouter.d.ts +26 -0
  36. package/dist/telephony/LiveKitSipRouter.d.ts.map +1 -0
  37. package/dist/telephony/LiveKitSipRouter.js +62 -0
  38. package/dist/telephony/LiveKitSipRouter.js.map +1 -0
  39. package/dist/telephony/LiveKitSipTelephonyService.d.ts +140 -0
  40. package/dist/telephony/LiveKitSipTelephonyService.d.ts.map +1 -0
  41. package/dist/telephony/LiveKitSipTelephonyService.js +501 -0
  42. package/dist/telephony/LiveKitSipTelephonyService.js.map +1 -0
  43. package/dist/telephony/RingCentralTelephonyService.d.ts +57 -8
  44. package/dist/telephony/RingCentralTelephonyService.d.ts.map +1 -1
  45. package/dist/telephony/RingCentralTelephonyService.js +137 -77
  46. package/dist/telephony/RingCentralTelephonyService.js.map +1 -1
  47. package/dist/telephony/TeamsMeetingsService.d.ts +5 -2
  48. package/dist/telephony/TeamsMeetingsService.d.ts.map +1 -1
  49. package/dist/telephony/TeamsMeetingsService.js +9 -2
  50. package/dist/telephony/TeamsMeetingsService.js.map +1 -1
  51. package/dist/telephony/TwilioTelephonyRouter.d.ts +36 -6
  52. package/dist/telephony/TwilioTelephonyRouter.d.ts.map +1 -1
  53. package/dist/telephony/TwilioTelephonyRouter.js +150 -54
  54. package/dist/telephony/TwilioTelephonyRouter.js.map +1 -1
  55. package/dist/telephony/TwilioTelephonyService.d.ts +64 -16
  56. package/dist/telephony/TwilioTelephonyService.d.ts.map +1 -1
  57. package/dist/telephony/TwilioTelephonyService.js +151 -77
  58. package/dist/telephony/TwilioTelephonyService.js.map +1 -1
  59. package/dist/telephony/VonageTelephonyRouter.d.ts +29 -1
  60. package/dist/telephony/VonageTelephonyRouter.d.ts.map +1 -1
  61. package/dist/telephony/VonageTelephonyRouter.js +84 -72
  62. package/dist/telephony/VonageTelephonyRouter.js.map +1 -1
  63. package/dist/telephony/VonageTelephonyService.d.ts +66 -8
  64. package/dist/telephony/VonageTelephonyService.d.ts.map +1 -1
  65. package/dist/telephony/VonageTelephonyService.js +152 -67
  66. package/dist/telephony/VonageTelephonyService.js.map +1 -1
  67. package/dist/telephony/agentIdentityLookup.d.ts +30 -0
  68. package/dist/telephony/agentIdentityLookup.d.ts.map +1 -0
  69. package/dist/telephony/agentIdentityLookup.js +129 -0
  70. package/dist/telephony/agentIdentityLookup.js.map +1 -0
  71. package/dist/telephony/callEndObserver.d.ts +47 -0
  72. package/dist/telephony/callEndObserver.d.ts.map +1 -0
  73. package/dist/telephony/callEndObserver.js +95 -0
  74. package/dist/telephony/callEndObserver.js.map +1 -0
  75. package/dist/telephony/callLifecycleTracker.d.ts +83 -0
  76. package/dist/telephony/callLifecycleTracker.d.ts.map +1 -0
  77. package/dist/telephony/callLifecycleTracker.js +155 -0
  78. package/dist/telephony/callLifecycleTracker.js.map +1 -0
  79. package/dist/telephony/callerIdentity.d.ts +65 -0
  80. package/dist/telephony/callerIdentity.d.ts.map +1 -0
  81. package/dist/telephony/callerIdentity.js +72 -0
  82. package/dist/telephony/callerIdentity.js.map +1 -0
  83. package/dist/telephony/handoffDestinations.d.ts +57 -0
  84. package/dist/telephony/handoffDestinations.d.ts.map +1 -0
  85. package/dist/telephony/handoffDestinations.js +78 -0
  86. package/dist/telephony/handoffDestinations.js.map +1 -0
  87. package/dist/telephony/index.d.ts +21 -0
  88. package/dist/telephony/index.d.ts.map +1 -1
  89. package/dist/telephony/index.js +23 -0
  90. package/dist/telephony/index.js.map +1 -1
  91. package/dist/telephony/interactionLifecycle.d.ts +101 -0
  92. package/dist/telephony/interactionLifecycle.d.ts.map +1 -0
  93. package/dist/telephony/interactionLifecycle.js +340 -0
  94. package/dist/telephony/interactionLifecycle.js.map +1 -0
  95. package/dist/telephony/livekit-sip-runtime.d.ts +55 -0
  96. package/dist/telephony/livekit-sip-runtime.d.ts.map +1 -0
  97. package/dist/telephony/livekit-sip-runtime.js +36 -0
  98. package/dist/telephony/livekit-sip-runtime.js.map +1 -0
  99. package/dist/telephony/mediaSocketAuth.d.ts +77 -0
  100. package/dist/telephony/mediaSocketAuth.d.ts.map +1 -0
  101. package/dist/telephony/mediaSocketAuth.js +136 -0
  102. package/dist/telephony/mediaSocketAuth.js.map +1 -0
  103. package/dist/telephony/numberPoolSelector.d.ts +62 -0
  104. package/dist/telephony/numberPoolSelector.d.ts.map +1 -0
  105. package/dist/telephony/numberPoolSelector.js +201 -0
  106. package/dist/telephony/numberPoolSelector.js.map +1 -0
  107. package/dist/telephony/outboundCallPolicy.d.ts +226 -0
  108. package/dist/telephony/outboundCallPolicy.d.ts.map +1 -0
  109. package/dist/telephony/outboundCallPolicy.js +364 -0
  110. package/dist/telephony/outboundCallPolicy.js.map +1 -0
  111. package/dist/telephony/roomCallSession.d.ts +136 -0
  112. package/dist/telephony/roomCallSession.d.ts.map +1 -0
  113. package/dist/telephony/roomCallSession.js +361 -0
  114. package/dist/telephony/roomCallSession.js.map +1 -0
  115. package/dist/telephony/roomCallTools.d.ts +99 -0
  116. package/dist/telephony/roomCallTools.d.ts.map +1 -0
  117. package/dist/telephony/roomCallTools.js +255 -0
  118. package/dist/telephony/roomCallTools.js.map +1 -0
  119. package/dist/telephony/runAsIdentity.d.ts +62 -0
  120. package/dist/telephony/runAsIdentity.d.ts.map +1 -0
  121. package/dist/telephony/runAsIdentity.js +89 -0
  122. package/dist/telephony/runAsIdentity.js.map +1 -0
  123. package/dist/telephony/sipTrunkCarrier.d.ts +100 -0
  124. package/dist/telephony/sipTrunkCarrier.d.ts.map +1 -0
  125. package/dist/telephony/sipTrunkCarrier.js +118 -0
  126. package/dist/telephony/sipTrunkCarrier.js.map +1 -0
  127. package/dist/telephony/teamsAcsMediaRegistry.d.ts.map +1 -1
  128. package/dist/telephony/teamsAcsMediaRegistry.js +3 -2
  129. package/dist/telephony/teamsAcsMediaRegistry.js.map +1 -1
  130. package/dist/telephony/telephonyCallSession.d.ts +135 -0
  131. package/dist/telephony/telephonyCallSession.d.ts.map +1 -0
  132. package/dist/telephony/telephonyCallSession.js +331 -0
  133. package/dist/telephony/telephonyCallSession.js.map +1 -0
  134. package/dist/telephony/telephonyCallTools.d.ts +112 -0
  135. package/dist/telephony/telephonyCallTools.d.ts.map +1 -0
  136. package/dist/telephony/telephonyCallTools.js +269 -0
  137. package/dist/telephony/telephonyCallTools.js.map +1 -0
  138. package/dist/telephony/telephonyCapacity.d.ts +63 -0
  139. package/dist/telephony/telephonyCapacity.d.ts.map +1 -0
  140. package/dist/telephony/telephonyCapacity.js +94 -0
  141. package/dist/telephony/telephonyCapacity.js.map +1 -0
  142. package/dist/telephony/telephonySettings.d.ts +40 -0
  143. package/dist/telephony/telephonySettings.d.ts.map +1 -0
  144. package/dist/telephony/telephonySettings.js +69 -0
  145. package/dist/telephony/telephonySettings.js.map +1 -0
  146. package/dist/telephony/twilioMediaRegistry.d.ts +83 -11
  147. package/dist/telephony/twilioMediaRegistry.d.ts.map +1 -1
  148. package/dist/telephony/twilioMediaRegistry.js +145 -22
  149. package/dist/telephony/twilioMediaRegistry.js.map +1 -1
  150. package/dist/telephony/vonageMediaRegistry.d.ts +96 -2
  151. package/dist/telephony/vonageMediaRegistry.d.ts.map +1 -1
  152. package/dist/telephony/vonageMediaRegistry.js +227 -26
  153. package/dist/telephony/vonageMediaRegistry.js.map +1 -1
  154. package/dist/telephony/webhookParams.d.ts +21 -0
  155. package/dist/telephony/webhookParams.d.ts.map +1 -0
  156. package/dist/telephony/webhookParams.js +45 -0
  157. package/dist/telephony/webhookParams.js.map +1 -0
  158. package/dist/types.d.ts +90 -7
  159. package/dist/types.d.ts.map +1 -1
  160. package/dist/types.js.map +1 -1
  161. package/package.json +16 -13
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonySettings.d.ts","sourceRoot":"","sources":["../../src/telephony/telephonySettings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,CAAC,uBAAuB,CAAC,GAAG,SAAS,GAAG,uBAAuB,CAStH;AAED,4GAA4G;AAC5G,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,CAEzE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAI3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAOtD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMzD"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @fileoverview Normalizes the settings every carrier extension shares (run-as user, call cap, outbound
3
+ * policy) and the carrier-specific URL / machine-detection defaults the extensions derive.
4
+ *
5
+ * The host merges `telephony.{inboundRunAsUserEmail,maxCallSeconds,outbound}` into each carrier's extension
6
+ * settings, and an operator configuring `serverExtensions` directly supplies them the same way — so both
7
+ * paths arrive here as a loosely typed settings bag.
8
+ *
9
+ * @module @memberjunction/telephony-adapters
10
+ */
11
+ import { LogError } from '@memberjunction/core';
12
+ /**
13
+ * Picks the shared settings out of an extension's raw settings bag. Anything not set stays `undefined` so the
14
+ * consuming service applies its own default (and, for the run-as user, refuses inbound calls).
15
+ */
16
+ export function ReadSharedTelephonySettings(raw) {
17
+ return {
18
+ inboundRunAsUserEmail: raw?.inboundRunAsUserEmail,
19
+ maxCallSeconds: raw?.maxCallSeconds,
20
+ maxConcurrentCalls: raw?.maxConcurrentCalls,
21
+ outbound: raw?.outbound,
22
+ transferTargets: raw?.transferTargets,
23
+ costPerMinute: raw?.costPerMinute,
24
+ };
25
+ }
26
+ /** Maps a raw `onMachine` value to its action, defaulting (and treating anything unknown) to `'hangup'`. */
27
+ export function ResolveOnMachine(raw) {
28
+ return raw === 'continue' ? 'continue' : 'hangup';
29
+ }
30
+ /**
31
+ * Joins the public base URL, the extension's mount path and a route into the absolute URL a carrier should
32
+ * call back (e.g. `https://api.example.com` + `/telephony/twilio` + `/status`).
33
+ */
34
+ export function BuildCallbackUrl(publicUrl, rootPath, route) {
35
+ const base = PublicOrigin(publicUrl);
36
+ const mount = rootPath.startsWith('/') ? rootPath : `/${rootPath}`;
37
+ return `${base}${TrimTrailingSlashes(mount)}${route}`;
38
+ }
39
+ /**
40
+ * The scheme + host (+ port) of the host's public URL, with any path dropped.
41
+ *
42
+ * The host's public URL is typically the GraphQL endpoint (`https://api.example.com/graphql`), but extension
43
+ * routes are mounted at the application root, so the URL a carrier calls — and signs — is the ORIGIN plus the
44
+ * route's own path. Appending the route to the full public URL double-counts the GraphQL path
45
+ * (`/graphql/telephony/twilio/voice`), which breaks both the callback URLs we hand the carrier and the
46
+ * signature check. An unparseable value falls back to a trailing-slash trim so a misconfiguration surfaces as
47
+ * a plainly wrong URL rather than an exception on the request path.
48
+ */
49
+ export function PublicOrigin(publicUrl) {
50
+ try {
51
+ return new URL(publicUrl).origin;
52
+ }
53
+ catch (err) {
54
+ LogError(`[Telephony] Invalid publicUrl passed to PublicOrigin: ${publicUrl}`, undefined, err);
55
+ return TrimTrailingSlashes(publicUrl);
56
+ }
57
+ }
58
+ /**
59
+ * Removes every trailing `/` from a string in a single linear scan. Used on operator- and request-supplied
60
+ * URLs instead of a `/\/+$/` regex, whose backtracking is polynomial on inputs with many slashes.
61
+ */
62
+ export function TrimTrailingSlashes(value) {
63
+ let end = value.length;
64
+ while (end > 0 && value.charCodeAt(end - 1) === 47 /* '/' */) {
65
+ end--;
66
+ }
67
+ return value.slice(0, end);
68
+ }
69
+ //# sourceMappingURL=telephonySettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telephonySettings.js","sourceRoot":"","sources":["../../src/telephony/telephonySettings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAGhD;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,GAAiD;IACzF,OAAO;QACH,qBAAqB,EAAE,GAAG,EAAE,qBAAqB;QACjD,cAAc,EAAE,GAAG,EAAE,cAAc;QACnC,kBAAkB,EAAE,GAAG,EAAE,kBAAkB;QAC3C,QAAQ,EAAE,GAAG,EAAE,QAAQ;QACvB,eAAe,EAAE,GAAG,EAAE,eAAe;QACrC,aAAa,EAAE,GAAG,EAAE,aAAa;KACpC,CAAC;AACN,CAAC;AAED,4GAA4G;AAC5G,MAAM,UAAU,gBAAgB,CAAC,GAAuB;IACpD,OAAO,GAAG,KAAK,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAiB,EAAE,QAAgB,EAAE,KAAa;IAC/E,MAAM,IAAI,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC;IACnE,OAAO,GAAG,IAAI,GAAG,mBAAmB,CAAC,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC;AAC1D,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC1C,IAAI,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC;IACrC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACX,QAAQ,CAAC,yDAAyD,SAAS,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;QAC/F,OAAO,mBAAmB,CAAC,SAAS,CAAC,CAAC;IAC1C,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC7C,IAAI,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACvB,OAAO,GAAG,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,SAAS,EAAE,CAAC;QAC3D,GAAG,EAAE,CAAC;IACV,CAAC;IACD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC"}
@@ -7,17 +7,27 @@
7
7
  * when an INBOUND call's webhook fires, the bridge session starts and `RealTwilioBindings` registers
8
8
  * its inbound-audio handler — but Twilio has not yet opened the media websocket (it does so only AFTER
9
9
  * the webhook's `<Connect><Stream>` TwiML response). The registry bridges that gap by buffering
10
- * handler registrations + outbound frames per Call SID and binding them to the socket once it connects
11
- * (matched on the `start` frame's Call SID).
10
+ * handler registrations + outbound frames per Call SID and binding them to the socket once it connects.
11
+ *
12
+ * **Authentication.** A socket attaches only to a call MJ itself registered ({@link ExpectCall}) and only
13
+ * with that call's secret token (see {@link ExpectedCallStore}). It never replaces an already-attached
14
+ * socket and never creates state for a call MJ did not register.
15
+ *
16
+ * **Buffering, in both directions, is bounded.**
17
+ * - Outbound frames the agent produces before the socket connects are held (capped) and flushed on attach,
18
+ * re-addressed to the real `streamSid` (they were encoded before it was known).
19
+ * - Inbound frames that arrive before the bridge session has registered its handlers (the webhook now
20
+ * answers before the session finishes starting) are held (capped) and replayed to each handler as it
21
+ * registers.
12
22
  *
13
23
  * Pure + unit-testable: the websocket is injected as the minimal {@link ITelephonyMediaSocket} surface,
14
- * so the registry's buffering / dispatch / stream-SID capture logic is exercised with a fake socket and
15
- * no `ws` install or network.
24
+ * so the registry's logic is exercised with a fake socket and no `ws` install or network.
16
25
  *
17
26
  * @module @memberjunction/telephony-adapters
18
27
  */
19
28
  import type { TwilioMediaFrame } from '@memberjunction/ai-bridge-twilio';
20
29
  import type { ITwilioMediaPump } from '@memberjunction/ai-bridge-twilio';
30
+ import { type SocketAuthResult } from './mediaSocketAuth.js';
21
31
  /**
22
32
  * The minimal websocket surface the registry drives — a structural subset of a `ws` socket, so the
23
33
  * registry never imports `ws` and is testable with a fake. Outbound frames are sent as JSON strings.
@@ -28,6 +38,15 @@ export interface ITelephonyMediaSocket {
28
38
  /** Closes the socket (best-effort; called on call end). */
29
39
  close(): void;
30
40
  }
41
+ /** Tunables for {@link TwilioCallMediaRegistry} (defaults are sized for 20 ms Media-Streams frames). */
42
+ export interface TwilioMediaRegistryOptions {
43
+ /** Max outbound frames held before the socket connects (default 500 ≈ 10 s of 20 ms frames). */
44
+ MaxOutboundBufferFrames?: number;
45
+ /** Max inbound frames held before the bridge registers its handlers (default 250 ≈ 5 s of 20 ms frames). */
46
+ MaxEarlyInboundFrames?: number;
47
+ /** How long an expected call may wait for its socket (default {@link DEFAULT_EXPECTATION_TTL_MS}). */
48
+ ExpectationTtlMs?: number;
49
+ }
31
50
  /**
32
51
  * Coordinates Media-Streams sockets with the bridge bindings, keyed by Call SID. One instance per
33
52
  * server, shared between the inbound-webhook service (which binds `RealTwilioBindings` over this as the
@@ -35,26 +54,79 @@ export interface ITelephonyMediaSocket {
35
54
  */
36
55
  export declare class TwilioCallMediaRegistry implements ITwilioMediaPump {
37
56
  private readonly channels;
57
+ private readonly expected;
58
+ private readonly maxOutboundBufferFrames;
59
+ private readonly maxEarlyInboundFrames;
60
+ private connectTimeoutListener?;
61
+ private callRegisteredListener?;
62
+ constructor(options?: TwilioMediaRegistryOptions);
38
63
  /** Ensures a channel exists for a call (called when a bridge session for the call starts). */
39
64
  RegisterCall(callSid: string): void;
40
- /** @inheritdoc — buffers when the socket has not yet connected; sends immediately once it has. Flushes buffer on 'clear'. */
65
+ /**
66
+ * Registers a call MJ accepted or placed, together with the secret token its media socket must present.
67
+ * Creates the call's channel so frames and handlers can be staged before the socket connects.
68
+ *
69
+ * @param callSid The Twilio Call SID.
70
+ * @param token The per-call secret (also embedded in the TwiML `<Parameter name="mjToken">`).
71
+ * @param ttlMs Optional override of how long to wait for the socket.
72
+ */
73
+ ExpectCall(callSid: string, token: string, ttlMs?: number): void;
74
+ /**
75
+ * Registers the listener told the moment a call becomes known to MJ ({@link ExpectCall}) — for an outbound
76
+ * call that is the instant the carrier REST response yields the Call SID, which is earlier than the bridge
77
+ * session finishing its start. One listener; the latest wins.
78
+ */
79
+ OnCallRegistered(listener: (callSid: string) => void): void;
80
+ /**
81
+ * Registers the listener told when a call's media socket never connected within its TTL — the call has
82
+ * been dropped from the registry and the owner should end the session. One listener; the latest wins.
83
+ */
84
+ OnConnectTimeout(listener: (callSid: string) => void): void;
85
+ /**
86
+ * @inheritdoc — buffers (bounded) when the socket has not yet connected; sends immediately once it has.
87
+ * Discards the buffer on 'clear'.
88
+ */
41
89
  Send(callSid: string, frame: TwilioMediaFrame): void;
42
- /** @inheritdoc — stores the handler so frames delivered before AND after socket connect reach it. */
90
+ /**
91
+ * @inheritdoc — stores the handler so frames delivered before AND after socket connect reach it, and
92
+ * replays any inbound frames that arrived before the first handler registered.
93
+ */
43
94
  OnFrame(callSid: string, handler: (frame: TwilioMediaFrame) => void): void;
44
95
  /** @inheritdoc — the captured stream SID, or `''` until the `start` frame arrives. */
45
96
  GetStreamSid(callSid: string): string;
46
97
  /**
47
- * Binds a connected Media-Streams socket (and its captured stream SID) to a call, flushing any
48
- * outbound frames produced while the socket was still connecting. Called by the WSS server on the
49
- * `start` frame.
98
+ * Authenticates and binds a connected Media-Streams socket (and its captured stream SID) to a call,
99
+ * flushing any outbound frames produced while the socket was still connecting. Called by the WSS server
100
+ * on the `start` frame. A refused socket is NOT attached and changes no state; the caller closes it.
101
+ *
102
+ * @param callSid The Call SID claimed by the `start` frame.
103
+ * @param token The `mjToken` custom parameter from the `start` frame (absent ⇒ refused).
104
+ * @param socket The connected socket.
105
+ * @param streamSid The stream SID from the `start` frame.
106
+ * @returns `{Ok:true}`, or why the socket was refused (`unknown-call` | `bad-token` | `already-attached`).
50
107
  */
51
- AttachSocket(callSid: string, socket: ITelephonyMediaSocket, streamSid: string): void;
52
- /** Dispatches one inbound Media-Streams frame to all registered handlers for the call. */
108
+ TryAttachSocket(callSid: string, token: string | undefined, socket: ITelephonyMediaSocket, streamSid: string): SocketAuthResult;
109
+ /** Dispatches one inbound Media-Streams frame to all registered handlers for the call (or buffers it early). */
53
110
  DispatchInbound(callSid: string, frame: TwilioMediaFrame): void;
54
111
  /** Tears down a call's channel and closes its socket (called on socket close / call end). */
55
112
  EndCall(callSid: string): void;
56
113
  /** Whether a channel is currently tracked for the call (test/observability helper). */
57
114
  HasCall(callSid: string): boolean;
115
+ /** Whether MJ is still waiting for (or has already authenticated) a socket for the call. */
116
+ IsExpected(callSid: string): boolean;
117
+ /** Cancels every outstanding connect timer (server shutdown). */
118
+ Dispose(): void;
119
+ /** Connect TTL elapsed with no socket: free the channel, then tell the owner so it can end the session. */
120
+ private handleConnectTimeout;
121
+ /** Adds an outbound frame to the pre-attach buffer, dropping the oldest (and warning once) at the cap. */
122
+ private bufferOutbound;
123
+ /** Adds an inbound frame to the pre-handler buffer, dropping the oldest (and warning once) at the cap. */
124
+ private bufferEarlyInbound;
125
+ /**
126
+ * Sends the frames the agent produced before the socket existed. They were encoded when `GetStreamSid`
127
+ * still returned `''`, which Twilio rejects — so each is re-addressed to the real stream SID first.
128
+ */
129
+ private flushOutbound;
58
130
  private ensureChannel;
59
131
  }
60
132
  //# sourceMappingURL=twilioMediaRegistry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"twilioMediaRegistry.d.ts","sourceRoot":"","sources":["../../src/telephony/twilioMediaRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EA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AG,IAAI;IAMlE;;;OAGG;IACI,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAY3D;;;OAGG;IACI,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,IAAI;IAQjF,sFAAsF;IAC/E,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAM5C;;;;;;;;;;OAUG;IACI,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,qBAAqB,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB;IAatI,gHAAgH;IACzG,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAiBtE,6FAA6F;IACtF,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAcrC,uFAAuF;IAChF,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAIxC,4FAA4F;IACrF,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAI3C,iEAAiE;IAC1D,OAAO,IAAI,IAAI;IAMtB,2GAA2G;IAC3G,OAAO,CAAC,oBAAoB;IAM5B,0GAA0G;IAC1G,OAAO,CAAC,cAAc;IAWtB,0GAA0G;IAC1G,OAAO,CAAC,kBAAkB;IAW1B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,aAAa;CAcxB"}
@@ -7,30 +7,79 @@
7
7
  * when an INBOUND call's webhook fires, the bridge session starts and `RealTwilioBindings` registers
8
8
  * its inbound-audio handler — but Twilio has not yet opened the media websocket (it does so only AFTER
9
9
  * the webhook's `<Connect><Stream>` TwiML response). The registry bridges that gap by buffering
10
- * handler registrations + outbound frames per Call SID and binding them to the socket once it connects
11
- * (matched on the `start` frame's Call SID).
10
+ * handler registrations + outbound frames per Call SID and binding them to the socket once it connects.
11
+ *
12
+ * **Authentication.** A socket attaches only to a call MJ itself registered ({@link ExpectCall}) and only
13
+ * with that call's secret token (see {@link ExpectedCallStore}). It never replaces an already-attached
14
+ * socket and never creates state for a call MJ did not register.
15
+ *
16
+ * **Buffering, in both directions, is bounded.**
17
+ * - Outbound frames the agent produces before the socket connects are held (capped) and flushed on attach,
18
+ * re-addressed to the real `streamSid` (they were encoded before it was known).
19
+ * - Inbound frames that arrive before the bridge session has registered its handlers (the webhook now
20
+ * answers before the session finishes starting) are held (capped) and replayed to each handler as it
21
+ * registers.
12
22
  *
13
23
  * Pure + unit-testable: the websocket is injected as the minimal {@link ITelephonyMediaSocket} surface,
14
- * so the registry's buffering / dispatch / stream-SID capture logic is exercised with a fake socket and
15
- * no `ws` install or network.
24
+ * so the registry's logic is exercised with a fake socket and no `ws` install or network.
16
25
  *
17
26
  * @module @memberjunction/telephony-adapters
18
27
  */
28
+ import { LogError, LogStatus } from '@memberjunction/core';
29
+ import { ExpectedCallStore } from './mediaSocketAuth.js';
30
+ /** Default outbound pre-attach cap: 10 s of 20 ms frames. */
31
+ const DEFAULT_MAX_OUTBOUND_BUFFER_FRAMES = 500;
32
+ /** Default inbound pre-handler cap: 5 s of 20 ms frames. */
33
+ const DEFAULT_MAX_EARLY_INBOUND_FRAMES = 250;
19
34
  /**
20
35
  * Coordinates Media-Streams sockets with the bridge bindings, keyed by Call SID. One instance per
21
36
  * server, shared between the inbound-webhook service (which binds `RealTwilioBindings` over this as the
22
37
  * `ITwilioMediaPump`) and the WSS server (which attaches sockets + dispatches inbound frames).
23
38
  */
24
39
  export class TwilioCallMediaRegistry {
25
- constructor() {
40
+ constructor(options = {}) {
26
41
  this.channels = new Map();
42
+ this.maxOutboundBufferFrames = options.MaxOutboundBufferFrames ?? DEFAULT_MAX_OUTBOUND_BUFFER_FRAMES;
43
+ this.maxEarlyInboundFrames = options.MaxEarlyInboundFrames ?? DEFAULT_MAX_EARLY_INBOUND_FRAMES;
44
+ this.expected = new ExpectedCallStore((callSid) => this.handleConnectTimeout(callSid), options.ExpectationTtlMs);
27
45
  }
28
46
  /** Ensures a channel exists for a call (called when a bridge session for the call starts). */
29
47
  RegisterCall(callSid) {
30
48
  this.ensureChannel(callSid);
31
49
  }
50
+ /**
51
+ * Registers a call MJ accepted or placed, together with the secret token its media socket must present.
52
+ * Creates the call's channel so frames and handlers can be staged before the socket connects.
53
+ *
54
+ * @param callSid The Twilio Call SID.
55
+ * @param token The per-call secret (also embedded in the TwiML `<Parameter name="mjToken">`).
56
+ * @param ttlMs Optional override of how long to wait for the socket.
57
+ */
58
+ ExpectCall(callSid, token, ttlMs) {
59
+ this.ensureChannel(callSid);
60
+ this.expected.Expect(callSid, token, ttlMs);
61
+ this.callRegisteredListener?.(callSid);
62
+ }
63
+ /**
64
+ * Registers the listener told the moment a call becomes known to MJ ({@link ExpectCall}) — for an outbound
65
+ * call that is the instant the carrier REST response yields the Call SID, which is earlier than the bridge
66
+ * session finishing its start. One listener; the latest wins.
67
+ */
68
+ OnCallRegistered(listener) {
69
+ this.callRegisteredListener = listener;
70
+ }
71
+ /**
72
+ * Registers the listener told when a call's media socket never connected within its TTL — the call has
73
+ * been dropped from the registry and the owner should end the session. One listener; the latest wins.
74
+ */
75
+ OnConnectTimeout(listener) {
76
+ this.connectTimeoutListener = listener;
77
+ }
32
78
  // ── ITwilioMediaPump ─────────────────────────────────────────────────────────
33
- /** @inheritdoc — buffers when the socket has not yet connected; sends immediately once it has. Flushes buffer on 'clear'. */
79
+ /**
80
+ * @inheritdoc — buffers (bounded) when the socket has not yet connected; sends immediately once it has.
81
+ * Discards the buffer on 'clear'.
82
+ */
34
83
  Send(callSid, frame) {
35
84
  const channel = this.ensureChannel(callSid);
36
85
  if (frame.event === 'clear') {
@@ -40,12 +89,19 @@ export class TwilioCallMediaRegistry {
40
89
  channel.socket.send(JSON.stringify(frame));
41
90
  }
42
91
  else if (frame.event !== 'clear') {
43
- channel.outboundBuffer.push(frame);
92
+ this.bufferOutbound(callSid, channel, frame);
44
93
  }
45
94
  }
46
- /** @inheritdoc — stores the handler so frames delivered before AND after socket connect reach it. */
95
+ /**
96
+ * @inheritdoc — stores the handler so frames delivered before AND after socket connect reach it, and
97
+ * replays any inbound frames that arrived before the first handler registered.
98
+ */
47
99
  OnFrame(callSid, handler) {
48
- this.ensureChannel(callSid).frameHandlers.push(handler);
100
+ const channel = this.ensureChannel(callSid);
101
+ channel.frameHandlers.push(handler);
102
+ for (const frame of channel.earlyInbound) {
103
+ handler(frame);
104
+ }
49
105
  }
50
106
  /** @inheritdoc — the captured stream SID, or `''` until the `start` frame arrives. */
51
107
  GetStreamSid(callSid) {
@@ -53,20 +109,29 @@ export class TwilioCallMediaRegistry {
53
109
  }
54
110
  // ── WSS-server side ─────────────────────────────────────────────────────────
55
111
  /**
56
- * Binds a connected Media-Streams socket (and its captured stream SID) to a call, flushing any
57
- * outbound frames produced while the socket was still connecting. Called by the WSS server on the
58
- * `start` frame.
112
+ * Authenticates and binds a connected Media-Streams socket (and its captured stream SID) to a call,
113
+ * flushing any outbound frames produced while the socket was still connecting. Called by the WSS server
114
+ * on the `start` frame. A refused socket is NOT attached and changes no state; the caller closes it.
115
+ *
116
+ * @param callSid The Call SID claimed by the `start` frame.
117
+ * @param token The `mjToken` custom parameter from the `start` frame (absent ⇒ refused).
118
+ * @param socket The connected socket.
119
+ * @param streamSid The stream SID from the `start` frame.
120
+ * @returns `{Ok:true}`, or why the socket was refused (`unknown-call` | `bad-token` | `already-attached`).
59
121
  */
60
- AttachSocket(callSid, socket, streamSid) {
61
- const channel = this.ensureChannel(callSid);
122
+ TryAttachSocket(callSid, token, socket, streamSid) {
123
+ const verdict = this.expected.Verify(callSid, token);
124
+ const channel = this.channels.get(callSid);
125
+ if (!verdict.Ok || !channel) {
126
+ return verdict.Ok ? { Ok: false, Reason: 'unknown-call' } : verdict;
127
+ }
128
+ this.expected.MarkAttached(callSid);
62
129
  channel.socket = socket;
63
130
  channel.streamSid = streamSid;
64
- const buffered = channel.outboundBuffer.splice(0, channel.outboundBuffer.length);
65
- for (const frame of buffered) {
66
- socket.send(JSON.stringify(frame));
67
- }
131
+ this.flushOutbound(channel, socket, streamSid);
132
+ return { Ok: true };
68
133
  }
69
- /** Dispatches one inbound Media-Streams frame to all registered handlers for the call. */
134
+ /** Dispatches one inbound Media-Streams frame to all registered handlers for the call (or buffers it early). */
70
135
  DispatchInbound(callSid, frame) {
71
136
  const channel = this.channels.get(callSid);
72
137
  if (!channel) {
@@ -75,12 +140,17 @@ export class TwilioCallMediaRegistry {
75
140
  if (frame.event === 'start' && frame.streamSid) {
76
141
  channel.streamSid = frame.streamSid;
77
142
  }
143
+ if (channel.frameHandlers.length === 0) {
144
+ this.bufferEarlyInbound(callSid, channel, frame);
145
+ return;
146
+ }
78
147
  for (const handler of channel.frameHandlers) {
79
148
  handler(frame);
80
149
  }
81
150
  }
82
151
  /** Tears down a call's channel and closes its socket (called on socket close / call end). */
83
152
  EndCall(callSid) {
153
+ this.expected.Forget(callSid);
84
154
  const channel = this.channels.get(callSid);
85
155
  if (!channel) {
86
156
  return;
@@ -88,8 +158,8 @@ export class TwilioCallMediaRegistry {
88
158
  try {
89
159
  channel.socket?.close();
90
160
  }
91
- catch {
92
- /* best-effort */
161
+ catch (err) {
162
+ LogError(`[TwilioMediaRegistry] Error closing socket for call ${callSid}`, undefined, err);
93
163
  }
94
164
  this.channels.delete(callSid);
95
165
  }
@@ -97,10 +167,63 @@ export class TwilioCallMediaRegistry {
97
167
  HasCall(callSid) {
98
168
  return this.channels.has(callSid);
99
169
  }
170
+ /** Whether MJ is still waiting for (or has already authenticated) a socket for the call. */
171
+ IsExpected(callSid) {
172
+ return this.expected.Has(callSid);
173
+ }
174
+ /** Cancels every outstanding connect timer (server shutdown). */
175
+ Dispose() {
176
+ this.expected.Clear();
177
+ }
178
+ // ── internals ────────────────────────────────────────────────────────────────
179
+ /** Connect TTL elapsed with no socket: free the channel, then tell the owner so it can end the session. */
180
+ handleConnectTimeout(callSid) {
181
+ LogStatus(`[Telephony][Twilio] media socket never connected for call ${callSid}; dropping its channel.`);
182
+ this.EndCall(callSid);
183
+ this.connectTimeoutListener?.(callSid);
184
+ }
185
+ /** Adds an outbound frame to the pre-attach buffer, dropping the oldest (and warning once) at the cap. */
186
+ bufferOutbound(callSid, channel, frame) {
187
+ channel.outboundBuffer.push(frame);
188
+ if (channel.outboundBuffer.length > this.maxOutboundBufferFrames) {
189
+ channel.outboundBuffer.shift();
190
+ if (!channel.outboundOverflowLogged) {
191
+ channel.outboundOverflowLogged = true;
192
+ LogStatus(`[Telephony][Twilio] outbound audio buffer full for call ${callSid} before the media socket connected; dropping oldest frames.`);
193
+ }
194
+ }
195
+ }
196
+ /** Adds an inbound frame to the pre-handler buffer, dropping the oldest (and warning once) at the cap. */
197
+ bufferEarlyInbound(callSid, channel, frame) {
198
+ channel.earlyInbound.push(frame);
199
+ if (channel.earlyInbound.length > this.maxEarlyInboundFrames) {
200
+ channel.earlyInbound.shift();
201
+ if (!channel.inboundOverflowLogged) {
202
+ channel.inboundOverflowLogged = true;
203
+ LogStatus(`[Telephony][Twilio] inbound audio buffer full for call ${callSid} before the bridge session was ready; dropping oldest frames.`);
204
+ }
205
+ }
206
+ }
207
+ /**
208
+ * Sends the frames the agent produced before the socket existed. They were encoded when `GetStreamSid`
209
+ * still returned `''`, which Twilio rejects — so each is re-addressed to the real stream SID first.
210
+ */
211
+ flushOutbound(channel, socket, streamSid) {
212
+ const buffered = channel.outboundBuffer.splice(0, channel.outboundBuffer.length);
213
+ for (const frame of buffered) {
214
+ socket.send(JSON.stringify({ ...frame, streamSid }));
215
+ }
216
+ }
100
217
  ensureChannel(callSid) {
101
218
  let channel = this.channels.get(callSid);
102
219
  if (!channel) {
103
- channel = { frameHandlers: [], outboundBuffer: [] };
220
+ channel = {
221
+ frameHandlers: [],
222
+ outboundBuffer: [],
223
+ earlyInbound: [],
224
+ outboundOverflowLogged: false,
225
+ inboundOverflowLogged: false,
226
+ };
104
227
  this.channels.set(callSid, channel);
105
228
  }
106
229
  return channel;
@@ -1 +1 @@
1
- {"version":3,"file":"twilioMediaRegistry.js","sourceRoot":"","sources":["../../src/telephony/twilioMediaRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AA0BH;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAApC;QACqB,aAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IA0FpE,CAAC;IAxFG,8FAA8F;IACvF,YAAY,CAAC,OAAe;QAC/B,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;IAED,gFAAgF;IAEhF,6HAA6H;IACtH,IAAI,CAAC,OAAe,EAAE,KAAuB;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC5C,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YAC1B,OAAO,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;QAC/C,CAAC;aAAM,IAAI,KAAK,CAAC,KAAK,KAAK,OAAO,EAAE,CAAC;YACjC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvC,CAAC;IACL,CAAC;IAED,qGAAqG;IAC9F,OAAO,CAAC,OAAe,EAAE,OAA0C;QACtE,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC5D,CAAC;IAED,sFAAsF;IAC/E,YAAY,CAAC,OAAe;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;IACvD,CAAC;IAED,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0D,OAAO,+DAA+D,CAAC,CAAC;YAChJ,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;OAGG;IACK,aAAa,CAAC,OAAyB,EAAE,MAA6B,EAAE,SAAiB;QAC7F,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACjF,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAAe;QACjC,IAAI,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,GAAG;gBACN,aAAa,EAAE,EAAE;gBACjB,cAAc,EAAE,EAAE;gBAClB,YAAY,EAAE,EAAE;gBAChB,sBAAsB,EAAE,KAAK;gBAC7B,qBAAqB,EAAE,KAAK;aAC/B,CAAC;YACF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ"}
@@ -1,6 +1,16 @@
1
1
  /**
2
2
  * @fileoverview Per-call WebSocket-media pump registry for the Vonage telephony ingress.
3
3
  *
4
+ * Mirrors the Twilio registry's contract (see `twilioMediaRegistry.ts`): sockets are authenticated against a
5
+ * per-call token MJ registered, never replace an attached socket, never create state for an unregistered
6
+ * call, and both pre-attach / pre-handler buffers are bounded.
7
+ *
8
+ * **Vonage-specific: outbound correlation.** An outbound call's UUID is not known until `createCall`
9
+ * resolves, yet Vonage may open the media websocket before that response is processed. So an outbound call is
10
+ * first registered under a **correlation id** carried in the websocket URI (`mj_cid`); once the UUID is known
11
+ * ({@link BindOutboundCall}) the correlation id becomes an alias of it and the channel — socket, buffers and
12
+ * all — moves under the UUID. Every method accepts either id.
13
+ *
4
14
  * @module @memberjunction/telephony-adapters
5
15
  */
6
16
  import type { VonageControlEvent, IVonageMediaPump } from '@memberjunction/ai-bridge-vonage';
@@ -17,22 +27,106 @@ export interface ITelephonyMediaSocket {
17
27
  /** Closes the socket (best-effort; called on call end). */
18
28
  close(): void;
19
29
  }
30
+ /** Tunables for {@link VonageCallMediaRegistry}. */
31
+ export interface VonageMediaRegistryOptions {
32
+ /** Max outbound 320-byte frames held before the socket connects (default 500 ≈ 10 s). */
33
+ MaxOutboundBufferFrames?: number;
34
+ /** Max inbound audio bytes held before the bridge registers its handlers (default 80 000 ≈ 5 s). */
35
+ MaxEarlyInboundBytes?: number;
36
+ /** How long an expected call may wait for its socket (default {@link DEFAULT_EXPECTATION_TTL_MS}). */
37
+ ExpectationTtlMs?: number;
38
+ }
39
+ /** Which identifier a connecting socket claims: an inbound call UUID, or an outbound correlation id. */
40
+ export interface VonageSocketCallRef {
41
+ /** The `call_uuid` query param (inbound calls). */
42
+ CallUuid?: string;
43
+ /** The `mj_cid` query param (outbound calls). */
44
+ CorrelationId?: string;
45
+ }
46
+ /** The verdict of {@link VonageCallMediaRegistry.TryAttachSocket}. */
47
+ export type VonageAttachResult = {
48
+ Ok: true;
49
+ CallKey: string;
50
+ } | {
51
+ Ok: false;
52
+ Reason: 'unknown-call' | 'bad-token' | 'already-attached';
53
+ };
20
54
  /**
21
- * Coordinates Vonage media websockets with the bridge bindings, keyed by call UUID.
55
+ * Coordinates Vonage media websockets with the bridge bindings, keyed by call UUID (or, for an outbound call
56
+ * whose UUID is not yet known, its correlation id).
22
57
  */
23
58
  export declare class VonageCallMediaRegistry implements IVonageMediaPump {
24
59
  private readonly channels;
60
+ private readonly aliases;
61
+ private readonly expected;
62
+ private readonly maxOutboundBufferFrames;
63
+ private readonly maxEarlyInboundBytes;
64
+ private connectTimeoutListener?;
65
+ private callRegisteredListener?;
66
+ constructor(options?: VonageMediaRegistryOptions);
25
67
  /** Ensures a channel exists for a call (called when a bridge session for the call starts). */
26
68
  RegisterCall(callUuid: string): void;
69
+ /** Registers an INBOUND call MJ accepted, with the token its media socket must present. */
70
+ ExpectCall(callUuid: string, token: string, ttlMs?: number): void;
71
+ /**
72
+ * Registers the listener told the moment a call's UUID becomes known to MJ — {@link ExpectCall} for an
73
+ * inbound call, {@link BindOutboundCall} for an outbound one (the instant `createCall` yields the UUID,
74
+ * which is earlier than the bridge session finishing its start). One listener; the latest wins.
75
+ */
76
+ OnCallRegistered(listener: (callUuid: string) => void): void;
77
+ /** @inheritdoc — registers an OUTBOUND call under its correlation id, before `createCall` is issued. */
78
+ ExpectOutboundCall(correlationId: string, token: string, ttlMs?: number): void;
79
+ /**
80
+ * @inheritdoc — makes the correlation id an alias of the real call UUID and moves the channel (socket,
81
+ * handlers, buffers) under the UUID. Safe whether or not the socket has already connected.
82
+ */
83
+ BindOutboundCall(correlationId: string, callUuid: string): void;
84
+ /** @inheritdoc — `createCall` failed: nothing will ever connect, so drop the expectation and channel. */
85
+ AbandonOutboundCall(correlationId: string): void;
86
+ /**
87
+ * Registers the listener told when a call's media socket never connected within its TTL — the call has
88
+ * been dropped from the registry and the owner should end the session. One listener; the latest wins.
89
+ * The key passed is the call UUID once known, otherwise the correlation id.
90
+ */
91
+ OnConnectTimeout(listener: (callKey: string) => void): void;
92
+ /**
93
+ * Authenticates and binds a connected media socket to a call MJ registered. A refused socket is NOT
94
+ * attached and changes no state; the caller closes it.
95
+ *
96
+ * @param ref The id the socket claims (`call_uuid` for inbound, `mj_cid` for outbound).
97
+ * @param token The `mj_token` query param (absent ⇒ refused).
98
+ * @param socket The connected socket.
99
+ * @returns The channel key to dispatch under (`CallKey`), or why the socket was refused.
100
+ */
101
+ TryAttachSocket(ref: VonageSocketCallRef, token: string | undefined, socket: ITelephonyMediaSocket): VonageAttachResult;
27
102
  SendAudio(callUuid: string, pcm: ArrayBuffer): void;
103
+ /** @inheritdoc — also replays inbound audio that arrived before the first handler registered. */
28
104
  OnAudio(callUuid: string, handler: (pcm: ArrayBuffer) => void): void;
105
+ /** @inheritdoc — also replays control events that arrived before the first handler registered. */
29
106
  OnEvent(callUuid: string, handler: (event: VonageControlEvent) => void): void;
30
107
  Clear(callUuid: string): void;
31
- AttachSocket(callUuid: string, socket: ITelephonyMediaSocket): void;
32
108
  DispatchInboundAudio(callUuid: string, pcm: ArrayBuffer): void;
33
109
  DispatchInboundEvent(callUuid: string, event: VonageControlEvent): void;
34
110
  EndCall(callUuid: string): void;
35
111
  HasCall(callUuid: string): boolean;
112
+ /** Whether MJ is still waiting for (or has already authenticated) a socket for the call. */
113
+ IsExpected(callUuid: string): boolean;
114
+ /** Cancels every outstanding connect timer (server shutdown). */
115
+ Dispose(): void;
116
+ /** Resolves a correlation id to the call UUID it was bound to (identity for anything else). */
117
+ private canon;
118
+ /** Removes every alias that points at the (now ended) call so the table cannot grow without bound. */
119
+ private dropAliasesTo;
120
+ /** Connect TTL elapsed with no socket: free the channel, then tell the owner so it can end the session. */
121
+ private handleConnectTimeout;
122
+ /** Moves a channel from one key to another, merging into an existing destination channel if there is one. */
123
+ private moveChannel;
124
+ /** Adds an outbound frame to the pre-attach buffer, dropping the oldest (and warning once) at the cap. */
125
+ private bufferOutbound;
126
+ /** Adds inbound audio to the pre-handler buffer, dropping the oldest (and warning once) past the byte cap. */
127
+ private bufferEarlyAudio;
128
+ /** Sends the frames the agent produced before the socket existed, oldest first. */
129
+ private flushOutbound;
36
130
  private ensureChannel;
37
131
  }
38
132
  //# sourceMappingURL=vonageMediaRegistry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vonageMediaRegistry.d.ts","sourceRoot":"","sources":["../../src/telephony/vonageMediaRegistry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAE7F;;;;GAI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