Skip to content

Commit 3318b29

Browse files
committed
Rename setActive to setAvailable and isAvailable to isConnectionServiceAvailable
1 parent 345b5a8 commit 3318b29

File tree

3 files changed

+58
-54
lines changed

3 files changed

+58
-54
lines changed

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ public RNCallKeepModule(ReactApplicationContext reactContext) {
7979

8080
this.reactContext = reactContext;
8181

82-
VoiceConnectionService.setActive(false);
82+
VoiceConnectionService.setAvailable(false);
8383

84-
if (isAvailable()) {
84+
if (isConnectionServiceAvailable()) {
8585
this.registerPhoneAccount(this.getAppContext());
8686
voiceBroadcastReceiver = new VoiceBroadcastReceiver();
8787
registerReceiver();
88-
VoiceConnectionService.setActive(false);
88+
VoiceConnectionService.setAvailable(true);
8989
}
9090
}
9191

@@ -105,7 +105,7 @@ public String getName() {
105105

106106
@ReactMethod
107107
public void displayIncomingCall(String number, String callerName) {
108-
if (!isAvailable() || !hasPhoneAccount()) {
108+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
109109
return;
110110
}
111111

@@ -120,7 +120,7 @@ public void displayIncomingCall(String number, String callerName) {
120120

121121
@ReactMethod
122122
public void startCall(String number, String callerName) {
123-
if (!isAvailable() || !hasPhoneAccount()) {
123+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
124124
return;
125125
}
126126

@@ -138,7 +138,7 @@ public void startCall(String number, String callerName) {
138138

139139
@ReactMethod
140140
public void endCall() {
141-
if (!isAvailable() || !hasPhoneAccount()) {
141+
if (!isConnectionServiceAvailable() || !hasPhoneAccount()) {
142142
return;
143143
}
144144

@@ -154,7 +154,7 @@ public void endCall() {
154154

155155
@ReactMethod
156156
public void checkPhoneAccountPermission(Promise promise) {
157-
if (!isAvailable()) {
157+
if (!isConnectionServiceAvailable()) {
158158
promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "ConnectionService not available for this version of Android.");
159159
return;
160160
}
@@ -178,8 +178,8 @@ public void hasPhoneAccount(Promise promise) {
178178
}
179179

180180
@ReactMethod
181-
public void setActive(Boolean active) {
182-
VoiceConnectionService.setActive(active);
181+
public void setAvailable(Boolean active) {
182+
VoiceConnectionService.setAvailable(active);
183183
}
184184

185185
@ReactMethod
@@ -194,7 +194,7 @@ public void setCurrentCallActive() {
194194

195195
@ReactMethod
196196
public void openPhoneAccounts() {
197-
if (!isAvailable()) {
197+
if (!isConnectionServiceAvailable()) {
198198
return;
199199
}
200200

@@ -214,13 +214,13 @@ public void openPhoneAccounts() {
214214
}
215215

216216
@ReactMethod
217-
public static Boolean isAvailable() {
217+
public static Boolean isConnectionServiceAvailable() {
218218
// PhoneAccount is available since api level 23
219219
return Build.VERSION.SDK_INT >= 23;
220220
}
221221

222222
private void registerPhoneAccount(Context appContext) {
223-
if (!isAvailable()) {
223+
if (!isConnectionServiceAvailable()) {
224224
return;
225225
}
226226

@@ -267,7 +267,7 @@ private Boolean checkPermissions(String[] permissions, int id) {
267267
}
268268

269269
private static boolean hasPhoneAccount() {
270-
if (!isAvailable()) {
270+
if (!isConnectionServiceAvailable()) {
271271
return false;
272272
}
273273

android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import android.telecom.DisconnectCause;
3232
import android.telecom.PhoneAccountHandle;
3333
import android.telecom.TelecomManager;
34+
import android.util.Log;
3435

3536
import static io.wazo.callkeep.RNCallKeepModule.ACTION_ANSWER_CALL;
3637
import static io.wazo.callkeep.RNCallKeepModule.ACTION_AUDIO_SESSION;
@@ -47,14 +48,14 @@
4748
@TargetApi(Build.VERSION_CODES.M)
4849
public class VoiceConnectionService extends ConnectionService {
4950
private static Connection connection;
50-
private static Boolean isActive = false;
51+
private static Boolean isAvailable = false;
5152

5253
public static Connection getConnection() {
5354
return connection;
5455
}
5556

56-
public static void setActive(Boolean value) {
57-
isActive = value;
57+
public static void setAvailable(Boolean value) {
58+
isAvailable = value;
5859
}
5960

6061

@@ -87,7 +88,7 @@ public Connection onCreateOutgoingConnection(PhoneAccountHandle connectionManage
8788
}
8889

8990
private Boolean canMakeOutgoingCall() {
90-
return isActive;
91+
return isAvailable;
9192
}
9293

9394
private Connection createConnection(ConnectionRequest request) {

index.js

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,101 +13,104 @@ class RNCallKeep {
1313
}
1414

1515

16-
addEventListener(type, handler) {
16+
addEventListener = (type, handler) => {
1717
const listener = listeners[type](handler);
1818

1919
this._callkitEventHandlers.set(handler, listener);
20-
}
20+
};
2121

22-
removeEventListener(type, handler) {
22+
removeEventListener = (type, handler) => {
2323
const listener = this._callkitEventHandlers.get(handler);
2424
if (!listener) {
2525
return;
2626
}
2727

2828
listener.remove();
2929
this._callkitEventHandlers.delete(handler);
30-
}
30+
};
3131

32-
setup(options) {
32+
setup = (options) => {
3333
if (!isIOS) {
3434
return (async () => {
3535
return this._setupAndroid(options.android);
3636
})();
3737
}
3838

3939
return this._setupIOS(options.ios);
40-
}
40+
};
4141

42-
displayIncomingCall(uuid, handle, localizedCallerName, handleType = 'number', hasVideo = false) {
42+
displayIncomingCall = (uuid, handle, localizedCallerName, handleType = 'number', hasVideo = false) => {
4343
if (!isIOS) {
4444
RNCallKeepModule.displayIncomingCall(handle, localizedCallerName);
4545
return;
4646
}
4747

4848
RNCallKeepModule.displayIncomingCall(uuid, handle, handleType, hasVideo, localizedCallerName);
49-
}
49+
};
5050

51-
startCall(uuid, handle, handleType = 'number', hasVideo = false, contactIdentifier) {
51+
startCall = (uuid, handle, handleType = 'number', hasVideo = false, contactIdentifier) => {
5252
if (!isIOS) {
5353
RNCallKeepModule.startCall(handle, contactIdentifier);
5454
return;
5555
}
5656

5757
RNCallKeepModule.startCall(uuid, handle, handleType, hasVideo, contactIdentifier);
58-
}
58+
};
5959

60-
reportConnectedOutgoingCallWithUUID(uuid) {
60+
reportConnectedOutgoingCallWithUUID = (uuid) => {
6161
RNCallKeepModule.reportConnectedOutgoingCallWithUUID(uuid);
62-
}
62+
};
6363

64-
endCall(uuid) {
64+
endCall = (uuid) => {
6565
isIOS ? RNCallKeepModule.endCall(uuid) : RNCallKeepModule.endCall();
66-
}
66+
};
6767

68-
endAllCalls() {
68+
endAllCalls = () => {
6969
isIOS ? RNCallKeepModule.endAllCalls() : RNCallKeepModule.endCall();
70-
}
70+
};
7171

72-
supportConnectionService() {
73-
return supportConnectionService;
74-
}
72+
supportConnectionService = () => supportConnectionService;
7573

76-
async hasPhoneAccount() {
77-
return isIOS ? true : await RNCallKeepModule.hasPhoneAccount();
78-
}
74+
hasPhoneAccount = async () =>
75+
isIOS ? true : await RNCallKeepModule.hasPhoneAccount();
7976

80-
setMutedCAll(uuid, muted) {
77+
setMutedCAll = (uuid, muted) => {
8178
if (!isIOS) {
8279
// Can't mute on Android
8380
return;
8481
}
8582

8683
RNCallKeepModule.setMutedCall(uuid, muted);
87-
}
84+
};
8885

89-
checkIfBusy() {
90-
return Platform.OS === 'ios'
86+
checkIfBusy = () =>
87+
Platform.OS === 'ios'
9188
? RNCallKeepModule.checkIfBusy()
9289
: Promise.reject('RNCallKeep.checkIfBusy was called from unsupported OS');
93-
};
9490

95-
checkSpeaker() {
96-
return Platform.OS === 'ios'
91+
checkSpeaker = () =>
92+
Platform.OS === 'ios'
9793
? RNCallKeepModule.checkSpeaker()
9894
: Promise.reject('RNCallKeep.checkSpeaker was called from unsupported OS');
99-
}
10095

101-
setActive = (state) => {
96+
setAvailable = (state) => {
10297
if (isIOS) {
10398
return;
10499
}
105100

106101
// Tell android that we are able to make outgoing calls
107-
RNCallKeepModule.setActive(state);
108-
}
102+
RNCallKeepModule.setAvailable(state);
103+
};
109104

110-
_setupIOS(options) {
105+
setCurrentCallActive = () => {
106+
if (isIOS) {
107+
return;
108+
}
109+
110+
RNCallKeepModule.setCurrentCallActive();
111+
};
112+
113+
_setupIOS = (options) => {
111114
if (!options.appName) {
112115
throw new Error('RNCallKeep.setup: option "appName" is required');
113116
}
@@ -116,9 +119,9 @@ class RNCallKeep {
116119
}
117120

118121
RNCallKeepModule.setup(options);
119-
}
122+
};
120123

121-
async _setupAndroid(options) {
124+
_setupAndroid = async (options) => {
122125
const hasAccount = await RNCallKeepModule.checkPhoneAccountPermission();
123126
if (hasAccount) {
124127
return;
@@ -139,7 +142,7 @@ class RNCallKeep {
139142
],
140143
{ cancelable: true },
141144
);
142-
}
145+
};
143146

144147
/*
145148
static holdCall(uuid, onHold) {

0 commit comments

Comments
 (0)