Skip to content

Commit 7be7b05

Browse files
committed
Add support for windows.
1 parent ca2d4e5 commit 7be7b05

Some content is hidden

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

54 files changed

+5307
-4
lines changed

pubspec.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: flutter_webrtc
22
description: Flutter WebRTC plugin for iOS/Android/Destkop/Web.
33
version: 0.2.8
44
homepage: https://github.com/cloudwebrtc/flutter-webrtc
5+
environment:
6+
sdk: ">=2.2.2 <3.0.0"
7+
flutter: ^1.10.0
58

69
dependencies:
710
flutter:
@@ -17,7 +20,5 @@ flutter:
1720
pluginClass: FlutterWebRTCPlugin
1821
macos:
1922
pluginClass: FlutterWebRTCPlugin
20-
21-
environment:
22-
sdk: ">=2.2.2 <3.0.0"
23-
flutter: ^1.10.0
23+
windows:
24+
pluginClass: FlutterWebRTCPlugin

windows/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flutter/
2+
3+
# Visual Studio files
4+
*.user

windows/PluginInfo.props

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ImportGroup Label="PropertySheets" />
4+
<PropertyGroup Label="UserMacros">
5+
<FlutterPluginName>flutter_webrtc</FlutterPluginName>
6+
</PropertyGroup>
7+
<PropertyGroup />
8+
<ItemDefinitionGroup />
9+
<ItemGroup>
10+
<BuildMacro Include="FlutterPluginName">
11+
<Value>$(FlutterPluginName)</Value>
12+
</BuildMacro>
13+
</ItemGroup>
14+
</Project>

windows/flutter_webrtc_plugin.cc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "flutter_webrtc_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->textures()) {
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+
}

