8000 Merge pull request #183 from cloudwebrtc/0.2.6 · sinkync/flutter-webrtc@44d0ce1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 44d0ce1

Browse files
authored
Merge pull request flutter-webrtc#183 from cloudwebrtc/0.2.6
0.2.6
2 parents 2b301a7 + 608e6c1 commit 44d0ce1

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
## Changelog
22

33
--------------------------------------------
4+
5+
[0.2.6] - 2020.02.03
6+
7+
* Fixed the interruption of the Bluetooth headset that was playing music after the plugin started.
8+
49
[0.2.4] - 2020.02.03
510

611
* Fixed bug.

android/src/main/java/com/cloudwebrtc/webrtc/FlutterWebRTCPlugin.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,42 @@ private void onAudioManagerDevicesChanged(
158158
// TODO(henrika): add callback handler.
159159
}
160160

161+
private void startAudioManager() {
162+
if(rtcAudioManager != null)
163+
return;
164+
165+
rtcAudioManager = RTCAudioManager.create(registrar.context());
166+
// Store existing audio settings and change audio mode to
167+
// MODE_IN_COMMUNICATION for best possible VoIP performance.
168+
Log.d(TAG, "Starting the audio manager...");
169+
rtcAudioManager.start(new RTCAudioManager.AudioManagerEvents() {
170+
// This method will be called each time the number of available audio
171+
// devices has changed.
172+
@Override
173+
public void onAudioDeviceChanged(
174+
RTCAudioManager.AudioDevice audioDevice, Set<RTCAudioManager.AudioDevice> availableAudioDevices) {
175+
onAudioManagerDevicesChanged(audioDevice, availableAudioDevices);
176+
}
177+
});
178+
}
179+
180+
private void stopAudioManager() {
181+
if (rtcAudioManager != null) {
182+
Log.d(TAG, "Stoping the audio manager...");
183+
rtcAudioManager.stop();
184+
rtcAudioManager = null;
185+
}
186+
}
187+
188+
// This method is called when the audio manager reports audio device change,
189+
// e.g. from wired headset to speakerphone.
190+
private void onAudioManagerDevicesChanged(
191+
final RTCAudioManager.AudioDevice device, final Set<RTCAudioManager.AudioDevice> availableDevices) {
192+
Log.d(TAG, "onAudioManagerDevicesChanged: " + availableDevices + ", "
193+
+ "selected: " + device);
194+
// TODO(henrika): add callback handler.
195+
}
196+
161197
@Override
162198
public void onMethodCall(MethodCall call, Result notSafeResult) {
163199
final AnyThreadResult result = new AnyThreadResult(notSafeResult);
@@ -297,7 +333,7 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
297333
result.success(null);
298334
} else if(call.method.equals("peerConnectionDispose")){
299335
String peerConnectionId = call.argument("peerConnectionId");
300-
peerConnectionClose(peerConnectionId);
336+
peerConnectionDispose(peerConnectionId);
301337
result.success(null);
302338
}else if (call.method.equals("createVideoRenderer")) {
303339
TextureRegistry.SurfaceTextureEntry entry = textures.createSurfaceTexture();
@@ -362,6 +398,9 @@ public void onMethodCall(MethodCall call, Result notSafeResult) {
362398
result.success(null);
363399
} else if (call.method.equals("enableSpeakerphone")) {
364400
boolean enable = call.argument("enable");
401+
if(rtcAudioManager == null ){
402+
startAudioManager();
403+
}
365404
rtcAudioManager.setSpeakerphoneOn(enable);
366405
result.success(null);
367406
} else if(call.method.equals("getDisplayMedia")) {
@@ -723,6 +762,9 @@ public String peerConnectionInit(
723762
parseMediaConstraints(constraints),
724763
observer);
725764
observer.setPeerConnection(peerConnection);
765+
if(mPeerConnectionObservers.size() == 0) {
766+
startAudioManager();
767+
}
726768
mPeerConnectionObservers.put(peerConnectionId, observer);
727769
return peerConnectionId;
728770
}
@@ -1285,6 +1327,9 @@ public void peerConnectionDispose(final String id) {
12851327
pco.dispose();
12861328
mPeerConnectionObservers.remove(id);
12871329
}
1330+
if(mPeerConnectionObservers.size() == 0) {
1331+
stopAudioManager();
1332+
}
12881333
}
12891334

12901335
public void mediaStreamRelease(final String id) {

android/src/main/java/com/cloudwebrtc/webrtc/PeerConnectionObserver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void close() {
8282
remoteTracks.clear();
8383
dataChannels.clear();
8484
}
85-
void dispose(){
85+
86+
void dispose() {
8687
this.close();
8788
peerConnection.dispose();
8889
eventChannel.setStreamHandler(null);

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_webrtc
2-
description: Flutter WebRTC plugin for iOS/Android.
3-
version: 0.2.4
2+
description: Flutter WebRTC plugin for iOS/Android/Destkop/Web.
3+
version: 0.2.6
44
homepage: https://github.com/cloudwebrtc/flutter-webrtc
55

66
dependencies:

0 commit comments

Comments
 (0)
0