Skip to content

Conversation

@rasonyang
Copy link

Summary

This PR adds support for BroadSoft Access-Side Extensions, implementing two key features:

  1. Auto-Answer - Automatic call answering based on Call-Info header with answer-after parameter
  2. Remote Control - Talk Events - Remote call control via NOTIFY messages with Event: talk

Changes

Core API (src/api/broadsoft/)

  • auto-answer.ts - Auto-answer logic for Call-Info header parsing and delayed answering
  • call-info-parser.ts - Parser for Call-Info header with answer-after parameter
  • remote-control.ts - Handler for remote control NOTIFY events (talk/mute)
  • types.ts - TypeScript types and enums for BroadSoft extensions
  • index.ts - Public API exports with helper functions

Demo Application

  • demo/demo-broadsoft.html - Interactive demo UI for testing BroadSoft extensions
  • demo/demo-broadsoft.ts - Full-featured demo implementation with FreeSWITCH integration
  • demo/demo-broadsoft.css - Styled UI for demo application

Tests

  • test/spec/api/broadsoft/auto-answer.spec.ts - Unit tests for auto-answer functionality
  • test/spec/api/broadsoft/call-info-parser.spec.ts - Unit tests for Call-Info header parsing
  • test/spec/api/broadsoft/remote-control.spec.ts - Unit tests for remote control events

Documentation

  • src/api/broadsoft/README.md - Comprehensive API documentation with usage examples
  • examples/broadsoft-extensions.ts - Code examples demonstrating integration
  • integration-tests/FREESWITCH.md - FreeSWITCH integration testing guide
  • integration-tests/README.md - General integration testing documentation

Features

Auto-Answer

  • Parses Call-Info: <sip:domain>; answer-after=N header from incoming INVITE
  • Configurable delay before auto-answering (default: from header)
  • Optional callbacks for before/after auto-answer events
  • Helper functions: shouldAutoAnswer(), getAutoAnswerDelay(), handleAutoAnswer()

Remote Control

  • Handles NOTIFY messages with Event: talk
  • Automatic call answering/resuming when talk event received
  • Configurable callbacks for UI updates
  • Helper functions: isBroadSoftNotification(), handleRemoteControlNotification()

Testing

Run the test suite:

npm test

Run the demo application:
npm run build-demo
# Open demo/demo-broadsoft.html in browser

Integration with FreeSWITCH

Test auto-answer:
originate {sip_h_Call-Info=<sip:${domain}>; answer-after=0}user/1000@${domain} &echo

Test remote control:
uuid_phone_event <uuid> talk

See integration-tests/FREESWITCH.md for complete testing instructions.

API Usage

import { BroadSoft, Invitation } from "sip.js";

// Auto-answer configuration
const autoAnswerOptions: BroadSoft.AutoAnswerOptions = {
  enabled: true,
  onBeforeAutoAnswer: (delaySeconds) => console.log(`Auto-answering in ${delaySeconds}s`),
  onAfterAutoAnswer: () => console.log("Call answered")
};

userAgent.delegate = {
  onInvite: (invitation: Invitation) => {
    if (BroadSoft.shouldAutoAnswer(invitation)) {
      BroadSoft.handleAutoAnswer(invitation, autoAnswerOptions);
    }

    invitation.delegate = {
      onNotify: (notification) => {
        if (BroadSoft.isBroadSoftNotification(notification)) {
          BroadSoft.handleRemoteControlNotification(invitation, notification, {
            enabled: true,
            onTalkEvent: (action) => console.log(`Talk event: ${action}`)
          });
        }
        notification.accept();
      }
    };
  }
};

Breaking Changes

None. This is a new feature that is opt-in.

Checklist

- Core API implementation
- Unit tests with >90% coverage
- Demo application
- API documentation
- Integration testing guide
- Example code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant