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

30 lines
763 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;
public class MopEventStream implements EventChannel.StreamHandler {
EventChannel.EventSink mEventSlink;
@Override
public void onListen(Object o, EventChannel.EventSink eventSink) {
mEventSlink = eventSink;
}
@Override
public void onCancel(Object o) {
mEventSlink = null;
}
public void send(String channel,String event,Object body) {
if (mEventSlink != null) {
Map<String,Object> map = new HashMap<>();
map.put("channel",channel);
map.put("event",event);
map.put("body",body);
mEventSlink.success(map);
}
}
}