cordova-plugin-salus-call 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Plugin proprietário do Salus para integrar a interface Cordova ao ciclo de vida
7
7
  ## Instalação
8
8
 
9
9
  ```xml
10
- <plugin name="cordova-plugin-salus-call" spec="0.2.1" />
10
+ <plugin name="cordova-plugin-salus-call" spec="0.2.3" />
11
11
  ```
12
12
 
13
13
  ## API
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-salus-call",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Integração nativa de chamadas VoIP para o aplicativo Salus.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "engines": {
31
31
  "cordovaDependencies": {
32
- "0.2.1": {
32
+ "0.2.3": {
33
33
  "cordova": ">=12.0.0",
34
34
  "cordova-android": ">=14.0.0"
35
35
  }
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-plugin-salus-call"
5
- version="0.2.1">
5
+ version="0.2.3">
6
6
  <name>Salus Call</name>
7
7
  <description>Ponte nativa para chamadas de interfone do Salus.</description>
8
8
  <license>UNLICENSED</license>
@@ -15,6 +15,8 @@
15
15
  <config-file target="AndroidManifest.xml" parent="/manifest">
16
16
  <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
17
17
  <uses-permission android:name="android.permission.VIBRATE" />
18
+ <uses-permission android:name="android.permission.RECORD_AUDIO" />
19
+ <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
18
20
  </config-file>
19
21
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
20
22
  <provider
@@ -2,6 +2,11 @@ package br.com.salus.call;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.content.Intent;
5
+ import android.media.AudioAttributes;
6
+ import android.media.AudioFocusRequest;
7
+ import android.media.AudioDeviceInfo;
8
+ import android.media.AudioManager;
9
+ import android.os.Build;
5
10
 
6
11
  import org.apache.cordova.CallbackContext;
7
12
  import org.apache.cordova.CordovaInterface;
@@ -15,6 +20,8 @@ import org.json.JSONObject;
15
20
  public class SalusCallPlugin extends CordovaPlugin {
16
21
  private static SalusCallPlugin activeInstance;
17
22
  private CallbackContext eventCallback;
23
+ private AudioManager audioManager;
24
+ private AudioFocusRequest audioFocusRequest;
18
25
 
19
26
  @Override
20
27
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
@@ -47,17 +54,28 @@ public class SalusCallPlugin extends CordovaPlugin {
47
54
  callback.success(call);
48
55
  return true;
49
56
  case "answer":
57
+ prepareAudioSession();
50
58
  handleLocalAction("answered", args.optString(0, ""), "answered_in_app");
51
59
  callback.success();
52
60
  return true;
53
61
  case "reject":
62
+ releaseAudioSession();
54
63
  handleLocalAction("rejected", args.optString(0, ""), args.optString(1, "declined"));
55
64
  callback.success();
56
65
  return true;
57
66
  case "hangup":
67
+ releaseAudioSession();
58
68
  handleLocalAction("ended", args.optString(0, ""), args.optString(1, "local_hangup"));
59
69
  callback.success();
60
70
  return true;
71
+ case "prepareAudio":
72
+ prepareAudioSession();
73
+ callback.success();
74
+ return true;
75
+ case "releaseAudio":
76
+ releaseAudioSession();
77
+ callback.success();
78
+ return true;
61
79
  case "startCall":
62
80
  case "setMuted":
63
81
  case "setVideoEnabled":
@@ -76,6 +94,7 @@ public class SalusCallPlugin extends CordovaPlugin {
76
94
  result.put("audio", false);
77
95
  result.put("video", false);
78
96
  result.put("incomingCallUi", true);
97
+ result.put("audioSession", true);
79
98
  return result;
80
99
  }
81
100
 
@@ -110,6 +129,7 @@ public class SalusCallPlugin extends CordovaPlugin {
110
129
 
111
130
  @Override
112
131
  public void onDestroy() {
132
+ releaseAudioSession();
113
133
  if (activeInstance == this) activeInstance = null;
114
134
  super.onDestroy();
115
135
  }
@@ -147,6 +167,7 @@ public class SalusCallPlugin extends CordovaPlugin {
147
167
 
148
168
  JSONObject event = new JSONObject();
149
169
  if ("answer".equals(action)) {
170
+ prepareAudioSession();
150
171
  event.put("type", "answered");
151
172
  event.put("reason", "system_answer");
152
173
  } else {
@@ -159,4 +180,57 @@ public class SalusCallPlugin extends CordovaPlugin {
159
180
  dispatchEvent(cordova.getContext(), event);
160
181
  } catch (Exception ignored) {}
161
182
  }
183
+
184
+ private void prepareAudioSession() {
185
+ if (audioManager != null) return;
186
+ audioManager = (AudioManager) cordova.getContext().getSystemService(Context.AUDIO_SERVICE);
187
+ if (audioManager == null) return;
188
+
189
+ audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
190
+ routeToEarpiece();
191
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
192
+ AudioAttributes attributes = new AudioAttributes.Builder()
193
+ .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
194
+ .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
195
+ .build();
196
+ audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
197
+ .setAudioAttributes(attributes)
198
+ .setAcceptsDelayedFocusGain(false)
199
+ .setOnAudioFocusChangeListener(focusChange -> {})
200
+ .build();
201
+ audioManager.requestAudioFocus(audioFocusRequest);
202
+ } else {
203
+ audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
204
+ }
205
+ }
206
+
207
+ private void releaseAudioSession() {
208
+ if (audioManager == null) return;
209
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && audioFocusRequest != null) {
210
+ audioManager.abandonAudioFocusRequest(audioFocusRequest);
211
+ } else {
212
+ audioManager.abandonAudioFocus(null);
213
+ }
214
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
215
+ audioManager.clearCommunicationDevice();
216
+ } else {
217
+ audioManager.setSpeakerphoneOn(false);
218
+ }
219
+ audioManager.setMode(AudioManager.MODE_NORMAL);
220
+ audioFocusRequest = null;
221
+ audioManager = null;
222
+ }
223
+
224
+ private void routeToEarpiece() {
225
+ if (audioManager == null) return;
226
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
227
+ for (AudioDeviceInfo device : audioManager.getAvailableCommunicationDevices()) {
228
+ if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {
229
+ audioManager.setCommunicationDevice(device);
230
+ return;
231
+ }
232
+ }
233
+ }
234
+ audioManager.setSpeakerphoneOn(false);
235
+ }
162
236
  }
package/www/SalusCall.js CHANGED
@@ -64,6 +64,14 @@ module.exports = {
64
64
  return callNative('hangup', [callId, reason || 'local_hangup']);
65
65
  },
66
66
 
67
+ prepareAudio: function() {
68
+ return callNative('prepareAudio');
69
+ },
70
+
71
+ releaseAudio: function() {
72
+ return callNative('releaseAudio');
73
+ },
74
+
67
75
  setMuted: function(muted) {
68
76
  return callNative('setMuted', [Boolean(muted)]);
69
77
  },