|
1 | 1 | package com.cloudwebrtc.webrtc;
|
2 | 2 |
|
3 |
| -import java.nio.charset.Charset; |
4 |
| -import android.util.Base64; |
| 3 | +import com.cloudwebrtc.webrtc.utils.AnyThreadSink; |
| 4 | +import com.cloudwebrtc.webrtc.utils.ConstraintsMap; |
5 | 5 |
|
6 | 6 | import org.webrtc.DataChannel;
|
| 7 | + |
| 8 | +import java.nio.charset.Charset; |
| 9 | + |
| 10 | +import io.flutter.plugin.common.BinaryMessenger; |
7 | 11 | import io.flutter.plugin.common.EventChannel;
|
8 |
| -import com.cloudwebrtc.webrtc.utils.AnyThreadSink; |
9 |
| -import com.cloudwebrtc.webrtc.utils.ConstraintsMap; |
10 | 12 |
|
11 | 13 | class DataChannelObserver implements DataChannel.Observer, EventChannel.StreamHandler {
|
| 14 | + |
12 | 15 | private final int mId;
|
13 | 16 | private final DataChannel mDataChannel;
|
14 |
| - private final String peerConnectionId; |
15 |
| - private final FlutterWebRTCPlugin plugin; |
| 17 | + |
16 | 18 | private EventChannel eventChannel;
|
17 | 19 | private EventChannel.EventSink eventSink;
|
18 | 20 |
|
19 |
| - DataChannelObserver(FlutterWebRTCPlugin plugin, String peerConnectionId, int id, DataChannel dataChannel) { |
20 |
| - this.peerConnectionId = peerConnectionId; |
| 21 | + DataChannelObserver(BinaryMessenger messenger, String peerConnectionId, int id, |
| 22 | + DataChannel dataChannel) { |
21 | 23 | mId = id;
|
22 | 24 | mDataChannel = dataChannel;
|
23 |
| - this.plugin = plugin; |
24 |
| - this.eventChannel = |
25 |
| - new EventChannel( |
26 |
| - plugin.registrar().messenger(), |
27 |
| - "FlutterWebRTC/dataChannelEvent" + peerConnectionId + String.valueOf(id)); |
| 25 | + eventChannel = |
| 26 | + new EventChannel(messenger, "FlutterWebRTC/dataChannelEvent" + peerConnectionId + id); |
28 | 27 | eventChannel.setStreamHandler(this);
|
29 | 28 | }
|
30 | 29 |
|
@@ -53,7 +52,8 @@ public void onCancel(Object o) {
|
53 | 52 | }
|
54 | 53 |
|
55 | 54 | @Override
|
56 |
| - public void onBufferedAmountChange(long amount) { } |
| 55 | + public void onBufferedAmountChange(long amount) { |
| 56 | + } |
57 | 57 |
|
58 | 58 | @Override
|
59 | 59 | public void onStateChange() {
|
@@ -89,8 +89,9 @@ public void onMessage(DataChannel.Buffer buffer) {
|
89 | 89 | sendEvent(params);
|
90 | 90 | }
|
91 | 91 |
|
92 |
| - void sendEvent(ConstraintsMap params) { |
93 |
| - if(eventSink != null) |
| 92 | + private void sendEvent(ConstraintsMap params) { |
| 93 | + if (eventSink != null) { |
94 | 94 | eventSink.success(params.toMap());
|
| 95 | + } |
95 | 96 | }
|
96 | 97 | }
|
0 commit comments