Media

CallManager

High-level call orchestration

The CallManager wires SympleClient messaging to WebRTCPlayer to provide a complete call flow. It maps symple message events to WebRTC methods and player events back to symple messages.

Install

npm install symple-player

Usage

import SympleClient from 'symple-client'
import CallManager from 'symple-player/src/call-manager.js'

const client = new SympleClient({
  url: 'ws://localhost:4500',
  peer: { user: 'alice', name: 'Alice' }
})

const calls = new CallManager(client, document.getElementById('video'), {
  rtcConfig: {
    iceServers: [
      { urls: 'stun:stun.l.google.com:19302' }
    ]
  },
  mediaConstraints: { audio: true, video: true }
})

client.connect()

Making a call

calls.call('bob|session-id')

calls.on('accepted', (peerId) => {
  console.log('call accepted')
})

calls.on('active', (peerId) => {
  console.log('media flowing')
})

Handling incoming calls

calls.on('incoming', (peerId, message) => {
  if (confirm('Accept call from ' + peerId + '?')) {
    calls.accept()
  } else {
    calls.reject('declined')
  }
})

If already in a call, incoming calls are auto-rejected with reason busy.

Ending a call

calls.hangup('user ended')

Media controls

calls.muteAudio(true)   // mute outgoing audio
calls.muteVideo(true)   // mute outgoing video
calls.mute(true)         // mute incoming audio

Events

EventPayloadDescription
incomingpeerId, messageIncoming call received
ringingpeerIdOutgoing call initiated
acceptedpeerIdRemote accepted
rejectedpeerId, reasonRemote rejected
connectingpeerIdWebRTC negotiation started
activepeerIdMedia flowing
endedpeerId, reasonCall ended
errorErrorCall error
localstreamMediaStreamLocal media acquired
remotestreamMediaStreamRemote media received

Constructor options

OptionTypeDefaultDescription
rtcConfigobjectGoogle STUN serversRTCConfiguration for the peer connection
mediaConstraintsobject{ audio: true, video: true }getUserMedia constraints
localMediabooleantrueAcquire local media (false for receive-only)
receiveMediabooleantrueExpect remote media (false for send-only)

Cleanup

calls.destroy()

Hangs up any active call and unbinds client message handlers.