Handling call events

Listening to the call events#

In order to listen to the call events you need to listen to the Plugin Events using the below methods.

info

The call events mentioned below will return the JSON response. You can decode it to get the details for these events.

Mirrorfly.onMissedCall.listen((event){
var data = json.decode(event.toString());
var isOneToOneCall = data["isOneToOneCall"];
var userJid = data["userJid"];
var groupId = data["groupId"];
var callType = data["callType"];
var userList = data["userList"].toString().split(",");
//This listener will alert you about missed call notifications.
});
Mirrorfly.onLocalVideoTrackAdded.listen((event) {
var data = json.decode(event.toString());
var userJid = data["userJid"];//Current User jid
//This listener will notify when the local video track is added and starts streaming.
});
Mirrorfly.onRemoteVideoTrackAdded.listen((remoteTrackEvent) {
var data = json.decode(event.toString());
var userJid = data["userJid"];
//This listener will notify when the remote user video track is added and starts streaming.
});
Mirrorfly.onUserSpeaking.listen((event) {
var data = json.decode(event.toString());
var audioLevel = data["audioLevel"];
var userJid = data["userJid"];
//This listener will notify about the speaking events of the caller and callee.
});
Mirrorfly.onUserStoppedSpeaking.listen((jid) {
var userJid = jid;
//This listener will notify when the caller or callee stops talking.
});
info

AudioLevel ranges from 0 to 10, 0 being very low sound and 10 being too loud.

Handling mute events#

Whenever call end user mute/unmute video or audio, the below listener will be triggered.

Mirrorfly.onMuteStatusUpdated.listen((event) {
// parse a onMuteStatusUpdateEvent JSON string into a Dart object
//This listener will notify about the Mute/unmute audio and video actions of the caller and callee.
var muteStatus = json.decode(event);
var muteEvent = muteStatus["muteEvent"].toString();
var userJid = muteStatus["userJid"].toString();
switch (muteEvent){
case MuteStatus.remoteAudioMute:
break;
case MuteStatus.remoteAudioUnMute:
break;
case MuteStatus.remoteVideoMute:
break;
case MuteStatus.remoteVideoUnMute:
break;
}
});

muteEvent value will be anyone of the values of annotation class MuteEvent.

muteEvent ValueCall event
MuteStatus.remoteVideoMutewhen the remote user muted his video
MuteStatus.remoteVideoUnMutewhen the remote user unmuted his video
MuteStatus.remoteAudioMutewhen the remote user muted his audio
MuteStatus.remoteAudioUnMutewhen the remote user unmuted his video

Handling call status events#

Whenever call status changed in video or audio call, the below listener will be triggered.

Mirrorfly.onCallStatusUpdated.listen((onCallStatusUpdateEvent) {
//This listener will notify about the Ongoing call status of the caller and callee.
// parse a onCallStatusUpdate Event JSON string into a Dart object
var statusUpdateReceived = json.decode(onCallStatusUpdateEvent);
var callMode = statusUpdateReceived["callMode"].toString();
var userJid = statusUpdateReceived["userJid"].toString();
var callType = statusUpdateReceived["callType"].toString();
var callStatus = statusUpdateReceived["callStatus"].toString();
switch (callStatus){
case CallStatus.connecting:
break;
case CallStatus.onResume:
break;
case CallStatus.userJoined:
break;
case CallStatus.userLeft:
break;
case CallStatus.inviteCallTimeout:
break;
case CallStatus.attended:
break;
case CallStatus.disconnected:
break;
case CallStatus.calling10s:
break;
case CallStatus.callingAfter10s:
break;
case CallStatus.calling:
break;
case CallStatus.reconnected:
break;
case CallStatus.ringing:
break;
case CallStatus.onHold:
break;
case CallStatus.connected:
break;
case CallStatus.callTimeout:
break;
}
});

callStatus value will be anyone of the values of annotation class CallStatus.

callStatus ValueCall event
CallStatus.callingthe initial state of the call
CallStatus.connectingThe current call is in connecting state
CallStatus.ringingthe remote user is having internet and acknowledged the call
CallStatus.attendedthe user attended call and UI can be presented with the users in the call
CallStatus.connectedthe call is successfully connected and audio/video tracks transmission is about to start
CallStatus.disconnectedthe call is disconnected and call UI can be closed
CallStatus.reconnectedthe call is connected back after a reconnecting state
CallStatus.onHoldthe remote user has put your call on hold, it will happedn when the remote user attended gsm call
CallStatus.onResumethe remote user has resumed your call after a on hold, it will happen when the remote user disconnected gsm call
CallStatus.callTimeoutwhen we don't receive ack for the outgoing call from the remote user within 30 seconds, When we don't receive ack for the incoming call from the caller within 30 seconds, When we don't receive ack for the call invite from the invited user within 30 seconds

