mop-flutter-sdk/android/src/main/java/com/finogeeks/mop/MopEventStream.java

31 lines
769 B
Dart
Raw Normal View History

2020-02-27 22:59:31 +08:00
package com.finogeeks.mop;
import java.util.HashMap;
import java.util.Map;
import io.flutter.plugin.common.EventChannel;
2021-10-10 23:50:23 +08:00
public class MopEventStream implements EventChannel.StreamHandler {
2020-02-27 22:59:31 +08:00
EventChannel.EventSink mEventSlink;
2021-10-10 23:50:23 +08:00
2020-02-27 22:59:31 +08:00
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
mEventSlink = eventSink;
}
@Override
public void onCancel(Object o) {
mEventSlink = null;
}
2021-10-10 23:50:23 +08:00
public void send(String channel, String event, Object body) {
2020-02-27 22:59:31 +08:00
if (mEventSlink != null) {
2021-10-10 23:50:23 +08:00
Map<String, Object> map = new HashMap<>();
map.put("channel", channel);
map.put("event", event);
map.put("body", body);
2020-02-27 22:59:31 +08:00
mEventSlink.success(map);
}
}
}