|
7 | 7 | #include <VersionHelpers.h>
|
8 | 8 |
|
9 | 9 | #include <flutter/method_channel.h>
|
| 10 | +#include <flutter/event_channel.h> |
10 | 11 | #include <flutter/plugin_registrar_windows.h>
|
11 | 12 | #include <flutter/standard_method_codec.h>
|
12 | 13 |
|
13 | 14 | #include <map>
|
14 | 15 | #include <memory>
|
15 | 16 | #include <sstream>
|
16 | 17 |
|
17 |
| -#include <ZegoExpressSDK.h> |
18 |
| -using namespace ZEGO; |
| 18 | +#include "internal/ZegoExpressEngineMethodHandler.h" |
| 19 | +#include "internal/ZegoExpressEngineEventHandler.h" |
19 | 20 |
|
20 |
| -namespace { |
| 21 | +//namespace { |
21 | 22 |
|
22 |
| -class ZegoExpressEnginePlugin : public flutter::Plugin { |
23 |
| - public: |
24 |
| - static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); |
| 23 | +class ZegoExpressEnginePlugin : public flutter::Plugin, public flutter::StreamHandler<flutter::EncodableValue> { |
| 24 | + |
| 25 | +public: |
| 26 | + static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar); |
25 | 27 |
|
26 |
| - ZegoExpressEnginePlugin(); |
| 28 | + ZegoExpressEnginePlugin(); |
27 | 29 |
|
28 |
| - virtual ~ZegoExpressEnginePlugin(); |
| 30 | + |
| 31 | + virtual ~ZegoExpressEnginePlugin(); |
| 32 | + |
| 33 | +protected: |
| 34 | + virtual std::unique_ptr<flutter::StreamHandlerError<flutter::EncodableValue>> OnListenInternal( |
| 35 | + const flutter::EncodableValue* arguments, |
| 36 | + std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&& events) override; |
| 37 | + |
| 38 | + // Implementation of the public interface, to be provided by subclasses. |
| 39 | + virtual std::unique_ptr<flutter::StreamHandlerError<flutter::EncodableValue>> OnCancelInternal( |
| 40 | + const flutter::EncodableValue* arguments) override; |
| 41 | + |
| 42 | + |
| 43 | +private: |
| 44 | + // Called when a method is called on this plugin's channel from Dart. |
| 45 | + void HandleMethodCall(const flutter::MethodCall<flutter::EncodableValue> &method_call, |
| 46 | + std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result); |
29 | 47 |
|
30 |
| - private: |
31 |
| - // Called when a method is called on this plugin's channel from Dart. |
32 |
| - void HandleMethodCall( |
33 |
| - const flutter::MethodCall<flutter::EncodableValue> &method_call, |
34 |
| - std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result); |
35 | 48 | };
|
36 | 49 |
|
37 | 50 | // static
|
38 |
| -void ZegoExpressEnginePlugin::RegisterWithRegistrar( |
39 |
| - flutter::PluginRegistrarWindows *registrar) { |
40 |
| - auto channel = |
41 |
| - std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>( |
42 |
| - registrar->messenger(), "plugins.zego.im/zego_express_engine", |
43 |
| - &flutter::StandardMethodCodec::GetInstance()); |
| 51 | +void ZegoExpressEnginePlugin::RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar) { |
| 52 | + auto methodChannel = std::make_unique<flutter::MethodChannel<flutter::EncodableValue>> |
| 53 | + (registrar->messenger(), "plugins.zego.im/zego_express_engine", &flutter::StandardMethodCodec::GetInstance()); |
44 | 54 |
|
45 |
| - auto plugin = std::make_unique<ZegoExpressEnginePlugin>(); |
| 55 | + auto eventChannel = std::make_unique<flutter::EventChannel<flutter::EncodableValue>> |
| 56 | + (registrar->messenger(), "plugins.zego.im/zego_express_event_handler", &flutter::StandardMethodCodec::GetInstance()); |
46 | 57 |
|
47 |
| - channel->SetMethodCallHandler( |
48 |
| - [plugin_pointer = plugin.get()](const auto &call, auto result) { |
49 |
| - plugin_pointer->HandleMethodCall(call, std::move(result)); |
50 |
| - }); |
| 58 | + auto plugin = std::make_unique<ZegoExpressEnginePlugin>(); |
51 | 59 |
|
52 |
| - registrar->AddPlugin(std::move(plugin)); |
| 60 | + eventChannel->SetStreamHandler(std::move(plugin)); |
| 61 | + |
| 62 | + methodChannel->SetMethodCallHandler( |
| 63 | + [plugin_pointer = plugin.get()](const auto &call, auto result) { |
| 64 | + plugin_pointer->HandleMethodCall(call, std::move(result)); |
| 65 | + }); |
| 66 | + |
| 67 | + |
| 68 | + registrar->AddPlugin(std::move(plugin)); |
53 | 69 | }
|
54 | 70 |
|
55 | 71 | ZegoExpressEnginePlugin::ZegoExpressEnginePlugin() {}
|
56 | 72 |
|
57 | 73 | ZegoExpressEnginePlugin::~ZegoExpressEnginePlugin() {}
|
58 | 74 |
|
| 75 | +std::unique_ptr<flutter::StreamHandlerError<flutter::EncodableValue>> ZegoExpressEnginePlugin::OnListenInternal( |
| 76 | + const flutter::EncodableValue* arguments, |
| 77 | + std::unique_ptr<flutter::EventSink<flutter::EncodableValue>>&& events) { |
| 78 | + |
| 79 | + ZegoExpressEngineEventHandler::getInstance().setEventSink(std::move(events)); |
| 80 | + std::cout << "on listen event" << std::endl; |
| 81 | + |
| 82 | + return nullptr; |
| 83 | +} |
| 84 | + |
| 85 | +std::unique_ptr<flutter::StreamHandlerError<flutter::EncodableValue>> ZegoExpressEnginePlugin::OnCancelInternal( |
| 86 | + const flutter::EncodableValue* arguments) { |
| 87 | + |
| 88 | + ZegoExpressEngineEventHandler::getInstance().clearEventSink(); |
| 89 | + std::cout << "on listen event" << std::endl; |
| 90 | + |
| 91 | + return nullptr; |
| 92 | +} |
| 93 | + |
59 | 94 | void ZegoExpressEnginePlugin::HandleMethodCall(
|
60 | 95 | const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
61 | 96 | std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
62 | 97 | if(method_call.method_name() == "getVersion") {
|
63 | 98 |
|
64 |
| - result->Success(flutter::EncodableValue(EXPRESS::ZegoExpressSDK::getVersion())); |
| 99 | + auto version = ZegoExpressEngineMethodHandler::getInstance().getVersion(); |
| 100 | + result->Success(flutter::EncodableValue(version)); |
65 | 101 | } else {
|
66 | 102 | result->NotImplemented();
|
67 | 103 | }
|
68 | 104 | }
|
69 | 105 |
|
70 |
| -} // namespace |
| 106 | +//} // namespace |
71 | 107 |
|
72 | 108 | void ZegoExpressEnginePluginRegisterWithRegistrar(
|
73 | 109 | FlutterDesktopPluginRegistrarRef registrar) {
|
|
0 commit comments