Dial out with phone audio
The code on this page works with either the default UI or the custom UI.
In some scenarios, you may want to use phone audio instead of VoIP audio. Use the SDK to call your phone number or to get the dial-in phone numbers and dial into the meeting to connect to meeting audio. The MobileRTCMeetingService interface handles most of this functionality.
Prerequisites
The meeting host account is Pro or above, and subscribes to the Audio Plan add-on.
Verify feature support
Before using any phone functionality, use the method isSupportPhone to check whether the meeting supports basic phone features such as joining the meeting by phone. Then use the isDialoutSupported method to check if the meeting supports "call me" or "invite participants by phone" functionality.
if let meetingService = MobileRTC.shared().getMeetingService() {
if meetingService.isSupportPhone() {
// Phone audio is supported
if meetingService.isDialOutSupported(){
// Support phone dial-out features
}
}
}
MobileRTCMeetingService *meetingService = [[MobileRTC sharedRTC] getMeetingService];
if (meetingService) {
if ([meetingService isSupportPhone]) {
// Phone audio is supported
if ([meetingService isDialOutSupported]) {
// Support phone dial-out features
}
}
}
Call in to the meeting
Instead of directly dialing out to a number, you can display a phone number for the user to call. getCurrentMeetingCallInNumber provides a list of call-in numbers for the current meeting.
meetingService.getDialInAllCountryCodes()
meetingService.getDialInAllCountryCodes;
After getting the call in numbers, iterate through them to access data related to each number.
if let countryID = meetingService.getDialInCurrentCountryCode()?.countryId, let dialInCallCodes = meetingService.getDialInCallCodes(withCountryId: countryID) {
for numberInfo in dialInCallCodes {
numberInfo.countryCode
numberInfo.countryNumber
numberInfo.countryId
numberInfo.countryName
numberInfo.tollFree
}
}
for (MobileRTCCallCountryCode *numberInfo in [meetingService getDialInCallCodesWithCountryId:[meetingService getDialInCurrentCountryCode].countryId]) {
numberInfo.countryCode;
numberInfo.countryNumber;
numberInfo.countryId;
numberInfo.countryName;
numberInfo.tollFree;
}
Start the phone call
To initiate phone audio, use the dialOut method, providing the full phone number including country code and phone number of the current user, to call the current user's phone as the meeting audio.
if !meetingService.isDialOutInProgress() {
meetingService.dialOut("+86123456789", isCallMe: true, withName: nil)
}
if (!meetingService.isDialOutInProgress) {
[meetingService dialOut:@"+86123456789" isCallMe:YES withName:nil];
}
You can also add a phone-audio-only user by providing the country code, phone number, and username. The username can be any value, but should be something identifiable and related to the user since it's visible to other participants in the meeting.
if !meetingService.isDialOutInProgress() {
meetingService.dialOut("+86123456789", isCallMe: false, withName: nil)
}
if (!meetingService.isDialOutInProgress) {
[meetingService dialOut:@"+86123456789" isCallMe:NO withName:nil];
}
End an in-session call by using the cancelDialOut method.
// Parameter isCallMe: true means Call Me; false means inviting others by Phone.
meetingService.cancelDialOut(true)
// Parameter isCallMe: YES means Call Me; NO means inviting others by Phone.
[meetingService cancelDialOut:YES];
Get status updates
To get updates about the phone audio's call out status, conform your class to the MobileRTCMeetingServiceDelegate protocol and add the delegate.
if let meetingService = MobileRTC.shared().getMeetingService() {
meetingService.delegate = self
}
extension TestVC: MobileRTCMeetingServiceDelegate {
func onClickedDialOut(_ parentVC: UIViewController, isCallMe me: Bool) {
}
func onDialOutStatusChanged(_ status: DialOutStatus) {
}
}
// In your .h file
@interface TestViewController : UIViewController <MobileRTCMeetingServiceDelegate>
// In your .m file
MobileRTCMeetingService *meetingService = [[MobileRTC sharedRTC] getMeetingService];
if (meetingService) {
meetingService.delegate = self;
}
- (void)onClickedDialOut:(UIViewController *)parentVC isCallMe:(BOOL)me {
}
- (void)onDialOutStatusChanged:(DialOutStatus)status {
}
Within the listeners, you can get updates to DialOutStatus to know if a call is active and whether the request was successful.
DialOutStatus_Unknown- Status unknown.DialOutStatus_Calling- The phone call is connecting.DialOutStatus_Ringing- The phone call is connected and waiting for the other end to answer.DialOutStatus_Accepted- The phone call has been answered.DialOutStatus_Busy- The number dialed was busy.DialOutStatus_NotAvailable- The number dialed was disconnected or otherwise unable to connect.DialOutStatus_UserHangUp- The phone number terminated the connection by hanging up.DialOutStatus_OtherFail- The call failed for another reason.DialOutStatus_JoinSuccess- The phone call was successful.DialOutStatus_TimeOut- The call timed out.DialOutStatus_ZoomStartCancelCall- The phone call is being cancelled.DialOutStatus_ZoomCallCanceled- The phone call has been successfully cancelled.DialOutStatus_ZoomCancelCallFail- The SDK was unable to cancel the call.DialOutStatus_NoAnswerThe phone call was not answered.DialOutStatus_BlockNoHost- The call was not allowed because the host is not present.DialOutStatus_BlockHighRate- // The system blocks invite by phone due to the high cost.DialOutStatus_BlockTooFrequent- The rate limit for this feature has been hit. Please wait and try again later.
End the call and remove the listener
When you are no longer using phone audio, remove the listener. Take note that this affects all the MobileRTCAnnotationServiceDelegate callbacks within it, so be sure that you do not need any of the callbacks before you remove it.
meetingService.delegate = nil
meetingService.delegate = nil;