Skip to content

Commit bdea0d1

Browse files
authored
Merge pull request #40 from cloudwebrtc/desktop
Add macOS support.
2 parents 3d790db + 4508d22 commit bdea0d1

40 files changed

+2264
-3
lines changed

lib/main.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
import 'dart:core';
2+
import 'dart:io';
13
import 'package:flutter/material.dart';
24
import 'package:shared_preferences/shared_preferences.dart';
3-
import 'dart:core';
5+
import 'package:flutter/foundation.dart'
6+
show debugDefaultTargetPlatformOverride;
7+
48
import 'src/basic_sample/basic_sample.dart';
59
import 'src/call_sample/call_sample.dart';
610
import 'src/call_sample/data_channel_sample.dart';
711
import 'src/route_item.dart';
812

9-
void main() => runApp(new MyApp());
13+
bool isDesktop() {
14+
return Platform.isWindows || Platform.isLinux || Platform.isMacOS;
15+
}
16+
17+
void main(){
18+
if(isDesktop())
19+
debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia;
20+
runApp(new MyApp());
21+
}
1022

1123
class MyApp extends StatefulWidget {
1224
@override

linux/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flutter/

linux/Makefile

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Copyright 2018 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Executable name.
16+
BINARY_NAME=flutter_webrtc_demo
17+
# The location of the flutter-desktop-embedding repository.
18+
FDE_ROOT=$(CURDIR)/../..
19+
# The C++ code for the embedder application.
20+
SOURCES=flutter_webrtc_demo.cc
21+
22+
# Plugins to include from the flutter-desktop-embedding plugins/ directory.
23+
PLUGIN_NAMES=flutter_webrtc
24+
# Additional plugins to include from the plugins/flutter_plugins subdirectory.
25+
FLUTTER_PLUGIN_NAMES=url_launcher_fde
26+
27+
28+
# Default build type. For a release build, set BUILD=release.
29+
# Currently this only sets NDEBUG, which is used to control the flags passed
30+
# to the Flutter engine in the example shell, and not the complation settings
31+
# (e.g., optimization level) of the C++ code.
32+
BUILD=debug
33+
34+
# Configuration provided via flutter tool.
35+
include flutter/generated_config
36+
37+
# Dependency locations
38+
FLUTTER_APP_CACHE_DIR=flutter/
39+
FLUTTER_APP_DIR=$(CURDIR)
40+
FLUTTER_APP_BUILD_DIR=$(FLUTTER_APP_DIR)/../build
41+
PLUGINS_DIR=$(FDE_ROOT)
42+
FLUTTER_PLUGINS_DIR=$(PLUGINS_DIR)/flutter_plugins_fde
43+
44+
OUT_DIR=$(FLUTTER_APP_BUILD_DIR)/linux
45+
46+
# Libraries
47+
FLUTTER_LIB_NAME=flutter_linux
48+
FLUTTER_LIB=$(FLUTTER_APP_CACHE_DIR)/lib$(FLUTTER_LIB_NAME).so
49+
# The name of each plugin library is the name of its directory with _plugin
50+
# appended. The exception is example_plugin (to avoid confusion with the
51+
# top-level example/ directory), so it's added here separately.
52+
PLUGIN_LIB_NAMES=$(foreach plugin,$(PLUGIN_NAMES) $(FLUTTER_PLUGIN_NAMES),$(plugin)_plugin)
53+
PLUGIN_LIBS=$(foreach plugin,$(PLUGIN_LIB_NAMES),$(OUT_DIR)/lib$(plugin).so)
54+
ALL_LIBS=$(FLUTTER_LIB) $(PLUGIN_LIBS)
55+
56+
# Tools
57+
FLUTTER_BIN=$(FLUTTER_ROOT)/bin/flutter
58+
59+
# Resources
60+
ICU_DATA_NAME=icudtl.dat
61+
ICU_DATA_SOURCE=$(FLUTTER_APP_CACHE_DIR)/$(ICU_DATA_NAME)
62+
FLUTTER_ASSETS_NAME=flutter_assets
63+
FLUTTER_ASSETS_SOURCE=$(FLUTTER_APP_BUILD_DIR)/$(FLUTTER_ASSETS_NAME)
64+
65+
# Bundle structure
66+
BUNDLE_OUT_DIR=$(OUT_DIR)/$(BUILD)
67+
BUNDLE_DATA_DIR=$(BUNDLE_OUT_DIR)/data
68+
BUNDLE_LIB_DIR=$(BUNDLE_OUT_DIR)/lib
69+
70+
BIN_OUT=$(BUNDLE_OUT_DIR)/$(BINARY_NAME)
71+
ICU_DATA_OUT=$(BUNDLE_DATA_DIR)/$(ICU_DATA_NAME)
72+
FLUTTER_LIB_OUT=$(BUNDLE_LIB_DIR)/lib$(FLUTTER_LIB_NAME).so
73+
ALL_LIBS_OUT=$(foreach lib,$(ALL_LIBS),$(BUNDLE_LIB_DIR)/$(notdir $(lib)))
74+
75+
# Add relevant code from the wrapper library, which is intended to be statically
76+
# built into the client.
77+
WRAPPER_ROOT=$(FLUTTER_APP_CACHE_DIR)/cpp_client_wrapper
78+
WRAPPER_SOURCES= \
79+
$(WRAPPER_ROOT)/flutter_window_controller.cc \
80+
$(WRAPPER_ROOT)/plugin_registrar.cc \
81+
$(WRAPPER_ROOT)/engine_method_result.cc
82+
SOURCES+=$(WRAPPER_SOURCES)
83+
84+
# Headers
85+
WRAPPER_INCLUDE_DIR=$(WRAPPER_ROOT)/include
86+
# The plugin builds place all published headers in a top-level include/.
87+
PLUGIN_INCLUDE_DIRS=$(OUT_DIR)/include
88+
INCLUDE_DIRS=$(FLUTTER_APP_CACHE_DIR) $(PLUGIN_INCLUDE_DIRS) \
89+
$(WRAPPER_INCLUDE_DIR)
90+
91+
# Build settings
92+
CXX=clang++
93+
CXXFLAGS.release=-DNDEBUG
94+
CXXFLAGS=-std=c++14 -Wall -Werror $(CXXFLAGS.$(BUILD))
95+
CPPFLAGS=$(patsubst %,-I%,$(INCLUDE_DIRS))
96+
LDFLAGS=-L$(BUNDLE_LIB_DIR) \
97+
-l$(FLUTTER_LIB_NAME) \
98+
$(patsubst %,-l%,$(PLUGIN_LIB_NAMES)) \
99+
-Wl,-rpath=\$$ORIGIN/lib \
100+
-lwebrtc
101+
102+
# Targets
103+
104+
.PHONY: all
105+
all: $(BIN_OUT) bundle
106+
107+
# This is a phony target because the flutter tool cannot describe
108+
# its inputs and outputs yet.
109+
.PHONY: sync
110+
sync: flutter/generated_config
111+
$(FLUTTER_ROOT)/packages/flutter_tools/bin/tool_backend.sh linux-x64 $(BUILD)
112+
113+
.PHONY: bundle
114+
bundle: $(ICU_DATA_OUT) $(ALL_LIBS_OUT) bundleflutterassets
115+
116+
$(BIN_OUT): $(SOURCES) $(ALL_LIBS_OUT)
117+
mkdir -p $(@D)
118+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(SOURCES) $(LDFLAGS) -o $@
119+
120+
$(WRAPPER_SOURCES) $(FLUTTER_LIB) $(ICU_DATA_SOURCE) $(FLUTTER_ASSETS_SOURCE): \
121+
| sync
122+
123+
# Implicit rules won't match phony targets, so list plugin builds explicitly.
124+
#$(OUT_DIR)/libexample_plugin.so: | example_plugin
125+
#$(OUT_DIR)/libcolor_panel_plugin.so: | color_panel
126+
#$(OUT_DIR)/libfile_chooser_plugin.so: | file_chooser
127+
#$(OUT_DIR)/libmenubar_plugin.so: | menubar
128+
#$(OUT_DIR)/libwindow_size_plugin.so: | window_size
129+
$(OUT_DIR)/liburl_launcher_fde_plugin.so: | url_launcher_fde
130+
$(OUT_DIR)/libflutter_webrtc_plugin.so: | flutter_webrtc
131+
132+
.PHONY: $(PLUGIN_NAMES)
133+
$(PLUGIN_NAMES):
134+
make -C $(PLUGINS_DIR)/$@/linux \
135+
OUT_DIR=$(OUT_DIR) FLUTTER_ROOT=$(FLUTTER_ROOT)
136+
137+
.PHONY: $(FLUTTER_PLUGIN_NAMES)
138+
$(FLUTTER_PLUGIN_NAMES):
139+
make -C $(FLUTTER_PLUGINS_DIR)/$@/linux \
140+
OUT_DIR=$(OUT_DIR) FLUTTER_ROOT=$(FLUTTER_ROOT)
141+
142+
# Plugin library bundling pattern.
143+
$(BUNDLE_LIB_DIR)/%: $(OUT_DIR)/%
144+
mkdir -p $(BUNDLE_LIB_DIR)
145+
cp $< $@
146+
147+
$(FLUTTER_LIB_OUT): $(FLUTTER_LIB)
148+
mkdir -p $(@D)
149+
cp $< $@
150+
151+
$(ICU_DATA_OUT): $(ICU_DATA_SOURCE)
152+
mkdir -p $(@D)
153+
cp $< $@
154+
155+
# Fully re-copy the assets directory on each build to avoid having to keep a
156+
# comprehensive list of all asset files here, which would be fragile to changes
157+
# in the Flutter example (e.g., adding a new font to pubspec.yaml would require
158+
# changes here).
159+
.PHONY: bundleflutterassets
160+
bundleflutterassets: $(FLUTTER_ASSETS_SOURCE)
161+
mkdir -p $(BUNDLE_DATA_DIR)
162+
rsync -rpu --delete $(FLUTTER_ASSETS_SOURCE) $(BUNDLE_DATA_DIR)
163+
164+
.PHONY: clean
165+
clean:
166+
rm -rf $(OUT_DIR); \
167+
cd $(FLUTTER_APP_DIR); \
168+
$(FLUTTER_BIN) clean

linux/flutter_webrtc_demo.cc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
#include <linux/limits.h>
15+
#include <unistd.h>
16+
#include <cstdlib>
17+
#include <iostream>
18+
#include <memory>
19+
#include <vector>
20+
21+
#include <flutter_webrtc_plugin.h>
22+
#include <flutter/flutter_window_controller.h>
23+
#include <url_launcher_fde_plugin.h>
24+
25+
namespace {
26+
27+
// Returns the path of the directory containing this executable, or an empty
28+
// string if the directory cannot be found.
29+
std::string GetExecutableDirectory() {
30+
char buffer[PATH_MAX + 1];
31+
ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
32+
if (length > PATH_MAX) {
33+
std::cerr << "Couldn't locate executable" << std::endl;
34+
return "";
35+
}
36+
std::string executable_path(buffer, length);
37+
size_t last_separator_position = executable_path.find_last_of('/');
38+
if (last_separator_position == std::string::npos) {
39+
std::cerr << "Unabled to find parent directory of " << executable_path
40+
<< std::endl;
41+
return "";
42+
}
43+
return executable_path.substr(0, last_separator_position);
44+
}
45+
46+
} // namespace
47+
48+
int main(int argc, char **argv) {
49+
// Resources are located relative to the executable.
50+
std::string base_directory = GetExecutableDirectory();
51+
if (base_directory.empty()) {
52+
base_directory = ".";
53+
}
54+
std::string data_directory = base_directory + "/data";
55+
std::string assets_path = data_directory + "/flutter_assets";
56+
std::string icu_data_path = data_directory + "/icudtl.dat";
57+
58+
// Arguments for the Flutter Engine.
59+
std::vector<std::string> arguments;
60+
#ifdef NDEBUG
61+
arguments.push_back("--disable-dart-asserts");
62+
#endif
63+
64+
flutter::FlutterWindowController flutter_controller(icu_data_path);
65+
66+
// Start the engine.
67+
if (!flutter_controller.CreateWindow(800, 600, "Flutter WebRTC Demo", assets_path,
68+
arguments)) {
69+
return EXIT_FAILURE;
70+
}
71+
72+
// Register any native plugins.
73+
FlutterWebRTCPluginRegisterWithRegistrar(
74+
flutter_controller.GetRegistrarForPlugin("FlutterWebRTCPlugin"));
75+
UrlLauncherRegisterWithRegistrar(
76+
flutter_controller.GetRegistrarForPlugin("UrlLauncher"));
77+
78+
// Run until the window is closed.
79+
flutter_controller.RunEventLoop();
80+
return EXIT_SUCCESS;
81+
}

macos/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Flutter-related
2+
**/Flutter/ephemeral/
3+
**/Pods/
4+
5+
# Xcode-related
6+
**/xcuserdata/

macos/Flutter/Flutter-Debug.xcconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "ephemeral/Flutter-Generated.xcconfig"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "ephemeral/Flutter-Generated.xcconfig"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Generated file. Do not edit.
3+
//
4+
5+
import FlutterMacOS
6+
import Foundation
7+
8+
9+
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
10+
}

0 commit comments

Comments
 (0)