meowcaller-js / Docs / API Reference

API Reference

Exports

import {
  Client,
  Call,
  CallSession, CallDirection, CallPhase,
  NewPlayer, PlayerState,
  PCMStream, WAVFile, SinkFunc, SourceFunc,
  AnnexBRecorder, VideoSinkFunc,
  CallRegistry,
  AudioCodec,
  WithLogger, WithDiagnostics,
} from 'meowcaller-js';

Client

new Client(wa, opts?)
MethodReturnsDescription
connect()thisInstall event handlers on the Baileys socket
call(ctx, target)Promise<Call>Place an outbound call
onIncomingCall(fn)voidRegister incoming call handler
listCalls()(Call|CallSession)[]List all active calls
getCall(callID)Call|CallSession|nullLook up a call by ID

Call

MethodReturnsDescription
id()stringCall identifier
peer()stringPeer JID
state()symbolCurrent CallPhase
isVideo()booleanWhether the call has video
answer()Promise<void>Answer an incoming call
reject()Promise<void>Reject an incoming call
hangup()Promise<void>Hang up the call
play(source)PlayerPlay audio into the call
subscribe(player)voidAttach a player to the call
receive(sink)voidSet the incoming audio sink
receiveVideo(sink)voidSet the incoming video sink
sendVideo(au)voidSend H.264 Annex B data
onReady(fn)voidFirst RTP decoded callback
onEnd(fn)voidCall ended callback
onStateChange(fn)voidPhase transition callback
onVideoState(fn)voidVideo state change callback

CallSession

Internal session object tracking call state.

PropertyTypeDescription
callIDstringCall identifier
peerJIDstringPeer JID
callCreatorstringCreator JID
directionsymbolCallDirection.Incoming or Outgoing
isVideobooleanWhether video is present
phase_()symbolCurrent phase (note the underscore — avoids conflict with phase property)
isActive()booleantrue if phase is Active
isEnded()booleantrue if phase is Ended
description()stringHuman-readable description
transitionTo(next)booleanAttempt a phase transition

CallPhase

CallPhase.Idle      // Outbound call created
CallPhase.Calling   // Offer sent
CallPhase.Ringing   // Remote ringing (inbound starts here)
CallPhase.Connecting // Call accepted
CallPhase.Active    // Media flowing
CallPhase.Ended     // Call finished

CallDirection

CallDirection.Outgoing
CallDirection.Incoming

Player

NewPlayer()
MethodDescription
play(source)Start playing a source
pause()Pause playback
resume()Resume playback
stop()Stop and close source
state()Current PlayerState
onFinish(fn)Register finish callback
nextFrame()Get next frame (internal)

PlayerState

PlayerState.Idle
PlayerState.Playing
PlayerState.Paused

Audio

Constants

NameValueDescription
SampleRate16000Audio sample rate in Hz
FrameSamples960Samples per frame (60 ms)

Functions

FunctionReturnsDescription
WAVFile(path)Promise<AudioSource>Read a WAV file
PCMStream(r)AudioSourceRead raw PCM from a stream
SourceFunc(provider)AudioSourceCreate source from callback
SinkFunc(fn)AudioSinkCreate sink from callback

Video

FunctionReturnsDescription
AnnexBRecorder(path)Promise<VideoSink>Record H.264 to file
VideoSinkFunc(fn)VideoSinkCreate video sink from callback

CallRegistry

MethodReturnsDescription
insert(session, call?)booleanRegister a call
get(callID)entry|nullLook up an entry
has(callID)booleanCheck if call exists
list()(Call|CallSession)[]List all calls
remove(callID)booleanRemove and abort a call
abortAll()numberRemove all calls, returns count
activeCount()numberNumber of active calls
phase(callID)[symbol, boolean]Get call phase
transition(callID, next)booleanTransition a call
snapshot(callID)[obj, boolean]Get session snapshot
setMediaTask(callID, cancel)voidSet media abort function

Configuration

FunctionDescription
WithLogger(logger)Set a pino-compatible logger
WithDiagnostics(rec)Set a Recorder for call diagnostics

Codec

AudioCodec.Mlow  // WhatsApp's MLow codec (default)
AudioCodec.Opus  // Opus codec (alternative)
selectAudioCodec(vs) // Returns AudioCodec.Mlow or AudioCodec.Opus