|
1 |
| -#include "flutter_webrtc/flutter_web_r_t_c_plugin.h" |
2 |
| - |
3 |
| -#include <flutter/standard_message_codec.h> |
4 |
| - |
5 |
| -#include "flutter_webrtc.h" |
6 |
| - |
7 |
| -const char *kChannelName = "FlutterWebRTC.Method"; |
8 |
| - |
9 |
| -namespace flutter_webrtc_plugin { |
10 |
| - |
11 |
| -// A webrtc plugin for windows/linux. |
12 |
| -class FlutterWebRTCPluginImpl : public FlutterWebRTCPlugin { |
13 |
| - public: |
14 |
| - static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) { |
15 |
| - auto channel = std::make_unique<flutter::MethodChannel<EncodableValue>>( |
16 |
| - registrar->messenger(), kChannelName, |
17 |
| - &flutter::StandardMethodCodec::GetInstance()); |
18 |
| - |
19 |
| - auto *channel_pointer = channel.get(); |
20 |
| - |
21 |
| - // Uses new instead of make_unique due to private constructor. |
22 |
| - std::unique_ptr<FlutterWebRTCPluginImpl> plugin( |
23 |
| - new FlutterWebRTCPluginImpl(registrar, std::move(channel))); |
24 |
| - |
25 |
| - channel_pointer->SetMethodCallHandler( |
26 |
| - [plugin_pointer = plugin.get()](const auto &call, auto result) { |
27 |
| - plugin_pointer->HandleMethodCall(call, std::move(result)); |
28 |
| - }); |
29 |
| - |
30 |
| - registrar->AddPlugin(std::move(plugin)); |
31 |
| - } |
32 |
| - |
33 |
| - virtual ~FlutterWebRTCPluginImpl() {} |
34 |
| - |
35 |
| - flutter::BinaryMessenger *messenger() { return messenger_; } |
36 |
| - |
37 |
| - flutter::TextureRegistrar *textures() { return textures_; } |
38 |
| - |
39 |
| - private: |
40 |
| - // Creates a plugin that communicates on the given channel. |
41 |
| - FlutterWebRTCPluginImpl( |
42 |
| - flutter::PluginRegistrar *registrar, |
43 |
| - std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel) |
44 |
| - : channel_(std::move(channel)), |
45 |
| - messenger_(registrar->messenger()), |
46 |
| - textures_(registrar->texture_registrar()) { |
47 |
| - webrtc_ = std::make_unique<FlutterWebRTC>(this); |
48 |
| - } |
49 |
| - |
50 |
| - // Called when a method is called on |channel_|; |
51 |
| - void HandleMethodCall( |
52 |
| - const flutter::MethodCall<EncodableValue> &method_call, |
53 |
| - std::unique_ptr<flutter::MethodResult<EncodableValue>> result) { |
54 |
| - // handle method call and forward to webrtc native sdk. |
55 |
| - webrtc_->HandleMethodCall(method_call, std::move(result)); |
56 |
| - } |
57 |
| - |
58 |
| - private: |
59 |
| - std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel_; |
60 |
| - std::unique_ptr<FlutterWebRTC> webrtc_; |
61 |
| - flutter::BinaryMessenger *messenger_; |
62 |
| - flutter::TextureRegistrar *textures_; |
63 |
| -}; |
64 |
| - |
65 |
| -} // namespace flutter_webrtc_plugin |
66 |
| - |
67 |
| -void FlutterWebRTCPluginRegisterWithRegistrar( |
68 |
| - FlutterDesktopPluginRegistrarRef registrar) { |
69 |
| - static auto *plugin_registrar = new flutter::PluginRegistrar(registrar); |
70 |
| - flutter_webrtc_plugin::FlutterWebRTCPluginImpl::RegisterWithRegistrar( |
71 |
| - plugin_registrar); |
72 |
| -} |
| 1 | +#include "flutter_webrtc/flutter_web_r_t_c_plugin.h" |
| 2 | + |
| 3 | +#include <flutter/standard_message_codec.h> |
| 4 | + |
| 5 | +#include "flutter_webrtc.h" |
| 6 | + |
| 7 | +const char *kChannelName = "FlutterWebRTC.Method"; |
| 8 | + |
| 9 | +namespace flutter_webrtc_plugin { |
| 10 | + |
| 11 | +// A webrtc plugin for windows/linux. |
| 12 | +class FlutterWebRTCPluginImpl : public FlutterWebRTCPlugin { |
| 13 | + public: |
| 14 | + static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) { |
| 15 | + auto channel = std::make_unique<flutter::MethodChannel<EncodableValue>>( |
| 16 | + registrar->messenger(), kChannelName, |
| 17 | + &flutter::StandardMethodCodec::GetInstance()); |
| 18 | + |
| 19 | + auto *channel_pointer = channel.get(); |
| 20 | + |
| 21 | + // Uses new instead of make_unique due to private constructor. |
| 22 | + std::unique_ptr<FlutterWebRTCPluginImpl> plugin( |
| 23 | + new FlutterWebRTCPluginImpl(registrar, std::move(channel))); |
| 24 | + |
| 25 | + channel_pointer->SetMethodCallHandler( |
| 26 | + [plugin_pointer = plugin.get()](const auto &call, auto result) { |
| 27 | + plugin_pointer->HandleMethodCall(call, std::move(result)); |
| 28 | + }); |
| 29 | + |
| 30 | + registrar->AddPlugin(std::move(plugin)); |
| 31 | + } |
| 32 | + |
| 33 | + virtual ~FlutterWebRTCPluginImpl() {} |
| 34 | + |
| 35 | + flutter::BinaryMessenger *messenger() { return messenger_; } |
| 36 | + |
| 37 | + flutter::TextureRegistrar *textures() { return textures_; } |
| 38 | + |
| 39 | + private: |
| 40 | + // Creates a plugin that communicates on the given channel. |
| 41 | + FlutterWebRTCPluginImpl( |
| 42 | + flutter::PluginRegistrar *registrar, |
| 43 | + std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel) |
| 44 | + : channel_(std::move(channel)), |
| 45 | + messenger_(registrar->messenger()), |
| 46 | + textures_(registrar->texture_registrar()) { |
| 47 | + webrtc_ = std::make_unique<FlutterWebRTC>(this); |
| 48 | + } |
| 49 | + |
| 50 | + // Called when a method is called on |channel_|; |
| 51 | + void HandleMethodCall( |
| 52 | + const flutter::MethodCall<EncodableValue> &method_call, |
| 53 | + std::unique_ptr<flutter::MethodResult<EncodableValue>> result) { |
| 54 | + // handle method call and forward to webrtc native sdk. |
| 55 | + webrtc_->HandleMethodCall(method_call, std::move(result)); |
| 56 | + } |
| 57 | + |
| 58 | + private: |
| 59 | + std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel_; |
| 60 | + std::unique_ptr<FlutterWebRTC> webrtc_; |
| 61 | + flutter::BinaryMessenger *messenger_; |
| 62 | + flutter::TextureRegistrar *textures_; |
| 63 | +}; |
| 64 | + |
| 65 | +} // namespace flutter_webrtc_plugin |
| 66 | + |
| 67 | +void FlutterWebRTCPluginRegisterWithRegistrar( |
| 68 | + FlutterDesktopPluginRegistrarRef registrar) { |
| 69 | + static auto *plugin_registrar = new flutter::PluginRegistrar(registrar); |
| 70 | + flutter_webrtc_plugin::FlutterWebRTCPluginImpl::RegisterWithRegistrar( |
| 71 | + plugin_registrar); |
| 72 | +} |
0 commit comments