UNPKG

@audin.ai/operator-sdk

Version:

Headless browser SDK for the Audin operator softphone — make and receive calls over the Audin operator WebSockets.

41 lines (40 loc) 1.95 kB
/** * `@audin.ai/operator-sdk` — headless browser SDK for the Audin operator * softphone. * * Make and receive phone calls from a browser over the Audin operator * WebSockets. No UI: you build the interface, the SDK handles the microphone, * audio transcoding, the signalling + media channels, reconnection and * heartbeats. Credentials stay on your backend — the SDK obtains short-lived * session tokens through the `getToken` callback you provide. * * @example * ```ts * import { AudinOperator } from "@audin.ai/operator-sdk"; * * const op = new AudinOperator({ * coreUrl: "https://core.audin.ai", * getToken: async () => { * // Call YOUR backend, which holds the account key and proxies to * // POST /operator-sessions/token. Return at least { token }. * const r = await fetch("/api/operator/token", { method: "POST" }); * return r.json(); * }, * }); * * op.on("incomingCall", (call) => call.accept()); * op.on("callStarted", (call) => console.log("on a call", call.callSid)); * op.on("callEnded", (call) => console.log("ended:", call.endReason)); * * const numbers = await op.listPhoneNumbers(); // [{ id, phoneNumber, displayName }] * const mine = numbers[0]; * await op.goOnline([mine.id]); * const call = await op.dial("+39021234567", { callerId: mine.phoneNumber }); * call.mute(true); * call.hangup(); * await op.goOffline(); * ``` */ export { AudinOperator, OperatorRequestError } from "./AudinOperator.js"; export type { AudinOperatorConfig, AudinOperatorEventMap, AudinOperatorEventName, AudinOperatorListener, OperatorCall, OperatorPhoneNumber, OperatorSessionToken, GetTokenFn, DialOptions, CallDirection, CallState, CallEndReason, PresenceState, OperatorError, OperatorLogger, } from "./types.js"; export { encodeMuLaw, decodeMuLaw, encodeMuLawSample, decodeMuLawSample, resampleLinear, downsampleTo8k, upsampleFrom8k, floatToInt16, int16ToFloat, } from "./codec/index.js";