Skip to content

Commit 8f183ed

Browse files
authored
feat: Add support for linux desktop.
* feat: linux support. * chore: change MethodChannel Name. * update. * add file. * Add EventChannelProxy. * Add MethodResultProxy. * Refactoring proxy interface to abstract. * update. * update. * update. * update. * update. * fixed compile for linux. * update. * update. * fix compile error for windows. * update. * Update precompiled binaries. * support texture. * cpp format. * enable screen sharing for linux. * Update precompiled binaries. * update README.md * update. * update.
1 parent 4426d6d commit 8f183ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3967
-928
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22

33
--------------------------------------------
4+
[0.9.15] - 2022-11-13
5+
6+
* [Linux] Add Linux Support.
7+
48
[0.9.14] - 2022-11-12
59

610
* [iOS] Fix setSpeakerOn has no effect after change AVAudioSession mode to playback.

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Enterprise Grade APIs for Feeds & Chat. <a href="https://getstream.io/chat/flutt
2727

2828
| Feature | Android | iOS | [Web](https://flutter.dev/web) | macOS | Windows | Linux | [Embedded](https://github.com/sony/flutter-elinux) | [Fuchsia](https://fuchsia.dev/) |
2929
| :-------------: | :-------------:| :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: |
30-
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
31-
| Data Channel | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] ||
32-
| Screen Capture | :heavy_check_mark: | [:heavy_check_mark:(*)](https://github.com/flutter-webrtc/flutter-webrtc/wiki/iOS-Screen-Sharing) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | |
33-
| Unified-Plan | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | [WIP] | |
34-
| Simulcast | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | | | |
30+
| Audio/Video | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
31+
| Data Channel | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
32+
| Screen Capture | :heavy_check_mark: | [:heavy_check_mark:(*)](https://github.com/flutter-webrtc/flutter-webrtc/wiki/iOS-Screen-Sharing) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
33+
| Unified-Plan | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
34+
| Simulcast | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | [WIP] | |
3535
| MediaRecorder | :warning: | :warning: | :heavy_check_mark: | | | | | |
3636
| Insertable Streams | | | | | | | | |
3737
## Usage

common/cpp/flutter_webrtc_plugin.cc

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
#include "flutter_webrtc/flutter_web_r_t_c_plugin.h"
22

3-
#include <flutter/standard_message_codec.h>
4-
3+
#include "flutter_common.h"
54
#include "flutter_webrtc.h"
65

7-
const char *kChannelName = "FlutterWebRTC.Method";
6+
const char* kChannelName = "FlutterWebRTC.Method";
7+
8+
//#if defined(_WINDOWS)
89

910
namespace flutter_webrtc_plugin {
1011

1112
// A webrtc plugin for windows/linux.
1213
class FlutterWebRTCPluginImpl : public FlutterWebRTCPlugin {
1314
public:
14-
static void RegisterWithRegistrar(flutter::PluginRegistrar *registrar) {
15-
auto channel = std::make_unique<flutter::MethodChannel<EncodableValue>>(
15+
static void RegisterWithRegistrar(PluginRegistrar* registrar) {
16+
auto channel = std::make_unique<MethodChannel>(
1617
registrar->messenger(), kChannelName,
1718
&flutter::StandardMethodCodec::GetInstance());
1819

19-
auto *channel_pointer = channel.get();
20+
auto* channel_pointer = channel.get();
2021

2122
// Uses new instead of make_unique due to private constructor.
2223
std::unique_ptr<FlutterWebRTCPluginImpl> plugin(
2324
new FlutterWebRTCPluginImpl(registrar, std::move(channel)));
2425

2526
channel_pointer->SetMethodCallHandler(
26-
[plugin_pointer = plugin.get()](const auto &call, auto result) {
27+
[plugin_pointer = plugin.get()](const auto& call, auto result) {
2728
plugin_pointer->HandleMethodCall(call, std::move(result));
2829
});
2930

@@ -32,41 +33,42 @@ class FlutterWebRTCPluginImpl : public FlutterWebRTCPlugin {
3233

3334
virtual ~FlutterWebRTCPluginImpl() {}
3435

35-
flutter::BinaryMessenger *messenger() { return messenger_; }
36+
BinaryMessenger* messenger() { return messenger_; }
3637

37-
flutter::TextureRegistrar *textures() { return textures_; }
38+
TextureRegistrar* textures() { return textures_; }
3839

3940
private:
4041
// Creates a plugin that communicates on the given channel.
41-
FlutterWebRTCPluginImpl(
42-
flutter::PluginRegistrar *registrar,
43-
std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel)
42+
FlutterWebRTCPluginImpl(PluginRegistrar* registrar,
43+
std::unique_ptr<MethodChannel> channel)
4444
: channel_(std::move(channel)),
4545
messenger_(registrar->messenger()),
4646
textures_(registrar->texture_registrar()) {
4747
webrtc_ = std::make_unique<FlutterWebRTC>(this);
4848
}
4949

5050
// 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) {
51+
void HandleMethodCall(const MethodCall& method_call,
52+
std::unique_ptr<MethodResult> result) {
5453
// handle method call and forward to webrtc native sdk.
55-
webrtc_->HandleMethodCall(method_call, std::move(result));
54+
auto method_call_proxy = MethodCallProxy::Create(method_call);
55+
webrtc_->HandleMethodCall(*method_call_proxy.get(), MethodResultProxy::Create(std::move(result)));
5656
}
5757

5858
private:
59-
std::unique_ptr<flutter::MethodChannel<EncodableValue>> channel_;
59+
std::unique_ptr<MethodChannel> channel_;
6060
std::unique_ptr<FlutterWebRTC> webrtc_;
61-
flutter::BinaryMessenger *messenger_;
62-
flutter::TextureRegistrar *textures_;
61+
BinaryMessenger* messenger_;
62+
TextureRegistrar* textures_;
6363
};
6464

6565
} // namespace flutter_webrtc_plugin
6666

67-
void FlutterWebRTCPluginRegisterWithRegistrar(
68-
FlutterDesktopPluginRegistrarRef registrar) {
67+
#if defined(_WINDOWS)
68+
void FlutterWebRTCPluginRegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar){
69+
#else
70+
void flutter_web_r_t_c_plugin_register_with_registrar(FlPluginRegistrar* registrar) {
71+
#endif
6972
static auto *plugin_registrar = new flutter::PluginRegistrar(registrar);
70-
flutter_webrtc_plugin::FlutterWebRTCPluginImpl::RegisterWithRegistrar(
71-
plugin_registrar);
72-
}
73+
flutter_webrtc_plugin::FlutterWebRTCPluginImpl::RegisterWithRegistrar(plugin_registrar);
74+
}

common/cpp/include/flutter_common.h

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#ifndef FLUTTER_WEBRTC_COMMON_HXX
2+
#define FLUTTER_WEBRTC_COMMON_HXX
3+
4+
#include <flutter/encodable_value.h>
5+
#include <flutter/event_channel.h>
6+
#include <flutter/event_stream_handler_functions.h>
7+
#include <flutter/method_channel.h>
8+
#include <flutter/plugin_registrar.h>
9+
#include <flutter/standard_message_codec.h>
10+
#include <flutter/standard_method_codec.h>
11+
#include <flutter/texture_registrar.h>
12+
13+
#include <string>
14+
#include <memory>
15+
#include <list>
16+
17+
typedef flutter::EncodableValue EncodableValue;
18+
typedef flutter::EncodableMap EncodableMap;
19+
typedef flutter::EncodableList EncodableList;
20+
typedef flutter::BinaryMessenger BinaryMessenger;
21+
typedef flutter::TextureRegistrar TextureRegistrar;
22+
typedef flutter::PluginRegistrar PluginRegistrar;
23+
typedef flutter::MethodChannel<EncodableValue> MethodChannel;
24+
typedef flutter::EventChannel<EncodableValue> EventChannel;
25+
typedef flutter::EventSink<EncodableValue> EventSink;
26+
typedef flutter::MethodCall<EncodableValue> MethodCall;
27+
typedef flutter::MethodResult<EncodableValue> MethodResult;
28+
29+
// foo.StringValue() becomes std::get<std::string>(foo)
30+
// foo.IsString() becomes std::holds_alternative<std::string>(foo)
31+
32+
template <typename T>
33+
inline bool TypeIs(const EncodableValue val) {
34+
return std::holds_alternative<T>(val);
35+
}
36+
37+
template <typename T>
38+
inline const T GetValue(EncodableValue val) {
39+
return std::get<T>(val);
40+
}
41+
42+
inline EncodableValue findEncodableValue(const EncodableMap& map,
43+
const std::string& key) {
44+
auto it = map.find(EncodableValue(key));
45+
if (it != map.end())
46+
return it->second;
47+
return EncodableValue();
48+
}
49+
50+
inline EncodableMap findMap(const EncodableMap& map, const std::string& key) {
51+
auto it = map.find(EncodableValue(key));
52+
if (it != map.end() && TypeIs<EncodableMap>(it->second))
53+
return GetValue<EncodableMap>(it->second);
54+
return EncodableMap();
55+
}
56+
57+
inline EncodableList findList(const EncodableMap& map, const std::string& key) {
58+
auto it = map.find(EncodableValue(key));
59+
if (it != map.end() && TypeIs<EncodableList>(it->second))
60+
return GetValue<EncodableList>(it->second);
61+
return EncodableList();
62+
}
63+
64+
inline std::string findString(const EncodableMap& map, const std::string& key) {
65+
auto it = map.find(EncodableValue(key));
66+
if (it != map.end() && TypeIs<std::string>(it->second))
67+
return GetValue<std::string>(it->second);
68+
return std::string();
69+
}
70+
71+
inline int findInt(const EncodableMap& map, const std::string& key) {
72+
auto it = map.find(EncodableValue(key));
73+
if (it != map.end() && TypeIs<int>(it->second))
74+
return GetValue<int>(it->second);
75+
return -1;
76+
}
77+
78+
inline double findDouble(const EncodableMap& map, const std::string& key) {
79+
auto it = map.find(EncodableValue(key));
80+
if (it != map.end() && TypeIs<double>(it->second))
81+
return GetValue<double>(it->second);
82+
return 0.0;
83+
}
84+
85+
inline int64_t findLongInt(const EncodableMap& map, const std::string& key) {
86+
for (auto it : map) {
87+
if (key == GetValue<std::string>(it.first)) {
88+
if (TypeIs<int64_t>(it.second)) {
89+
return GetValue<int64_t>(it.second);
90+
} else if (TypeIs<int32_t>(it.second)) {
91+
return GetValue<int32_t>(it.second);
92+
}
93+
}
94+
}
95+
96+
return -1;
97+
}
98+
99+
inline int toInt(flutter::EncodableValue inputVal, int defaultVal) {
100+
int intValue = defaultVal;
101+
if (TypeIs<int>(inputVal)) {
102+
intValue = GetValue<int>(inputVal);
103+
} else if (TypeIs<int32_t>(inputVal)) {
104+
intValue = GetValue<int32_t>(inputVal);
105+
} else if (TypeIs<std::string>(inputVal)) {
106+
intValue = atoi(GetValue<std::string>(inputVal).c_str());
107+
}
108+
return intValue;
109+
}
110+
111+
class MethodCallProxy {
112+
public:
113+
static std::unique_ptr<MethodCallProxy> Create(const MethodCall& call);
114+
virtual ~MethodCallProxy() = default;
115+
// The name of the method being called.
116+
virtual const std::string& method_name() const = 0;
117+
118+
// The arguments to the method call, or NULL if there are none.
119+
virtual const EncodableValue* arguments() const = 0;
120+
};
121+
122+
class MethodResultProxy {
123+
public:
124+
static std::unique_ptr<MethodResultProxy> Create(
125+
std::unique_ptr<MethodResult> method_result);
126+
127+
virtual ~MethodResultProxy() = default;
128+
129+
// Reports success with no result.
130+
virtual void Success() = 0;
131+
132+
// Reports success with a result.
133+
virtual void Success(const EncodableValue& result) = 0;
134+
135+
// Reports an error.
136+
virtual void Error(const std::string& error_code,
137+
const std::string& error_message,
138+
const EncodableValue& error_details) = 0;
139+
140+
// Reports an error with a default error code and no details.
141+
virtual void Error(const std::string& error_code,
142+
const std::string& error_message = "") = 0;
143+
144+
virtual void NotImplemented() = 0;
145+
};
146+
147+
class EventChannelProxy {
148+
public:
149+
static std::unique_ptr<EventChannelProxy> Create(
150+
BinaryMessenger* messenger,
151+
const std::string& channelName);
152+
153+
virtual ~EventChannelProxy() = default;
154+
155+
virtual void Success(const EncodableValue& event,
156+
bool cache_event = true) = 0;
157+
};
158+
159+
#endif // FLUTTER_WEBRTC_COMMON_HXX

common/cpp/include/flutter_data_channel.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
#ifndef FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
22
#define FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
33

4+
#include "flutter_common.h"
45
#include "flutter_webrtc_base.h"
56

67
namespace flutter_webrtc_plugin {
78

89
class FlutterRTCDataChannelObserver : public RTCDataChannelObserver {
910
public:
1011
FlutterRTCDataChannelObserver(scoped_refptr<RTCDataChannel> data_channel,
11-
BinaryMessenger *messenger,
12-
const std::string &channel_name);
12+
BinaryMessenger* messenger,
13+
const std::string& channel_name);
1314
virtual ~FlutterRTCDataChannelObserver();
1415

1516
virtual void OnStateChange(RTCDataChannelState state) override;
1617

17-
virtual void OnMessage(const char *buffer, int length, bool binary) override;
18+
virtual void OnMessage(const char* buffer, int length, bool binary) override;
1819

1920
scoped_refptr<RTCDataChannel> data_channel() { return data_channel_; }
2021

2122
private:
22-
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
23-
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
23+
std::unique_ptr<EventChannelProxy> event_channel_;
2424
scoped_refptr<RTCDataChannel> data_channel_;
25-
std::list<EncodableValue> event_queue_;
2625
};
2726

2827
class FlutterDataChannel {
2928
public:
30-
FlutterDataChannel(FlutterWebRTCBase *base) : base_(base) {}
29+
FlutterDataChannel(FlutterWebRTCBase* base) : base_(base) {}
3130

3231
void CreateDataChannel(const std::string& peerConnectionId,
3332
const std::string& label,
34-
const EncodableMap &dataChannelDict,
35-
RTCPeerConnection *pc,
36-
std::unique_ptr<MethodResult<EncodableValue>>);
33+
const EncodableMap& dataChannelDict,
34+
RTCPeerConnection* pc,
35+
std::unique_ptr<MethodResultProxy>);
3736

38-
void DataChannelSend(RTCDataChannel *data_channel, const std::string &type,
39-
const EncodableValue &data,
40-
std::unique_ptr<MethodResult<EncodableValue>>);
37+
void DataChannelSend(RTCDataChannel* data_channel,
38+
const std::string& type,
39+
const EncodableValue& data,
40+
std::unique_ptr<MethodResultProxy>);
4141

42-
void DataChannelClose(RTCDataChannel *data_channel,
43-
const std::string &data_channel_uuid,
44-
std::unique_ptr<MethodResult<EncodableValue>>);
42+
void DataChannelClose(RTCDataChannel* data_channel,
43+
const std::string& data_channel_uuid,
44+
std::unique_ptr<MethodResultProxy>);
4545

46-
RTCDataChannel *DataChannelForId(const std::string &id);
46+
RTCDataChannel* DataChannelForId(const std::string& id);
4747

4848
private:
49-
FlutterWebRTCBase *base_;
49+
FlutterWebRTCBase* base_;
5050
};
5151

5252
} // namespace flutter_webrtc_plugin

0 commit comments

Comments
 (0)