windows/flutter_webrtc_plugin.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef PLUGINS_FLUTTER_WEBRTC_PLUGIN_WINDOWS_H_
2+
#define PLUGINS_FLUTTER_WEBRTC_PLUGIN_WINDOWS_H_
3+
4+
#include <flutter_plugin_registrar.h>
5+
6+
#if defined(_WINDOWS)
7+
#ifdef FLUTTER_PLUGIN_IMPL
8+
#define FLUTTER_PLUGIN_EXPORT __declspec(dllexport)
9+
#else
10+
#define FLUTTER_PLUGIN_EXPORT __declspec(dllimport)
11+
#endif
12+
#else
13+
#ifdef FLUTTER_PLUGIN_IMPL
14+
#define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default")))
15+
#else
16+
#define FLUTTER_PLUGIN_EXPORT
17+
#endif
18+
#endif
19+
20+
#if defined(__cplusplus)
21+
extern "C" {
22+
#endif
23+
24+
FLUTTER_PLUGIN_EXPORT void FlutterWebRTCPluginRegisterWithRegistrar(
25+
FlutterDesktopPluginRegistrarRef registrar);
26+
27+
#if defined(__cplusplus)
28+
} // extern "C"
29+
#endif
30+
31+
#endif // PLUGINS_FLUTTER_WEBRTC_PLUGIN_WINDOWS_H_
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
2+
#define FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
3+
4+
#include "flutter_webrtc_base.h"
5+
6+
namespace flutter_webrtc_plugin {
7+
8+
class FlutterRTCDataChannelObserver : public RTCDataChannelObserver {
9+
public:
10+
FlutterRTCDataChannelObserver(scoped_refptr<RTCDataChannel> data_channel,
11+
BinaryMessenger *messenger,
12+
const std::string &channel_name);
13+
virtual ~FlutterRTCDataChannelObserver();
14+
15+
virtual void OnStateChange(RTCDataChannelState state) override;
16+
17+
virtual void OnMessage(const char *buffer, int length, bool binary) override;
18+
19+
scoped_refptr<RTCDataChannel> data_channel() { return data_channel_; }
20+
21+
private:
22+
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
23+
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
24+
scoped_refptr<RTCDataChannel> data_channel_;
25+
};
26+
27+
class FlutterDataChannel {
28+
public:
29+
FlutterDataChannel(FlutterWebRTCBase *base) : base_(base) {}
30+
31+
void CreateDataChannel(const std::string &label,
32+
const EncodableMap &dataChannelDict,
33+
RTCPeerConnection *pc,
34+
std::unique_ptr<MethodResult<EncodableValue>>);
35+
36+
void DataChannelSend(RTCDataChannel *data_channel, const std::string &type,
37+
const EncodableValue &data,
38+
std::unique_ptr<MethodResult<EncodableValue>>);
39+
40+
void DataChannelClose(RTCDataChannel *data_channel,
41+
std::unique_ptr<MethodResult<EncodableValue>>);
42+
43+
RTCDataChannel *DataChannelFormId(int id);
44+
45+
private:
46+
FlutterWebRTCBase *base_;
47+
};
48+
49+
} // namespace flutter_webrtc_plugin
50+
51+
#endif // !FLUTTER_WEBRTC_RTC_DATA_CHANNEL_HXX
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#ifndef FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX
2+
#define FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX
3+
4+
#include "flutter_webrtc_base.h"
5+
6+
namespace flutter_webrtc_plugin {
7+
8+
using namespace flutter;
9+
10+
class FlutterMediaStream {
11+
public:
12+
FlutterMediaStream(FlutterWebRTCBase *base) : base_(base) {}
13+
14+
void GetUserMedia(const EncodableMap &constraints,
15+
std::unique_ptr<MethodResult<EncodableValue>> result);
16+
17+
void GetUserAudio(const EncodableMap &constraints,
18+
scoped_refptr<RTCMediaStream> stream, EncodableMap &params);
19+
20+
void GetUserVideo(const EncodableMap &constraints,
21+
scoped_refptr<RTCMediaStream> stream, EncodableMap &params);
22+
23+
void GetSources(std::unique_ptr<MethodResult<EncodableValue>> result);
24+
25+
void MediaStreamGetTracks(
26+
const std::string &stream_id,
27+
std::unique_ptr<MethodResult<EncodableValue>> result);
28+
29+
void MediaStreamDispose(const std::string &stream_id,
30+
std::unique_ptr<MethodResult<EncodableValue>> result);
31+
32+
void MediaStreamTrackSetEnable(
33+
const std::string &track_id,
34+
std::unique_ptr<MethodResult<EncodableValue>> result);
35+
36+
void MediaStreamTrackSwitchCamera(
37+
const std::string &track_id,
38+
std::unique_ptr<MethodResult<EncodableValue>> result);
39+
40+
void MediaStreamTrackDispose(
41+
const std::string &track_id,
42+
std::unique_ptr<MethodResult<EncodableValue>> result);
43+
44+
private:
45+
FlutterWebRTCBase *base_;
46+
};
47+
48+
} // namespace flutter_webrtc_plugin
49+
50+
#endif // !FLUTTER_WEBRTC_RTC_GET_USERMEDIA_HXX
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#ifndef FLUTTER_WEBRTC_RTC_PEER_CONNECTION_HXX
2+
#define FLUTTER_WEBRTC_RTC_PEER_CONNECTION_HXX
3+
4+
#include "flutter_webrtc_base.h"
5+
6+
namespace flutter_webrtc_plugin {
7+
8+
using namespace flutter;
9+
10+
class FlutterPeerConnectionObserver : public RTCPeerConnectionObserver {
11+
public:
12+
FlutterPeerConnectionObserver(FlutterWebRTCBase *base,
13+
scoped_refptr<RTCPeerConnection> peerconnection,
14+
BinaryMessenger *messenger,
15+
const std::string &channel_name);
16+
17+
virtual void OnSignalingState(RTCSignalingState state) override;
18+
virtual void OnIceGatheringState(RTCIceGatheringState state) override;
19+
virtual void OnIceConnectionState(RTCIceConnectionState state) override;
20+
virtual void OnIceCandidate(
21+
scoped_refptr<RTCIceCandidate> candidate) override;
22+
virtual void OnAddStream(scoped_refptr<RTCMediaStream> stream) override;
23+
virtual void OnRemoveStream(scoped_refptr<RTCMediaStream> stream) override;
24+
virtual void OnAddTrack(scoped_refptr<RTCMediaStream> stream,
25+
scoped_refptr<RTCMediaTrack> track) override;
26+
virtual void OnRemoveTrack(scoped_refptr<RTCMediaStream> stream,
27+
scoped_refptr<RTCMediaTrack> track) override;
28+
virtual void OnDataChannel(
29+
scoped_refptr<RTCDataChannel> data_channel) override;
30+
virtual void OnRenegotiationNeeded() override;
31+
32+
scoped_refptr<RTCMediaStream> MediaStreamForId(
33+
const std::string &id) {
34+
auto it = remote_streams_.find(id);
35+
if (it != remote_streams_.end()) return (*it).second;
36+
return nullptr;
37+
}
38+
39+
void RemoveStreamForId(const std::string &id) {
40+
auto it = remote_streams_.find(id);
41+
if (it != remote_streams_.end()) remote_streams_.erase(it);
42+
}
43+
44+
private:
45+
std::unique_ptr<EventChannel<EncodableValue>> event_channel_;
46+
std::unique_ptr<EventSink<EncodableValue>> event_sink_;
47+
scoped_refptr<RTCPeerConnection> peerconnection_;
48+
std::map<std::string, scoped_refptr<RTCMediaStream>> remote_streams_;
49+
FlutterWebRTCBase *base_;
50+
};
51+
52+
class FlutterPeerConnection {
53+
public:
54+
FlutterPeerConnection(FlutterWebRTCBase *base) : base_(base) {}
55+
56+
void CreateRTCPeerConnection(
57+
const EncodableMap &configuration, const EncodableMap &constraints,
58+
std::unique_ptr<MethodResult<EncodableValue>> result);
59+
60+
void RTCPeerConnectionClose(
61+
RTCPeerConnection *pc, const std::string &uuid,
62+
std::unique_ptr<MethodResult<EncodableValue>> result);
63+
64+
void CreateOffer(const EncodableMap &constraints, RTCPeerConnection *pc,
65+
std::unique_ptr<MethodResult<EncodableValue>> result);
66+
67+
void CreateAnswer(const EncodableMap &constraints, RTCPeerConnection *pc,
68+
std::unique_ptr<MethodResult<EncodableValue>> result);
69+
70+
void SetLocalDescription(
71+
RTCSessionDescription *sdp, RTCPeerConnection *pc,
72+
std::unique_ptr<MethodResult<EncodableValue>> result);
73+
74+
void SetRemoteDescription(
75+
RTCSessionDescription *sdp, RTCPeerConnection *pc,
76+
std::unique_ptr<MethodResult<EncodableValue>> result);
77+
78+
void AddIceCandidate(RTCIceCandidate *candidate, RTCPeerConnection *pc,
79+
std::unique_ptr<MethodResult<EncodableValue>> result);
80+
81+
void GetStats(const std::string &track_id, RTCPeerConnection *pc,
82+
std::unique_ptr<MethodResult<EncodableValue>> result);
83+
84+
private:
85+
FlutterWebRTCBase *base_;
86+
};
87+
} // namespace flutter_webrtc_plugin
88+
89+
#endif // !FLUTTER_WEBRTC_RTC_PEER_CONNECTION_HXX

0 commit comments

Comments
 (0)