Skip to content

Custom WebRTC Video Calling API for building real-time communication apps with 1000+ features, source code access and security.

License

Notifications You must be signed in to change notification settings

MirrorFly/MirrorflyWebrtc

Repository files navigation

MirrorFly WebRTC SDK For Voice & Video Calls

This repository includes a custom SDK for building voice and video calling features into your existing app or web. There are over 1000 real-time communication features along with 500+ AI-powered features to build AI chatbots and AI voice agents.

You can customize any part of the solution and deploy it on your own server. MirrorFly WebRTC SDK gives you full control over the security, data and infrastructure. Altogether you’ll only need minimal efforts to deploy a full AI-powered voice/ video calling app in 24 hrs with MirrorFly WebRTC SDK.

🤹 Key Product Offerings

MirrorFly helps build omni-channel communication apps for any kind of business

💬 In-app Messaging - Connect users individually or as groups via instant messaging features.
🎯 HD Video Calling- Engage users over face-to-face conversations anytime, and from anywhere.
🦾 HQ Voice Calling - Deliver crystal clear audio calling experiences with latency as low as 3ms.
🤖 AI Voice Agent - Build custom AI voicebots that can understand, act and respond to user questions.
🤖 AI Chatbot - Deploy white-label AI chatbots that drive autonomous conversations across any web or mobile app.
🦾 Live Streaming - Broadcast video content to millions of viewers around the world, within your own enterprise app.

Requirements

The requirements for the Audio & Video Chat SDK for Android are:

  • Android: Lollipop 5.0 (API Level 21) or higher
  • Java: Version 7 or higher
  • Gradle: 8.6.0 or higher
  • Kotlin: 2.0.20 or higher
  • targetSdkVersion / compileSdkVersion: 35 or above

Step 1: Register here to get a MirrorFly User account.
Step 2: Login to your Account
Step 3: Get the License key from the application Info’ section

![license-key][image2]

Step 1: Create a new project or open an existing project in Android Studio.
Step 2:

  • If using Gradle 6.8 or higher, add the following code to your settings.gradle file.
  • If using Gradle 6.7 or lower, add the code to your root build.gradle file.

![Jcenter][image3]

dependencyResolutionManagement {
    repositories {
        jcenter()
        maven {
            url "https://repo.mirrorfly.com/release"
        }
    }
}

Step 3: Add the following dependencies in the app/build.gradle file.

dependencies {
    implementation 'com.mirrorfly.sdk:mirrorflysdk:7.13.31'
}

Step 4: Add the below line in the gradle.properties file, to avoid imported library conflicts.

android.enableJetifier=true

Step 5: Add required runtime permissions for calls click here

Before using the SDK, ensure the basic requirements are met. In your Application class, within the onCreate() method, use the following ChatManager method to provide the necessary initialization data:

![configscyAar][image4]

ChatManager.initializeSDK("LICENSE_KEY", (isSuccess, throwable, data) -> {
    if (isSuccess) {
        Log.d("TAG", "initializeSDK success ");
    } else {
        Log.d("TAG", "initializeSDK failed with reason " + data.get("message"));
    }
});

Add the created MyApplication to AndroidManifest.xml.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.uikitapplication">
    <application
        android:name=".MyApplication"  // Add this line.
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                ...
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

The following method registers a user in sandbox or live mode based on the setIsTrialLicenceKey setting.

FlyCore.registerUser(USER_IDENTIFIER, (isSuccess, throwable, data) -> {
    if (isSuccess) {
        Boolean isNewUser = (Boolean) data.get("is_new_user");  // true - if the current user is different from the previous session's logged-in user, false - if the same user is logging in again
        String userJid = (String) data.get("userJid"); //Ex. 12345678@xmpp-preprod-sandbox.mirrorfly.com (USER_IDENTIFIER+@+domain of the chat server)
        JSONObject responseObject = (JSONObject) data.get("data");
        String username = responseObject.getString("username");
    } else {
        // Register user failed print throwable to find the exception details.
    }
});

Once registration is successful, the Chat SDK automatically attempts to connect to the chat server. It also observes application lifecycle changes and connects or disconnects from the chat server accordingly.

Once the ChatConnectionListener is set, you can receive connection status updates through the callback method shown below.

ChatManager.setConnectionListener(new ChatConnectionListener() {
    @Override
    public void onConnected() {
        // Write your success logic here to navigate Profile Page or
        // To Start your one-one chat with your friends
    }

    @Override
    public void onDisconnected() {
        // Connection disconnected
    }

    @Override
    public void onConnectionFailed(@NonNull FlyException e) {
        // Connection Not authorized or Unable to establish connection with server
    }

    @Override
    public void onReconnecting() {
        // Automatic reconnection enabled
    }
});

In your Application class, inside the onCreate() method add the below lines:

