1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15const call = requireInternal('telephony.call'); 16const ARGUMENTS_LEN_TWO = 2; 17const ARGUMENTS_LEN_ONE = 1; 18async function makeCallFunc(...args) { 19 if ((arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') || 20 (arguments.length === ARGUMENTS_LEN_ONE)) { 21 try { 22 let context = getContext(this); 23 await startAbility(arguments, context); 24 if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') { 25 return arguments[1](undefined, undefined); 26 } 27 return new Promise((resolve, reject) => { 28 resolve(); 29 }); 30 } catch (error) { 31 console.log('[call] makeCall error: ' + error); 32 if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'function') { 33 return arguments[1](error, undefined); 34 } 35 return new Promise((resolve, reject) => { 36 reject(error); 37 }); 38 } 39 } else if (arguments.length === ARGUMENTS_LEN_TWO && typeof arguments[1] === 'string') { 40 try { 41 let context = arguments[0]; 42 await startAbility(arguments, context); 43 return new Promise((resolve, reject) => { 44 resolve(); 45 }); 46 } catch (error) { 47 console.log("[call] makeCall error: " + error); 48 return new Promise((resolve, reject) => { 49 reject(error); 50 }); 51 } 52 } else { 53 console.log('[call] makeCall callback invalid'); 54 throw Error('invalid callback'); 55 } 56 57} 58 59async function startAbility(args, context) { 60 let config = { 61 parameters: { 62 'phoneNumber': '', 63 'pageFlag': 'page_flag_edit_before_calling' 64 }, 65 bundleName: 'com.ohos.contacts', 66 abilityName: 'com.ohos.contacts.MainAbility' 67 }; 68 if (args.length > 0 && typeof args[0] === 'string') { 69 let phoneNumberUri = new URL(args[0]); 70 if (phoneNumberUri && phoneNumberUri.protocol === 'tel:') { 71 let phoneNumber = phoneNumberUri.pathname; 72 config.parameters.phoneNumber = phoneNumber; 73 } else { 74 config.parameters.phoneNumber = args[0]; 75 } 76 } else if (args.length > 1 && typeof args[1] === 'string') { 77 let phoneNumberUri = new URL(args[1]); 78 if (phoneNumberUri && phoneNumberUri.protocol === 'tel:') { 79 let phoneNumber = phoneNumberUri.pathname; 80 config.parameters.phoneNumber = phoneNumber; 81 } else { 82 config.parameters.phoneNumber = args[1]; 83 } 84 } 85 if (context) { 86 await context.startAbility(config); 87 } else { 88 call.makeCall(config.parameters.phoneNumber); 89 } 90} 91 92export default { 93 makeCall: makeCallFunc, 94 dialCall: call.dialCall, 95 muteRinger: call.muteRinger, 96 answerCall: call.answerCall, 97 hangUpCall: call.hangUpCall, 98 hangup: call.hangup, 99 rejectCall: call.rejectCall, 100 reject: call.reject, 101 holdCall: call.holdCall, 102 unHoldCall: call.unHoldCall, 103 switchCall: call.switchCall, 104 setCallPreferenceMode: call.setCallPreferenceMode, 105 combineConference: call.combineConference, 106 kickOutFromConference: call.kickOutFromConference, 107 getMainCallId: call.getMainCallId, 108 getSubCallIdList: call.getSubCallIdList, 109 getCallIdListForConference: call.getCallIdListForConference, 110 getCallWaitingStatus: call.getCallWaitingStatus, 111 setCallWaiting: call.setCallWaiting, 112 startDTMF: call.startDTMF, 113 stopDTMF: call.stopDTMF, 114 postDialProceed: call.postDialProceed, 115 isInEmergencyCall: call.isInEmergencyCall, 116 on: call.on, 117 off: call.off, 118 isNewCallAllowed: call.isNewCallAllowed, 119 separateConference: call.separateConference, 120 getCallRestrictionStatus: call.getCallRestrictionStatus, 121 setCallRestriction: call.setCallRestriction, 122 setCallRestrictionPassword: call.setCallRestrictionPassword, 123 getCallTransferInfo: call.getCallTransferInfo, 124 setCallTransfer: call.setCallTransfer, 125 isRinging: call.isRinging, 126 setMuted: call.setMuted, 127 cancelMuted: call.cancelMuted, 128 setAudioDevice: call.setAudioDevice, 129 joinConference: call.joinConference, 130 updateImsCallMode: call.updateImsCallMode, 131 enableImsSwitch: call.enableImsSwitch, 132 disableImsSwitch: call.disableImsSwitch, 133 isImsSwitchEnabled: call.isImsSwitchEnabled, 134 isImsSwitchEnabledSync: call.isImsSwitchEnabledSync, 135 closeUnfinishedUssd: call.closeUnfinishedUssd, 136 setVoNRState: call.setVoNRState, 137 getVoNRState: call.getVoNRState, 138 canSetCallTransferTime: call.canSetCallTransferTime, 139 inputDialerSpecialCode: call.inputDialerSpecialCode, 140 reportOttCallDetailsInfo: call.reportOttCallDetailsInfo, 141 reportOttCallEventInfo: call.reportOttCallEventInfo, 142 removeMissedIncomingCallNotification: call.removeMissedIncomingCallNotification, 143 setVoIPCallState: call.setVoIPCallState, 144 setVoIPCallInfo: call.setVoIPCallInfo, 145 sendCallUiEvent: call.sendCallUiEvent, 146 DialOptions: call.DialOptions, 147 DialCallOptions: call.DialCallOptions, 148 ImsCallMode: call.ImsCallMode, 149 VoNRState: call.VoNRState, 150 AudioDevice: call.AudioDevice, 151 AudioDeviceType: call.AudioDeviceType, 152 AudioDeviceCallbackInfo: call.AudioDeviceCallbackInfo, 153 CallRestrictionType: call.CallRestrictionType, 154 CallTransferInfo: call.CallTransferInfo, 155 CallTransferType: call.CallTransferType, 156 CallTransferSettingType: call.CallTransferSettingType, 157 CallAttributeOptions: call.CallAttributeOptions, 158 VoipCallAttribute: call.VoipCallAttribute, 159 ConferenceState: call.ConferenceState, 160 CallType: call.CallType, 161 VideoStateType: call.VideoStateType, 162 DetailedCallState: call.DetailedCallState, 163 CallRestrictionInfo: call.CallRestrictionInfo, 164 CallRestrictionMode: call.CallRestrictionMode, 165 CallEventOptions: call.CallEventOptions, 166 CallAbilityEventId: call.CallAbilityEventId, 167 DialScene: call.DialScene, 168 DialType: call.DialType, 169 RejectMessageOptions: call.RejectMessageOptions, 170 CallTransferResult: call.CallTransferResult, 171 CallWaitingStatus: call.CallWaitingStatus, 172 RestrictionStatus: call.RestrictionStatus, 173 TransferStatus: call.TransferStatus, 174 DisconnectedDetails: call.DisconnectedDetails, 175 DisconnectedReason: call.DisconnectedReason, 176 MmiCodeResults: call.MmiCodeResults, 177 MmiCodeResult: call.MmiCodeResult, 178 answer: call.answer, 179 cancelCallUpgrade: call.cancelCallUpgrade, 180 controlCamera: call.controlCamera, 181 setPreviewSurface: call.setPreviewSurface, 182 setCameraZoom: call.setCameraZoom, 183 setDisplaySurface: call.setDisplaySurface, 184 setDeviceDirection: call.setDeviceDirection, 185 VideoRequestResultType: call.VideoRequestResultType, 186 DeviceDirection: call.DeviceDirection, 187 CallSessionEventId: call.CallSessionEventId, 188 ImsCallModeInfo: call.ImsCallModeInfo, 189 CallSessionEvent: call.CallSessionEvent, 190 PeerDimensionsDetail: call.PeerDimensionsDetail, 191 CameraCapabilities: call.CameraCapabilities, 192 NumberMarkInfo: call.NumberMarkInfo, 193 MarkType: call.MarkType, 194 dial: call.dial, 195 hasCall: call.hasCall, 196 hasCallSync: call.hasCallSync, 197 getCallState: call.getCallState, 198 getCallStateSync: call.getCallStateSync, 199 hasVoiceCapability: call.hasVoiceCapability, 200 isEmergencyPhoneNumber: call.isEmergencyPhoneNumber, 201 formatPhoneNumber: call.formatPhoneNumber, 202 formatPhoneNumberToE164: call.formatPhoneNumberToE164, 203 CallState: call.CallState, 204 EmergencyNumberOptions: call.EmergencyNumberOptions, 205 NumberFormatOptions: call.NumberFormatOptions, 206 startRTT: call.startRTT, 207 stopRTT: call.stopRTT, 208 sendUssdResponse: call.sendUssdResponse 209};