Handling call action events#

Whenever call action received in video or audio call, the below delegate will be triggered,

Mirrorfly.onCallAction.listen((event) {
// parse a onCallActionEvent JSON string into a Dart object
var actionReceived = json.decode(event);
var callAction = actionReceived["callAction"].toString();
var userJid = actionReceived["userJid"].toString();
var callMode = actionReceived["callMode"].toString();
var callType = actionReceived["callType"].toString();
//This listener will notify about the ongoing call actions of the caller and callee.
switch(callAction){
case CallAction.localHangup:
break;
case CallAction.remoteBusy:
break;
case CallAction.remoteHangup:
break;
case CallAction.remoteEngaged:
break;
case CallAction.audioDeviceChanged:
break;
case CallAction.denyCall:
break;
case CallAction.cameraSwitchSuccess:
break;
case CallAction.changedToAudioCall:
break;
case CallAction.videoCallConversionCancel:
break;
case CallAction.videoCallConversionRequest:
break;
case CallAction.videoCallConversionAccepted:
break;
case CallAction.videoCallConversionRejected:
break;
}
});

callAction value will be anyone of the values of annotation class CallAction.

callAction ValueCall event
CallAction.localHangupwhenever you disconnect the call, the action will be received
CallAction.remoteHangupwhenever remote user disconnect the call, the action will be received
CallAction.denyCallwhen you decline the incoming call, the action will be received for callee
CallAction.remoteEngagedwhen the remote user is engaged in the another call, the action will be received for the caller
CallAction.remoteBusywhen the remote user declines incoming the call, the action will be received for the caller
CallAction.audioDeviceChangedwhenever the audio device changed in call, update the audio device UI
CallAction.videoCallConversionRejectedWhen remote user declined our video call switch request
CallAction.videoCallConversionAcceptedWhen remote user accepted our video call switch request
CallAction.videoCallConversionCancelWhen remote user cancels the video call switch request made by them
CallAction.cameraSwitchSuccessWhen camera switch done, the action will be received
CallAction.changedToAudioCallWhen ui needs to be changed as audio call ui this action will be received
CallAction.videoCallConversionRequestWhen Remote user request to switch Audio call to Video call this action will be received

Listening to the call events Collectively#

Assign the listener to the appropriate class to receive event updates. Extend the class and implement the necessary event listeners collectively for streamlined integration you can register your own listener by using the below method.

tip

There can be only one message listener at a time, if you set multiple times using the below method it will replace the old listener always.

Mirrorfly.setCallEventListener(YourClass());
class YourClass extends CallEventListeners{
@override
void onCallAction(String userJid, String callMode, String callType, String callAction) {
// TODO: implement onCallAction
}
@override
void onCallLogDeleted(String callLogId) {
// TODO: implement onCallLogDeleted
}
@override
void onCallLogsCleared() {
// TODO: implement onCallLogsCleared
}
@override
void onCallLogsUpdated() {
// TODO: implement onCallLogsUpdated
}
@override
void onCallStatusUpdated(String userJid, String callMode, String callType, String callStatus) {
// TODO: implement onCallStatusUpdated
}
@override
void onLocalVideoTrackAdded(String userJid) {
// TODO: implement onLocalVideoTrackAdded
}
@override
void onMissedCall(String userJid, String groupId, bool isOneToOneCall, String callType, List<String> userList) {
// TODO: implement onMissedCall
}
@override
void onMuteStatusUpdated(String userJid, String muteEvent) {
// TODO: implement onMuteStatusUpdated
}
@override
void onRemoteVideoTrackAdded(String userJid) {
// TODO: implement onRemoteVideoTrackAdded
}
@override
void onTrackAdded(String userJid) {
// TODO: implement onTrackAdded
}
@override
void onUserSpeaking(String userJid, String audioLevel) {
// TODO: implement onUserSpeaking
}
@override
void onUserStoppedSpeaking(String userJid) {
// TODO: implement onUserStoppedSpeaking
}
}