23
23
import com .cloudwebrtc .webrtc .record .AudioChannel ;
24
24
import com .cloudwebrtc .webrtc .record .FrameCapturer ;
25
25
import com .cloudwebrtc .webrtc .utils .AnyThreadResult ;
26
+ import com .cloudwebrtc .webrtc .utils .AnyThreadSink ;
26
27
import com .cloudwebrtc .webrtc .utils .Callback ;
27
28
import com .cloudwebrtc .webrtc .utils .ConstraintsArray ;
28
29
import com .cloudwebrtc .webrtc .utils .ConstraintsMap ;
86
87
import io .flutter .view .TextureRegistry ;
87
88
import io .flutter .view .TextureRegistry .SurfaceTextureEntry ;
88
89
89
- public class MethodCallHandlerImpl implements MethodCallHandler , StateProvider {
90
+ public class MethodCallHandlerImpl implements MethodCallHandler , StateProvider , EventChannel . StreamHandler {
90
91
static public final String TAG = "FlutterWebRTCPlugin" ;
91
92
static public final String NEXTAG = "NexWebRTCPlugin" ;
92
93
@@ -111,10 +112,16 @@ public class MethodCallHandlerImpl implements MethodCallHandler, StateProvider {
111
112
112
113
private Activity activity ;
113
114
115
+ private EventChannel eventChannel ;
116
+ private EventChannel .EventSink eventSink ;
117
+
114
118
MethodCallHandlerImpl (Context context , BinaryMessenger messenger , TextureRegistry textureRegistry ) {
115
119
this .context = context ;
116
120
this .textures = textureRegistry ;
117
121
this .messenger = messenger ;
122
+
123
+ eventChannel = new EventChannel ( messenger ,"FlutterWebRTC.Event" );
124
+ eventChannel .setStreamHandler (this );
118
125
}
119
126
120
127
static private void resultError (String method , String error , Result result ) {
@@ -137,6 +144,18 @@ void dispose() {
137
144
peerConnectionDispose (connection );
138
145
}
139
146
mPeerConnectionObservers .clear ();
147
+
148
+ eventChannel .setStreamHandler (null );
149
+ }
150
+
151
+ @ Override
152
+ public void onListen (Object arguments , EventChannel .EventSink events ) {
153
+ eventSink = new AnyThreadSink (events );
154
+ }
155
+
156
+ @ Override
157
+ public void onCancel (Object arguments ) {
158
+ eventSink = null ;
140
159
}
141
160
142
161
private void ensureInitialized () {
@@ -2008,9 +2027,9 @@ private void initAudioSwitch(){
2008
2027
AudioSwitchManager .instance .audioDeviceChangeListener = (devices , currentDevice ) -> {
2009
2028
Log .w (TAG , "audioFocusChangeListener " + devices + " " + currentDevice );
2010
2029
sendLog ("audioDeviceChangeListener devices" + devices .toString () + " currentDevice" + currentDevice .toString ());
2011
- // ConstraintsMap params = new ConstraintsMap();
2012
- // params.putString("event", "onDeviceChange");
2013
- // sendEvent(params.toMap());
2030
+ ConstraintsMap params = new ConstraintsMap ();
2031
+ params .putString ("event" , "onDeviceChange" );
2032
+ sendEvent (params .toMap ());
2014
2033
return null ;
2015
2034
};
2016
2035
AudioSwitchManager .instance .audioFocusChangeListener = (focusChange ) -> {
@@ -2026,10 +2045,32 @@ private void initAudioSwitch(){
2026
2045
//AUDIOFOCUS_LOSS (非フォーカス時)
2027
2046
sendLog ("AUDIOFOCUS_LOSS availableAudioDevices" + AudioSwitchManager .instance .availableAudioDevices ().toString () + " selectedAudioDevice" + AudioSwitchManager .instance .selectedAudioDevice ().toString ());
2028
2047
}
2048
+ onAudioFocusChange (Integer .toString (focusChange ));
2029
2049
};
2030
2050
}
2031
2051
2052
+ public void sendEvent (Object event ) {
2053
+ if (eventSink != null ) {
2054
+ eventSink .success (event );
2055
+ }
2056
+ }
2057
+
2032
2058
private void sendLog (String value ){
2033
2059
Log .d (NEXTAG , value );
2060
+ if (eventSink != null ) {
2061
+ ConstraintsMap params = new ConstraintsMap ();
2062
+ params .putString ("event" , "onLogger" );
2063
+ params .putString ("value" , value );
2064
+ eventSink .success (params .toMap ());
2065
+ }
2066
+ }
2067
+
2068
+ private void onAudioFocusChange (String value ){
2069
+ if (eventSink != null ) {
2070
+ ConstraintsMap params = new ConstraintsMap ();
2071
+ params .putString ("event" , "onAudioFocusChange" );
2072
+ params .putString ("value" , value );
2073
+ eventSink .success (params .toMap ());
2074
+ }
2034
2075
}
2035
2076
}
0 commit comments