c_icare_sipcall 0.0.5 copy "c_icare_sipcall: ^0.0.5" to clipboard
c_icare_sipcall: ^0.0.5 copied to clipboard

A Flutter package for SIP calling using WebRTC and sip_ua.

CicareSipcall #

CicareSipcall is a SIP (Session Initiation Protocol) implementation using sip_ua that provides functionality for managing SIP registration and making audio calls with a SIP server, specifically for Asterisk or any other SIP server. This module also offers features for answering, accepting calls, and performing call bridging (spying, whispering, and barging).

Features #

  • SIP server registration
  • Make outgoing calls
  • Handle incoming calls
  • Call handling features (spying, whispering, and barging)
  • Handle SIP notifications like registration changes and call state changes

CicareSipcall Class #

CicareSipcall is the main class that manages all SIP-related operations and calls. This class implements SipListener to receive notifications about call status, registration changes, and transport state changes.

Constructor #

CicareSipcall({
  required this.exten,
  required this.password,
  required this.displayName
});
  • exten: The SIP extension (username) for registration.
  • password: The SIP password for the extension.
  • displayName: The display name used in SIP registration.

Main Methods #

Future<void> register(); // Registers to the SIP server.
void unregister(); // Unregisters from the SIP server.
void call(String target); // Initiates an outgoing call.
void spying(String target); // Listens to a call.
void wispering(String target); // Speaks to the target without them knowing.
void barging(String target); // Joins the target's call.
void hangup(Call call); // Ends the ongoing call.
void accept(Call call); // Accepts an incoming call.
void makeCall(String dn); // Makes a call to a destination number.

Registration and Usage Procedure #

1. SIP Initialization and Registration #

Before using the call features, you need to register to the SIP server using the register() method.

CicareSipcall sipCall = CicareSipcall(
  exten: '1001',
  password: 'yourpassword',
  displayName: 'John Doe'
);

await sipCall.register();

2. Making a Call #

After successful registration, you can initiate an outgoing call using call().

sipCall.call('1002');  // Call extension 1002

3. Handling Incoming Calls #

When an incoming call is received, you can handle it using callStateChanged.

@override
void callStateChanged(Call call, CallState state) {
  if (state.state == CallStateEnum.CALL_INITIATION && call.direction == 'INCOMING') {
    call.answer(_helper.buildCallOptions(true)); // Automatically answers the call
  }
}

4. Spying, Whispering, and Barging #

Use the respective methods to perform spying, whispering, or barging.

sipCall.spying('1002');  // Listen to the call on extension 1002
sipCall.wispering('1002');  // Speak without the target knowing
sipCall.barging('1002');  // Join the call

5. Ending the Call #

To end an ongoing call, use hangup().

sipCall.hangup(call);  // End the ongoing call

Implementing Listener #

To handle SIP status changes, add a listener to receive various SIP events.

void setListener(SipListener listener) {
  _helper.addSipUaHelperListener(listener);
}

Implementing SipListener #

The CicareSipcall class implements SipListener to handle SIP notifications.

  • callStateChanged(): Handles changes in call state.
  • registrationStateChanged(): Handles changes in registration status.
  • transportStateChanged(): Handles changes in transport state.
  • onNewMessage(), onNewNotify(), onNewReinvite(): Handles new SIP messages.

Complete Example #

void main() async {
  CicareSipcall sipCall = CicareSipcall(
    exten: '1001',
    password: 'yourpassword',
    displayName: 'John Doe'
  );

  await sipCall.register();  // SIP registration

  // Wait for an incoming call and automatically accept it
  sipCall.setListener(MySipListener());

  // Make an outgoing call
  sipCall.call('1002');
}

class MySipListener implements SipListener {
  @override
  void callStateChanged(Call call, CallState state) {
    if (state.state == CallStateEnum.CALL_INITIATION && call.direction == 'INCOMING') {
      call.answer(true);  // Automatically answer the call
    }
  }

  @override
  void registrationStateChanged(RegistrationState state) {
    if (state.state == RegistrationStateEnum.REGISTERED) {
      print('Successfully registered with SIP server!');
    }
  }

  @override
  void transportStateChanged(TransportState state) {
    // Handle transport state changes
  }

  @override
  void onNewMessage(SIPMessageRequest msg) {
    // Handle new SIP message
  }
}

Troubleshooting #

1. Error: RTCVideoRenderer is missing implementations for these members #

Error Message:

Error: The non-abstract class 'RTCVideoRenderer' is missing implementations for these members:
 - VideoRenderer.videoValue

Solution: Add the following code inside the file: /home/linux/.pub-cache/hosted/pub.flutter-io.cn/webrtc_interface-1.2.1+hotfix.1/lib/src/rtc_video_renderer.dart

@override
RTCVideoValue get videoValue => value;

Then, run the following commands to clean and rebuild the project:

flutter clean
flutter pub get

2. Ensure Microphone Permissions are Enabled #

Add the following permissions inside AndroidManifest.xml: android/app/src/main/AndroidManifest.xml

<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

This package has been tested with Flutter 3.24.5. It is recommended to use this version or newer for optimal compatibility.

Add the following lines to pubspec.yaml:

environment:
  sdk: ">=3.0.0 <4.0.0"
  flutter: ">=3.24.5"

To update Flutter to the latest version, run:

flutter upgrade
0
likes
0
points
21
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for SIP calling using WebRTC and sip_ua.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_webrtc, permission_handler, sip_ua

More

Packages that depend on c_icare_sipcall