cordova-plugin-salus-call 0.2.1 → 0.2.2

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.2" />
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.2",
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.2": {
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.2">
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,10 @@ 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.AudioManager;
8
+ import android.os.Build;
5
9
 
6
10
  import org.apache.cordova.CallbackContext;
7
11
  import org.apache.cordova.CordovaInterface;
@@ -15,6 +19,8 @@ import org.json.JSONObject;
15
19
  public class SalusCallPlugin extends CordovaPlugin {
16
20
  private static SalusCallPlugin activeInstance;
17
21
  private CallbackContext eventCallback;
22
+ private AudioManager audioManager;
23
+ private AudioFocusRequest audioFocusRequest;
18
24
 
19
25
  @Override
20
26
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {
@@ -47,17 +53,28 @@ public class SalusCallPlugin extends CordovaPlugin {
47
53
  callback.success(call);
48
54
  return true;
49
55
  case "answer":
56
+ prepareAudioSession();
50
57
  handleLocalAction("answered", args.optString(0, ""), "answered_in_app");
51
58
  callback.success();
52
59
  return true;
53
60
  case "reject":
61
+ releaseAudioSession();
54
62
  handleLocalAction("rejected", args.optString(0, ""), args.optString(1, "declined"));
55
63
  callback.success();
56
64
  return true;
57
65
  case "hangup":
66
+ releaseAudioSession();
58
67
  handleLocalAction("ended", args.optString(0, ""), args.optString(1, "local_hangup"));
59
68
  callback.success();
60
69
  return true;
70
+ case "prepareAudio":
71
+ prepareAudioSession();
72
+ callback.success();
73
+ return true;
74
+ case "releaseAudio":
75
+ releaseAudioSession();
76
+ callback.success();
77
+ return true;
61
78
  case "startCall":
62
79
  case "setMuted":
63
80
  case "setVideoEnabled":
@@ -76,6 +93,7 @@ public class SalusCallPlugin extends CordovaPlugin {
76
93
  result.put("audio", false);
77
94
  result.put("video", false);
78
95
  result.put("incomingCallUi", true);
96
+ result.put("audioSession", true);
79
97
  return result;
80
98
  }
81
99
 
@@ -110,6 +128,7 @@ public class SalusCallPlugin extends CordovaPlugin {
110
128
 
111
129
  @Override
112
130
  public void onDestroy() {
131
+ releaseAudioSession();
113
132
  if (activeInstance == this) activeInstance = null;
114
133
  super.onDestroy();
115
134
  }
@@ -147,6 +166,7 @@ public class SalusCallPlugin extends CordovaPlugin {
147
166
 
148
167
  JSONObject event = new JSONObject();
149
168
  if ("answer".equals(action)) {
169
+ prepareAudioSession();
150
170
  event.put("type", "answered");
151
171
  event.put("reason", "system_answer");
152
172
  } else {
@@ -159,4 +179,38 @@ public class SalusCallPlugin extends CordovaPlugin {
159
179
  dispatchEvent(cordova.getContext(), event);
160
180
  } catch (Exception ignored) {}
161
181
  }
182
+
183
+ private void prepareAudioSession() {
184
+ if (audioManager != null) return;
185
+ audioManager = (AudioManager) cordova.getContext().getSystemService(Context.AUDIO_SERVICE);
186
+ if (audioManager == null) return;
187
+
188
+ audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
189
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
190
+ AudioAttributes attributes = new AudioAttributes.Builder()
191
+ .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
192
+ .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
193
+ .build();
194
+ audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
195
+ .setAudioAttributes(attributes)
196
+ .setAcceptsDelayedFocusGain(false)
197
+ .setOnAudioFocusChangeListener(focusChange -> {})
198
+ .build();
199
+ audioManager.requestAudioFocus(audioFocusRequest);
200
+ } else {
201
+ audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
202
+ }
203
+ }
204
+
205
+ private void releaseAudioSession() {
206
+ if (audioManager == null) return;
207
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && audioFocusRequest != null) {
208
+ audioManager.abandonAudioFocusRequest(audioFocusRequest);
209
+ } else {
210
+ audioManager.abandonAudioFocus(null);
211
+ }
212
+ audioManager.setMode(AudioManager.MODE_NORMAL);
213
+ audioFocusRequest = null;
214
+ audioManager = null;
215
+ }
162
216
  }
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
  },