@Override
public void onCreate() {
    super.onCreate();

    //set your call activity
    CallManager.setCallActivityClass(CALL_UI_ACTIVITY.class);

    CallManager.setMissedCallListener((isOneToOneCall, userJid, groupId, callType, userList, CallMetaData[] callMetaDataArray) -> {
        //show missed call notification
    });

    CallManager.setCallHelper(new CallHelper() {
        @NonNull
        @Override
        public String getNotificationContent(@NonNull String callDirection, CallMetaData[] callMetaDataArray) {
            return CallNotificationHelper.getNotificationMessage();
        }
    });

    CallManager.setCallNameHelper(new CallNameHelper() {
        @NonNull
        @Override
        public String getDisplayName(@NonNull String jid, CallMetaData[] callMetaDataArray) {
            return ContactManager.getDisplayName(jid);
        }
    });
}

Define your Call UI activity in the AndroidManifest.xml as shown below.
In your call activity’s onCreate() method, call the following method to configure the call activity.

<activity
    android:name="YOUR_CALL_ACTIVITY"
    android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
    android:excludeFromRecents="true"
    android:launchMode="singleTask"
    android:resizeableActivity="false"
    android:screenOrientation="portrait"
    android:supportsPictureInPicture="true"
    android:showOnLockScreen="true"
    android:turnScreenOn="true"
    android:taskAffinity="call.video"
    tools:targetApi="o_mr1" />

To remove the ongoing call notification, call the following method in your call activity’s onStart() to notify the audio and video calling SDK.

CallManager.configureCallActivity(ACTIVITY);

Call the following method in your call activity’s onStop() to notify the Call SDK to display the ongoing call notification.

CallManager.bindCallService();
CallManager.unbindCallService();

To generate a JID for any user, use the below method.

FlyUtils.getJid(USER_NAME);

To send custom data when making a call, use the optional metaData parameter in all makeCall methods. This parameter accepts an array of type CallMetadata.

The voice call feature allows users to make a one-to-one audio call with another SDK user, including optional call metadata. Use the following method to initiate a voice call:

CallManager.makeVoiceCall("TO_JID", CALL_METADATA, (isSuccess, flyException) -> {
    if (isSuccess) {
        //SDK will take care of presenting the Call UI. It will present the activity that is passed using the method `CallManager.setCallActivityClass()`
        Log.d("MakeCall", "call success");
    } else {
        if (flyException != null) {
            String errorMessage = flyException.getMessage();
            Log.d("MakeCall", "Call failed with error: " + errorMessage);
            //toast error message
        }
    }
});

When you receive an audio call from another SDK user, the Call SDK will display a notification if the device is running Android 10 (API level 29) or higher. On lower Android versions, the activity set via CallManager.setCallActivityClass() during SDK initialization will launch with the call details. A sample call UI is provided for quick integration.

Answer the call

When you receive an audio call from another SDK user, your activity may be launched depending on the Android version. When the user presses the accept button in your call UI, call the following SDK method to answer the call and notify the caller.

Note: If the required permissions are not granted, the call will be automatically declined even if the user attempts to answer it.

CallManager.answerCall((isSuccess, flyException) -> {
    if (isSuccess) {
        Log.d("AnswerCall", "call answered success");
    } else {
        if (flyException != null) {
            String errorMessage = flyException.getMessage();
            Log.d("AnswerCall", "Call answered failed with error: " + errorMessage);
            //toast error message
        }
    }
});

When you receive an audio call from another SDK user, your activity may be launched depending on the Android version. When the user presses the decline button in your call UI, call the following SDK method to decline the call and notify the caller.

CallManager.declineCall();

Whenever you make an audio call to another SDK user and want to disconnect either before the call connects or after the conversation ends, call the following SDK method when the user presses the disconnect button in your call UI. This will end the call and notify the other participant.

CallManager.disconnectCall();

☁️ Deployment Models - Self-hosted and Cloud

MirrorFly offers full freedom with the hosting options:
Self-hosted: Deploy your client on your own data centers, private cloud or third-party servers.
Check out our multi-tenant cloud hosting
Cloud: Host your client on MirrorFly’s multi-tenant cloud servers.
Check out our multi-tenant cloud hosting

📱 Mobile Client

MirrorFly offers a fully-built client SafeTalk that is available in:
![Rocket.Chat on Apple App Store][image5] ![Rocket.Chat on Google Play][image6]
You can use this client as a messaging app, or customize, rebrand & white-label it as your chat client.

📚 Learn More

🧑‍💻 Hire Experts

Need a tech team to build your enterprise app? Hire a full team of experts. From concept to launch, we handle every step of the development process. Get a high-quality, fully-built app ready to launch, carefully built by industry experts

⏱️ Round-the-clock Support

If you’d like to take help when working with our solution, feel free to contact our experts who will be available to help you anytime of the day or night.

💼 Become a Part of our amazing team

We're always on the lookout for talented developers, support specialists, and product managers. Visit our careers page to explore current opportunities.

🗞️ Get the Latest Updates