├── .gitignore
├── .metadata
├── LICENSE
├── README.md
├── analysis_options.yaml
├── android
├── .gitignore
├── app
│ ├── build.gradle
│ └── src
│ │ ├── debug
│ │ └── AndroidManifest.xml
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── kotlin
│ │ │ └── cn
│ │ │ │ └── leo
│ │ │ │ └── watch
│ │ │ │ └── togther
│ │ │ │ └── watch_together
│ │ │ │ └── MainActivity.kt
│ │ └── res
│ │ │ ├── drawable-v21
│ │ │ └── launch_background.xml
│ │ │ ├── drawable
│ │ │ └── launch_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── values-night
│ │ │ └── styles.xml
│ │ │ ├── values
│ │ │ └── styles.xml
│ │ │ └── xml
│ │ │ └── base_network_security_config.xml
│ │ └── profile
│ │ └── AndroidManifest.xml
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
├── keystore
│ └── key.jks
└── settings.gradle
├── assets
├── icon
│ ├── ic_app.png
│ └── ic_movie.png
└── watch_together.crt
├── flutter_launcher_icons.yaml
├── ios
├── .gitignore
├── Flutter
│ ├── AppFrameworkInfo.plist
│ ├── Debug.xcconfig
│ └── Release.xcconfig
├── Podfile
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── IDEWorkspaceChecks.plist
│ │ │ └── WorkspaceSettings.xcsettings
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ ├── IDEWorkspaceChecks.plist
│ │ └── WorkspaceSettings.xcsettings
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-App-1024x1024@1x.png
│ │ ├── Icon-App-20x20@1x.png
│ │ ├── Icon-App-20x20@2x.png
│ │ ├── Icon-App-20x20@3x.png
│ │ ├── Icon-App-29x29@1x.png
│ │ ├── Icon-App-29x29@2x.png
│ │ ├── Icon-App-29x29@3x.png
│ │ ├── Icon-App-40x40@1x.png
│ │ ├── Icon-App-40x40@2x.png
│ │ ├── Icon-App-40x40@3x.png
│ │ ├── Icon-App-50x50@1x.png
│ │ ├── Icon-App-50x50@2x.png
│ │ ├── Icon-App-57x57@1x.png
│ │ ├── Icon-App-57x57@2x.png
│ │ ├── Icon-App-60x60@2x.png
│ │ ├── Icon-App-60x60@3x.png
│ │ ├── Icon-App-72x72@1x.png
│ │ ├── Icon-App-72x72@2x.png
│ │ ├── Icon-App-76x76@1x.png
│ │ ├── Icon-App-76x76@2x.png
│ │ └── Icon-App-83.5x83.5@2x.png
│ └── LaunchImage.imageset
│ │ ├── Contents.json
│ │ ├── LaunchImage.png
│ │ ├── LaunchImage@2x.png
│ │ ├── LaunchImage@3x.png
│ │ └── README.md
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ └── Runner-Bridging-Header.h
├── lib
├── config_device.dart
├── config_web.dart
├── config_window.dart
├── constants.dart
├── dialog
│ └── dialog_input_video_url.dart
├── dlna
│ └── dlna_flutter.dart
├── ext
│ └── string_ext.dart
├── generated
│ └── assets.dart
├── includes.dart
├── info
│ ├── player_info.dart
│ └── room_info.dart
├── logger
│ ├── log_printer.dart
│ └── log_utils.dart
├── main.dart
├── main_web.dart
├── mqtt
│ ├── mqtt_client.dart
│ ├── mqtt_client_device.dart
│ ├── mqtt_client_web.dart
│ ├── mqtt_config.dart
│ ├── mqtt_observer.dart
│ └── mqtt_topic.dart
├── page
│ ├── join
│ │ ├── join_logic.dart
│ │ └── join_view.dart
│ ├── main
│ │ ├── main_ext.dart
│ │ ├── main_logic.dart
│ │ ├── main_service.dart
│ │ └── main_view.dart
│ └── video
│ │ ├── desktop
│ │ ├── desktop_video_logic.dart
│ │ └── desktop_video_page.dart
│ │ ├── phone
│ │ ├── phone_video_logic.dart
│ │ └── phone_video_page.dart
│ │ └── web
│ │ ├── web_logic.dart
│ │ └── web_view.dart
├── route
│ ├── pages.dart
│ ├── pages_web.dart
│ ├── route_ext.dart
│ ├── router_helper.dart
│ ├── router_web.dart
│ └── routes.dart
├── utils
│ ├── client_id_util.dart
│ ├── platform_utils.dart
│ └── task_queue_utils.dart
└── widget
│ └── widget_send_danmaku.dart
├── linux
├── .gitignore
├── CMakeLists.txt
├── flutter
│ ├── CMakeLists.txt
│ ├── generated_plugin_registrant.cc
│ ├── generated_plugin_registrant.h
│ └── generated_plugins.cmake
├── main.cc
├── my_application.cc
└── my_application.h
├── macos
├── .gitignore
├── Flutter
│ ├── Flutter-Debug.xcconfig
│ ├── Flutter-Release.xcconfig
│ └── GeneratedPluginRegistrant.swift
├── Podfile
├── Runner.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ └── xcshareddata
│ │ └── xcschemes
│ │ └── Runner.xcscheme
├── Runner.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── Runner
│ ├── AppDelegate.swift
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── app_icon_1024.png
│ │ ├── app_icon_128.png
│ │ ├── app_icon_16.png
│ │ ├── app_icon_256.png
│ │ ├── app_icon_32.png
│ │ ├── app_icon_512.png
│ │ └── app_icon_64.png
│ ├── Base.lproj
│ └── MainMenu.xib
│ ├── Configs
│ ├── AppInfo.xcconfig
│ ├── Debug.xcconfig
│ ├── Release.xcconfig
│ └── Warnings.xcconfig
│ ├── DebugProfile.entitlements
│ ├── Info.plist
│ ├── MainFlutterWindow.swift
│ └── Release.entitlements
├── pubspec.lock
├── pubspec.yaml
├── test
└── widget_test.dart
├── web
├── favicon.png
├── icons
│ ├── Icon-192.png
│ ├── Icon-512.png
│ ├── Icon-maskable-192.png
│ └── Icon-maskable-512.png
├── index.html
└── manifest.json
└── windows
├── .gitignore
├── CMakeLists.txt
├── flutter
├── CMakeLists.txt
├── generated_plugin_registrant.cc
├── generated_plugin_registrant.h
└── generated_plugins.cmake
└── runner
├── CMakeLists.txt
├── Runner.rc
├── flutter_window.cpp
├── flutter_window.h
├── main.cpp
├── resource.h
├── resources
└── app_icon.ico
├── runner.exe.manifest
├── utils.cpp
├── utils.h
├── win32_window.cpp
└── win32_window.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .packages
31 | .pub-cache/
32 | .pub/
33 | /build/
34 |
35 | # Web related
36 |
37 | # Symbolication related
38 | app.*.symbols
39 |
40 | # Obfuscation related
41 | app.*.map.json
42 |
43 | # Android Studio will place build artifacts here
44 | /android/app/debug
45 | /android/app/profile
46 | /android/app/release
47 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: "e1e47221e86272429674bec4f1bd36acc4fc7b77"
8 | channel: "stable"
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
17 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
18 | - platform: android
19 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
20 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
21 | - platform: ios
22 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
23 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
24 | - platform: linux
25 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
26 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
27 | - platform: macos
28 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
29 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
30 | - platform: web
31 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
32 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
33 | - platform: windows
34 | create_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
35 | base_revision: e1e47221e86272429674bec4f1bd36acc4fc7b77
36 |
37 | # User provided section
38 |
39 | # List of Local paths (relative to this file) that should be
40 | # ignored by the migrate tool.
41 | #
42 | # Files that are not part of the templates will be ignored by default.
43 | unmanaged_files:
44 | - 'lib/main.dart'
45 | - 'ios/Runner.xcodeproj/project.pbxproj'
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # watch_together
2 |
3 |
4 | ## A project can watch video together on different device.
5 |
6 |
7 | ### ==郑重声明:==
8 | > 1.本项目做为开源项目,不从事商业用途,不盈利;
9 | > 2.采用GPL3许可证协议,不允许商用;
10 | > 3.项目初衷是解决异地恋一起看片的需求;
11 | > 4.项目技术原理:dlna投屏协议,跟投屏到电视原理一致;
12 | > 5.用户投屏的视频内容与本项目无关,造成的侵权和法律责任由用户自己承担,本项目作者不承担任何责任;
13 |
14 | ### 使用方法:
15 | > 1.打开app->输入房间号;
16 | > 2.如果显示你是房主,则打开其它视频app,选择你要播放的视频,然后选择投屏->Watch together;
17 | > 3.如果你是观众,则自动播放房主的视频,并同步房主的进度;
18 | > 4.如果你和房主视频进度不同步,点击界面上的同步按钮即可;
19 |
20 | ### tips:
21 | > 1.由于各主流视频平台对于投屏协议的收紧,
22 | 目前测试只有百度网盘手机app全屏播放时能投屏本app,
23 | 开发者可以自行研究其他平台的投屏协议;
24 | > 2.不支持本地视频投屏;
25 | > 3.支持填写视频播放地址;
26 |
27 | 本项目 由flutter 编写,支持多平台;
28 | 利用dlna 投屏原理实现多端 异地一起看视频的项目;
29 |
30 | 目前支持 android, windows, iphone, ipad, linux, web;
31 |
32 | 已测试:android, iphone, Windows, web;
33 |
34 | 项目开源,不上架应用市场,安卓用户和windows 用户可以点击下面链接体验:
35 |
36 | [Android下载](https://github.com/jarryleo/watch_together/releases/download/2.0.1/Android_WatchTogether_2.0.1.apk)
37 |
38 | [Windows下载](https://github.com/jarryleo/watch_together/releases/download/2.0.1/Windows_WatchTogtherSetup_2.0.1.zip)
39 |
40 | [Web体验地址](https://jarryleo.github.io/)
41 |
42 | WEB不支持投屏,支持输入视频地址播放;
43 |
44 | ios用户需要自己编译;
45 |
46 | ### 关于MQTT:
47 |
48 | 本项目采用mqtt协议,实现多端同步;
49 |
50 | mqtt服务器采用[EMQX CLOUD](https://cloud.emqx.com/)免费服务器,每月有1G免费流量,可同时连接1000客户端;
51 |
52 | 如果流量不够用,可以自己搭建或申请mqtt服务器,修改代码中的mqtt_config的服务器配置即可;
53 |
54 |
--------------------------------------------------------------------------------
/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at
17 | # https://dart-lang.github.io/linter/lints/index.html.
18 | #
19 | # Instead of disabling a lint rule for the entire project in the
20 | # section below, it can also be suppressed for a single line of code
21 | # or a specific dart file by using the `// ignore: name_of_lint` and
22 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
23 | # producing the lint.
24 | rules:
25 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
26 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
27 |
28 | # Additional information about this file can be found at
29 | # https://dart.dev/guides/language/analysis-options
30 |
--------------------------------------------------------------------------------
/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | #**/*.keystore
13 | #**/*.jks
14 |
--------------------------------------------------------------------------------
/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | def localProperties = new Properties()
2 | def localPropertiesFile = rootProject.file('local.properties')
3 | if (localPropertiesFile.exists()) {
4 | localPropertiesFile.withReader('UTF-8') { reader ->
5 | localProperties.load(reader)
6 | }
7 | }
8 |
9 | def flutterRoot = localProperties.getProperty('flutter.sdk')
10 | if (flutterRoot == null) {
11 | throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
12 | }
13 |
14 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
15 | if (flutterVersionCode == null) {
16 | flutterVersionCode = '2'
17 | }
18 |
19 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
20 | if (flutterVersionName == null) {
21 | flutterVersionName = '1.0.1'
22 | }
23 |
24 | apply plugin: 'com.android.application'
25 | apply plugin: 'kotlin-android'
26 | apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
27 |
28 | android {
29 | compileSdkVersion flutter.compileSdkVersion
30 | ndkVersion flutter.ndkVersion
31 |
32 | compileOptions {
33 | sourceCompatibility JavaVersion.VERSION_1_8
34 | targetCompatibility JavaVersion.VERSION_1_8
35 | }
36 |
37 | kotlinOptions {
38 | jvmTarget = '1.8'
39 | }
40 |
41 | sourceSets {
42 | main.java.srcDirs += 'src/main/kotlin'
43 | }
44 |
45 | defaultConfig {
46 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
47 | applicationId "cn.leo.watch.togther.watch_together"
48 | // You can update the following values to match your application needs.
49 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
50 | minSdkVersion flutter.minSdkVersion
51 | targetSdkVersion flutter.targetSdkVersion
52 | versionCode flutterVersionCode.toInteger()
53 | versionName flutterVersionName
54 | }
55 |
56 | signingConfigs {
57 | release {
58 | v1SigningEnabled true
59 | v2SigningEnabled true
60 | storeFile file('..\\keystore\\key.jks')
61 | keyAlias '123456'
62 | keyPassword '123456'
63 | storePassword '123456'
64 | }
65 | }
66 |
67 | buildTypes {
68 | release {
69 | // TODO: Add your own signing config for the release build.
70 | // Signing with the debug keys for now, so `flutter run --release` works.
71 | signingConfig signingConfigs.release
72 | }
73 | }
74 | }
75 |
76 | flutter {
77 | source '../..'
78 | }
79 |
80 | dependencies {
81 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
82 | }
83 |
--------------------------------------------------------------------------------
/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
19 |
27 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
42 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/android/app/src/main/kotlin/cn/leo/watch/togther/watch_together/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package cn.leo.watch.togther.watch_together
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/android/app/src/main/res/xml/base_network_security_config.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.6.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:7.1.2'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | google()
17 | mavenCentral()
18 | }
19 | }
20 |
21 | rootProject.buildDir = '../build'
22 | subprojects {
23 | project.buildDir = "${rootProject.buildDir}/${project.name}"
24 | }
25 | subprojects {
26 | project.evaluationDependsOn(':app')
27 | }
28 |
29 | tasks.register("clean", Delete) {
30 | delete rootProject.buildDir
31 | }
32 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536M
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 23 08:50:38 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
7 |
--------------------------------------------------------------------------------
/android/keystore/key.jks:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/android/keystore/key.jks
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
3 | def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
4 | def properties = new Properties()
5 |
6 | assert localPropertiesFile.exists()
7 | localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
8 |
9 | def flutterSdkPath = properties.getProperty("flutter.sdk")
10 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
11 | apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
12 |
--------------------------------------------------------------------------------
/assets/icon/ic_app.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/assets/icon/ic_app.png
--------------------------------------------------------------------------------
/assets/icon/ic_movie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/assets/icon/ic_movie.png
--------------------------------------------------------------------------------
/assets/watch_together.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
3 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
4 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
5 | QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
6 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
7 | b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
8 | 9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
9 | CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
10 | nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
11 | 43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
12 | T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
13 | gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
14 | BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
15 | TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
16 | DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
17 | hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
18 | 06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
19 | PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
20 | YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
21 | CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
22 | -----END CERTIFICATE-----
23 | -----BEGIN CERTIFICATE-----
24 | MIIEqjCCA5KgAwIBAgIQAnmsRYvBskWr+YBTzSybsTANBgkqhkiG9w0BAQsFADBh
25 | MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
26 | d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
27 | QTAeFw0xNzExMjcxMjQ2MTBaFw0yNzExMjcxMjQ2MTBaMG4xCzAJBgNVBAYTAlVT
28 | MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
29 | b20xLTArBgNVBAMTJEVuY3J5cHRpb24gRXZlcnl3aGVyZSBEViBUTFMgQ0EgLSBH
30 | MTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALPeP6wkab41dyQh6mKc
31 | oHqt3jRIxW5MDvf9QyiOR7VfFwK656es0UFiIb74N9pRntzF1UgYzDGu3ppZVMdo
32 | lbxhm6dWS9OK/lFehKNT0OYI9aqk6F+U7cA6jxSC+iDBPXwdF4rs3KRyp3aQn6pj
33 | pp1yr7IB6Y4zv72Ee/PlZ/6rK6InC6WpK0nPVOYR7n9iDuPe1E4IxUMBH/T33+3h
34 | yuH3dvfgiWUOUkjdpMbyxX+XNle5uEIiyBsi4IvbcTCh8ruifCIi5mDXkZrnMT8n
35 | wfYCV6v6kDdXkbgGRLKsR4pucbJtbKqIkUGxuZI2t7pfewKRc5nWecvDBZf3+p1M
36 | pA8CAwEAAaOCAU8wggFLMB0GA1UdDgQWBBRVdE+yck/1YLpQ0dfmUVyaAYca1zAf
37 | BgNVHSMEGDAWgBQD3lA1VtFMu2bwo+IbG8OXsj3RVTAOBgNVHQ8BAf8EBAMCAYYw
38 | HQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMBIGA1UdEwEB/wQIMAYBAf8C
39 | AQAwNAYIKwYBBQUHAQEEKDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdp
40 | Y2VydC5jb20wQgYDVR0fBDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQu
41 | Y29tL0RpZ2lDZXJ0R2xvYmFsUm9vdENBLmNybDBMBgNVHSAERTBDMDcGCWCGSAGG
42 | /WwBAjAqMCgGCCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BT
43 | MAgGBmeBDAECATANBgkqhkiG9w0BAQsFAAOCAQEAK3Gp6/aGq7aBZsxf/oQ+TD/B
44 | SwW3AU4ETK+GQf2kFzYZkby5SFrHdPomunx2HBzViUchGoofGgg7gHW0W3MlQAXW
45 | M0r5LUvStcr82QDWYNPaUy4taCQmyaJ+VB+6wxHstSigOlSNF2a6vg4rgexixeiV
46 | 4YSB03Yqp2t3TeZHM9ESfkus74nQyW7pRGezj+TC44xCagCQQOzzNmzEAP2SnCrJ
47 | sNE2DpRVMnL8J6xBRdjmOsC3N6cQuKuRXbzByVBjCqAA8t1L0I+9wXJerLPyErjy
48 | rMKWaBFLmfK/AHNF4ZihwPGOc7w6UHczBZXH5RFzJNnww+WnKuTPI0HfnVH8lg==
49 | -----END CERTIFICATE-----
50 |
51 |
--------------------------------------------------------------------------------
/flutter_launcher_icons.yaml:
--------------------------------------------------------------------------------
1 | # 图标配置 [https://pub.dev/packages/flutter_launcher_icons]
2 | ### 生成图标:
3 | # `dart run flutter_launcher_icons -f flutter_launcher_icons.yaml`
4 | flutter_launcher_icons:
5 | android: "ic_launcher"
6 | ios: true
7 | image_path: "assets/icon/ic_app.png"
8 | min_sdk_android: 21 # android min sdk min:16, default 21
9 | web:
10 | generate: true
11 | image_path: "assets/icon/ic_app.png"
12 | background_color: "#000000"
13 | theme_color: "#0000FF"
14 | windows:
15 | generate: true
16 | image_path: "assets/icon/ic_app.png"
17 | icon_size: 128 # min:48, max:256, default: 48
18 | macos:
19 | generate: true
20 | image_path: "assets/icon/ic_app.png"
--------------------------------------------------------------------------------
/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 9.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '9.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def flutter_root
14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15 | unless File.exist?(generated_xcode_build_settings_path)
16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17 | end
18 |
19 | File.foreach(generated_xcode_build_settings_path) do |line|
20 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
21 | return matches[1].strip if matches
22 | end
23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24 | end
25 |
26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27 |
28 | flutter_ios_podfile_setup
29 |
30 | target 'Runner' do
31 | use_frameworks!
32 | use_modular_headers!
33 |
34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35 | end
36 |
37 | post_install do |installer|
38 | installer.pods_project.targets.each do |target|
39 | flutter_additional_ios_build_settings(target)
40 | end
41 | end
42 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-50x50@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-57x57@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-72x72@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CADisableMinimumFrameDurationOnPhone
6 |
7 | CFBundleDevelopmentRegion
8 | $(DEVELOPMENT_LANGUAGE)
9 | CFBundleDisplayName
10 | Watch Together
11 | CFBundleExecutable
12 | $(EXECUTABLE_NAME)
13 | CFBundleIdentifier
14 | $(PRODUCT_BUNDLE_IDENTIFIER)
15 | CFBundleInfoDictionaryVersion
16 | 6.0
17 | CFBundleName
18 | watch_together
19 | CFBundlePackageType
20 | APPL
21 | CFBundleShortVersionString
22 | $(FLUTTER_BUILD_NAME)
23 | CFBundleSignature
24 | ????
25 | CFBundleVersion
26 | $(FLUTTER_BUILD_NUMBER)
27 | LSRequiresIPhoneOS
28 |
29 | NSAppTransportSecurity
30 |
31 | NSAllowsArbitraryLoads
32 |
33 |
34 | NSLocalNetworkUsageDescription
35 | 网络连接权限
36 | UILaunchStoryboardName
37 | LaunchScreen
38 | UIMainStoryboardFile
39 | Main
40 | UISupportedInterfaceOrientations
41 |
42 | UIInterfaceOrientationPortrait
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 | UISupportedInterfaceOrientations~ipad
47 |
48 | UIInterfaceOrientationPortrait
49 | UIInterfaceOrientationPortraitUpsideDown
50 | UIInterfaceOrientationLandscapeLeft
51 | UIInterfaceOrientationLandscapeRight
52 |
53 | UIViewControllerBasedStatusBarAppearance
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/lib/config_device.dart:
--------------------------------------------------------------------------------
1 | import 'package:get_storage/get_storage.dart';
2 | import 'package:watch_together/mqtt/mqtt_client_device.dart';
3 | import 'package:watch_together/page/main/main_service.dart';
4 | import 'package:watch_together/utils/platform_utils.dart';
5 |
6 | import 'includes.dart';
7 |
8 | class ConfigDevice {
9 | ///初始化
10 | static Future init() async {
11 | //初始化mqtt
12 | PlatFormUtils.mqttClient = MqttClientDevice();
13 | //初始化存储
14 | await GetStorage.init();
15 | //初始化服务
16 | await Get.putAsync(() => MainService().init());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lib/config_web.dart:
--------------------------------------------------------------------------------
1 | import 'package:get_storage/get_storage.dart';
2 | import 'package:watch_together/mqtt/mqtt_client_web.dart';
3 | import 'package:watch_together/page/main/main_service.dart';
4 | import 'package:watch_together/utils/platform_utils.dart';
5 |
6 | import 'includes.dart';
7 |
8 | class ConfigWeb {
9 | ///初始化
10 | static Future init() async {
11 | //初始化mqtt
12 | PlatFormUtils.mqttClient = MqttClientWeb();
13 | //初始化存储
14 | await GetStorage.init();
15 | //初始化服务
16 | await Get.putAsync(() => MainService().init());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/lib/config_window.dart:
--------------------------------------------------------------------------------
1 | import 'package:dart_vlc/dart_vlc.dart';
2 | import 'package:window_manager/window_manager.dart';
3 |
4 | import 'includes.dart';
5 |
6 | class ConfigWindow {
7 | ///初始化
8 | static Future init() async {
9 | //初始化vlc
10 | await DartVLC.initialize(useFlutterNativeView: true);
11 | //初始化窗口
12 | await initWindow();
13 | }
14 |
15 | ///初始化窗口设置
16 | static Future initWindow() async {
17 | WidgetsFlutterBinding.ensureInitialized();
18 | // Must add this line.
19 | await windowManager.ensureInitialized();
20 | WindowOptions windowOptions = const WindowOptions(
21 | size: Size(800, 600),
22 | minimumSize: Size(360, 240),
23 | center: true,
24 | skipTaskbar: false,
25 | );
26 | windowManager.waitUntilReadyToShow(windowOptions, () async {
27 | await windowManager.show();
28 | await windowManager.focus();
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/constants.dart:
--------------------------------------------------------------------------------
1 | class Constants {
2 | /// 误差多少秒自动同步
3 | static const int diffSec = 3;
4 | }
5 |
--------------------------------------------------------------------------------
/lib/dialog/dialog_input_video_url.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
2 |
3 | import '../includes.dart';
4 |
5 | typedef UrlCallBack = void Function(String value);
6 |
7 | class InputVideoUrlDialog extends StatelessWidget {
8 | InputVideoUrlDialog({super.key, required this.onInputUrlCallback});
9 |
10 | final UrlCallBack onInputUrlCallback;
11 | final TextEditingController _controller = TextEditingController();
12 |
13 | @override
14 | Widget build(BuildContext context) {
15 | return Container(
16 | width: 320,
17 | height: 240,
18 | padding: const EdgeInsets.all(16),
19 | decoration: BoxDecoration(
20 | color: Theme.of(context).cardColor,
21 | borderRadius: BorderRadius.circular(8),
22 | ),
23 | child: Column(
24 | children: [
25 | const SizedBox(height: 16),
26 | const Text(
27 | '请输入视频地址',
28 | style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
29 | ),
30 | const SizedBox(height: 16),
31 | TextField(
32 | controller: _controller,
33 | decoration: const InputDecoration(
34 | border: OutlineInputBorder(),
35 | hintText: '请输入视频地址',
36 | ),
37 | ),
38 | const SizedBox(height: 16),
39 | Row(
40 | mainAxisAlignment: MainAxisAlignment.spaceAround,
41 | children: [
42 | ElevatedButton(
43 | onPressed: () {
44 | SmartDialog.dismiss();
45 | },
46 | child: const Text('取消'),
47 | ),
48 | ElevatedButton(
49 | onPressed: () {
50 | onInputUrlCallback(_controller.text);
51 | SmartDialog.dismiss();
52 | },
53 | child: const Text('确定'),
54 | ),
55 | ],
56 | ),
57 | ],
58 | ),
59 | );
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/lib/ext/string_ext.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
2 |
3 | import '../includes.dart';
4 |
5 | extension StringExt on String {
6 | void showToast() {
7 | if (trim().isNotEmpty) {
8 | SmartDialog.showToast(this, alignment: Alignment.center);
9 | }
10 | }
11 |
12 | void showSnackBar() {
13 | if (trim().isNotEmpty) {
14 | Get.snackbar("提示", this, colorText: Colors.white);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/lib/generated/assets.dart:
--------------------------------------------------------------------------------
1 | ///This file is automatically generated. DO NOT EDIT, all your changes would be lost.
2 | class QAssets {
3 | QAssets._();
4 |
5 | static const String assetsWatchTogether = 'assets/watch_together.crt';
6 | static const String iconIcApp = 'assets/icon/ic_app.png';
7 | static const String iconIcMovie = 'assets/icon/ic_movie.png';
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/lib/includes.dart:
--------------------------------------------------------------------------------
1 | library includes;
2 |
3 | export 'package:flutter/material.dart';
4 | export 'package:flutter/widgets.dart';
5 | export 'package:get/get.dart';
6 | export 'dart:async';
7 |
8 |
--------------------------------------------------------------------------------
/lib/info/player_info.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:flutter/foundation.dart';
4 |
5 | /// 传递json对象实体
6 | class PlayerInfo {
7 | String url = ""; //播放地址
8 | bool isPlaying = false; // 是否正在播放
9 | int position = 0; //播放进度 单位 秒
10 |
11 | PlayerInfo(
12 | {this.url = "",
13 | this.isPlaying = false,
14 | this.position = 0});
15 |
16 | factory PlayerInfo.fromJson(Map json) {
17 | return PlayerInfo(
18 | url: json['url'],
19 | isPlaying: json['isPlaying'],
20 | position: json['position'],
21 | );
22 | }
23 |
24 | Map toJson() {
25 | final Map data = {};
26 | data['url'] = url;
27 | data['isPlaying'] = isPlaying;
28 | data['position'] = position;
29 | return data;
30 | }
31 |
32 | String toJsonString() {
33 | return jsonEncode(toJson());
34 | }
35 |
36 | static PlayerInfo fromJsonString(String json) {
37 | try {
38 | return PlayerInfo.fromJson(jsonDecode(json));
39 | } catch (e) {
40 | if (kDebugMode) {
41 | print(e);
42 | }
43 | return PlayerInfo();
44 | }
45 | }
46 |
47 | ///拷贝
48 | PlayerInfo copyWith({
49 | String? url,
50 | bool? isPlaying,
51 | int? position,
52 | }) =>
53 | PlayerInfo(
54 | url: url ?? this.url,
55 | isPlaying: isPlaying ?? this.isPlaying,
56 | position: position ?? this.position,
57 | );
58 | }
59 |
--------------------------------------------------------------------------------
/lib/info/room_info.dart:
--------------------------------------------------------------------------------
1 | import 'player_info.dart';
2 |
3 | ///房间信息管理
4 | class RoomInfo {
5 | static final RoomInfo _singleton = RoomInfo._internal();
6 |
7 | factory RoomInfo() {
8 | return _singleton;
9 | }
10 |
11 | RoomInfo._internal();
12 |
13 | ///房间号 6位数字 字符串
14 | static String roomId = "";
15 |
16 | ///是否是房主
17 | static bool isOwner = false;
18 |
19 | ///房间播放状态
20 | static PlayerInfo playerInfo = PlayerInfo();
21 |
22 | ///重置房间信息
23 | static void reset() {
24 | roomId = "";
25 | isOwner = false;
26 | playerInfo = PlayerInfo();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/lib/logger/log_printer.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:logger/logger.dart';
4 |
5 | class CPrinter extends LogPrinter {
6 | static const topLeftCorner = '┌';
7 | static const bottomLeftCorner = '└';
8 | static const middleCorner = '├';
9 | static const verticalLine = '│';
10 | static const doubleDivider = '─';
11 | static const singleDivider = '┄';
12 |
13 | static final levelColors = {
14 | Level.trace: AnsiColor.fg(AnsiColor.grey(0.5)),
15 | Level.debug: const AnsiColor.none(),
16 | Level.info: const AnsiColor.fg(12),
17 | Level.warning: const AnsiColor.fg(208),
18 | Level.error: const AnsiColor.fg(196),
19 | Level.fatal: const AnsiColor.fg(199),
20 | };
21 |
22 | static final levelEmojis = {
23 | Level.trace: '',
24 | Level.debug: '🐛 ',
25 | Level.info: '💡 ',
26 | Level.warning: '⚠️ ',
27 | Level.error: '⛔ ',
28 | Level.fatal: '👾 ',
29 | };
30 |
31 | /// Matches a stacktrace line as generated on Android/iOS devices.
32 | /// For example:
33 | /// #1 Logger.log (package:logger/src/logger.dart:115:29)
34 | static final _deviceStackTraceRegex = RegExp(r'#[0-9]+\s+(.+) \((\s+)\)');
35 |
36 | /// Matches a stacktrace line as generated by Flutter web.
37 | /// For example:
38 | /// packages/logger/src/printers/pretty_printer.dart 91:37
39 | static final _webStackTraceRegex = RegExp(r'^((packages|dart-sdk)/\S+/)');
40 |
41 | static late DateTime _startTime;
42 |
43 | late final int offsetMethodCount;
44 | late final int methodCount;
45 | final int? errorMethodCount;
46 | late final int lineLength;
47 | final bool? colors;
48 | late final bool printEmojis;
49 | late final bool printTime;
50 |
51 | int? dynamicMethodCount;
52 | String? _topBorder = '';
53 | String _middleBorder = '';
54 | String? _bottomBorder = '';
55 | String? tag;
56 |
57 | CPrinter({
58 | this.offsetMethodCount = 2,
59 | this.methodCount = 2,
60 | this.errorMethodCount = 8,
61 | this.lineLength = 120,
62 | this.colors = true,
63 | this.printEmojis = true,
64 | this.printTime = false,
65 | }) {
66 | _startTime = DateTime.now();
67 |
68 | var doubleDividerLine = StringBuffer();
69 | var singleDividerLine = StringBuffer();
70 | for (var i = 0; i < lineLength - 1; i++) {
71 | doubleDividerLine.write(doubleDivider);
72 | singleDividerLine.write(singleDivider);
73 | }
74 |
75 | _topBorder = '$topLeftCorner$doubleDividerLine';
76 | _middleBorder = '$middleCorner$singleDividerLine';
77 | _bottomBorder = '$bottomLeftCorner$doubleDividerLine';
78 | }
79 |
80 | void setTag(String? tag) {
81 | tag = '';
82 | this.tag = tag;
83 | }
84 |
85 | void setDynamicMethodCount(int? dynamicMethodCount) {
86 | this.dynamicMethodCount = dynamicMethodCount;
87 | }
88 |
89 | @override
90 | List log(LogEvent event) {
91 | var messageStr = stringifyMessage(event.message);
92 |
93 | String? stackTraceStr;
94 | if (event.stackTrace == null) {
95 | final int methodCount = dynamicMethodCount ?? this.methodCount;
96 | dynamicMethodCount = null;
97 | if (methodCount > 0) {
98 | stackTraceStr = formatStackTrace(
99 | StackTrace.current, methodCount, offsetMethodCount);
100 | }
101 | } else {
102 | stackTraceStr = formatStackTrace(event.stackTrace, -1, 0);
103 | }
104 |
105 | var errorStr = event.error?.toString();
106 |
107 | String? timeStr;
108 | if (printTime) {
109 | timeStr = getTime();
110 | }
111 |
112 | return _formatAndPrint(
113 | event.level,
114 | messageStr,
115 | timeStr,
116 | errorStr,
117 | stackTraceStr,
118 | );
119 | }
120 |
121 | String? formatStackTrace(
122 | StackTrace? stackTrace, int methodCount, int offset) {
123 | var lines = stackTrace.toString().split('\n');
124 | var formatted = [];
125 | var count = 0;
126 | var curOffset = 0;
127 | for (var line in lines) {
128 | if (_discardDeviceStacktraceLine(line) ||
129 | _discardWebStacktraceLine(line)) {
130 | continue;
131 | }
132 | if (curOffset < offset) {
133 | curOffset++;
134 | continue;
135 | }
136 | formatted.add('#$count ${line.replaceFirst(RegExp(r'#\d+\s+'), '')}');
137 | if (methodCount > 0 && ++count == methodCount) {
138 | break;
139 | }
140 | }
141 |
142 | if (formatted.isEmpty) {
143 | return null;
144 | } else {
145 | return formatted.join('\n');
146 | }
147 | }
148 |
149 | bool _discardDeviceStacktraceLine(String line) {
150 | var match = _deviceStackTraceRegex.matchAsPrefix(line);
151 | if (match == null) {
152 | return false;
153 | }
154 | return match.group(2)?.startsWith('package:logger') == true;
155 | }
156 |
157 | bool _discardWebStacktraceLine(String line) {
158 | var match = _webStackTraceRegex.matchAsPrefix(line);
159 | if (match == null) {
160 | return false;
161 | }
162 | return match.group(1)?.startsWith('packages/logger') == true ||
163 | match.group(1)?.startsWith('dart-sdk/lib') == true;
164 | }
165 |
166 | String _threeDigits(int n) {
167 | if (n >= 100) return '$n';
168 | if (n >= 10) return '0$n';
169 | return '00$n';
170 | }
171 |
172 | String _twoDigits(int n) {
173 | if (n >= 10) return '$n';
174 | return '0$n';
175 | }
176 |
177 | String getTime() {
178 | var now = DateTime.now();
179 | var h = _twoDigits(now.hour);
180 | var min = _twoDigits(now.minute);
181 | var sec = _twoDigits(now.second);
182 | var ms = _threeDigits(now.millisecond);
183 | var timeSinceStart = now.difference(_startTime).toString();
184 | return '$h:$min:$sec.$ms (+$timeSinceStart)';
185 | }
186 |
187 | String stringifyMessage(dynamic message) {
188 | if (message is Map || message is Iterable) {
189 | var encoder = const JsonEncoder.withIndent(' ');
190 | return encoder.convert(message);
191 | } else {
192 | return message.toString();
193 | }
194 | }
195 |
196 | AnsiColor _getLevelColor(Level level) {
197 | if (colors == true) {
198 | return levelColors[level] ?? const AnsiColor.none();
199 | } else {
200 | return const AnsiColor.none();
201 | }
202 | }
203 |
204 | AnsiColor _getErrorColor(Level level) {
205 | if (colors == true) {
206 | if (level == Level.fatal) {
207 | return levelColors[Level.fatal]?.toBg() ?? const AnsiColor.none();
208 | } else {
209 | return levelColors[Level.error]?.toBg() ?? const AnsiColor.none();
210 | }
211 | } else {
212 | return const AnsiColor.none();
213 | }
214 | }
215 |
216 | String _getEmoji(Level level) {
217 | if (printEmojis) {
218 | return levelEmojis[level] ?? '';
219 | } else {
220 | return '';
221 | }
222 | }
223 |
224 | List _formatAndPrint(
225 | Level level,
226 | String message,
227 | String? time,
228 | String? error,
229 | String? stacktrace,
230 | ) {
231 | // This code is non trivial and a type annotation here helps understanding.
232 | // ignore: omit_local_variable_types
233 | List buffer = [];
234 | var color = _getLevelColor(level);
235 | buffer.add(color('${tag ?? ""}$_topBorder'));
236 |
237 | if (error != null) {
238 | var errorColor = _getErrorColor(level);
239 | for (var line in error.split('\n')) {
240 | buffer.add(
241 | color('${tag ?? ""}$verticalLine ') +
242 | errorColor.resetForeground +
243 | errorColor(line) +
244 | errorColor.resetBackground,
245 | );
246 | }
247 | buffer.add(color('${tag ?? ""}$_middleBorder'));
248 | }
249 |
250 | if (stacktrace != null) {
251 | for (var line in stacktrace.split('\n')) {
252 | buffer.add('${tag ?? ""}$color$verticalLine $line');
253 | }
254 | buffer.add(color('${tag ?? ""}$_middleBorder'));
255 | }
256 |
257 | if (time != null) {
258 | buffer
259 | ..add(color('${tag ?? ""}$verticalLine $time'))
260 | ..add(color(_middleBorder));
261 | }
262 |
263 | var emoji = _getEmoji(level);
264 | for (var line in message.split('\n')) {
265 | buffer.add(color('${tag ?? ""}$verticalLine $emoji$line'));
266 | }
267 | buffer.add(color('${tag ?? ""}$_bottomBorder'));
268 | tag = null;
269 | return buffer;
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/lib/logger/log_utils.dart:
--------------------------------------------------------------------------------
1 | import 'package:logger/logger.dart';
2 |
3 | import 'log_printer.dart';
4 |
5 | class QLog {
6 | static const tag = 'QLOG';
7 |
8 | QLog._();
9 |
10 | static final CPrinter _printer =
11 | CPrinter(colors: true, printEmojis: false, printTime: true);
12 | static final Logger _logger = Logger(
13 | printer: PrettyPrinter(),
14 | level: Level.trace,
15 | );
16 |
17 |
18 | static CPrinter get printer => _printer;
19 |
20 | static void v(dynamic message,
21 | {String tag = QLog.tag,
22 | dynamic error,
23 | StackTrace? stackTrace,
24 | int? methodCount}) {
25 | _printer.setTag(tag);
26 | _printer.setDynamicMethodCount(methodCount);
27 | _logger.i(message ?? "null",error: error, stackTrace: stackTrace);
28 | }
29 |
30 | /// [message] 日志msg
31 | /// [tag]
32 | /// [error]
33 | /// [stackTrace]
34 | /// [methodCount] 日志堆栈层级数量,默认2
35 | static void d(dynamic message,
36 | {String tag = QLog.tag,
37 | dynamic error,
38 | StackTrace? stackTrace,
39 | int? methodCount}) {
40 | _printer.setTag(tag);
41 | _printer.setDynamicMethodCount(methodCount);
42 | _logger.d(message ?? "null",error: error, stackTrace: stackTrace);
43 | }
44 |
45 | static void i(dynamic message,
46 | {String tag = QLog.tag,
47 | dynamic error,
48 | StackTrace? stackTrace,
49 | int? methodCount}) {
50 | _printer.setTag(tag);
51 | _printer.setDynamicMethodCount(methodCount);
52 | _logger.i(message ?? "null", error: error, stackTrace: stackTrace);
53 | }
54 |
55 | static void w(dynamic message,
56 | {String tag = QLog.tag,
57 | dynamic error,
58 | StackTrace? stackTrace,
59 | int? methodCount}) {
60 | _printer.setTag(tag);
61 | _printer.setDynamicMethodCount(methodCount);
62 | _logger.w(message ?? "null", error: error, stackTrace: stackTrace);
63 | }
64 |
65 | static void e(dynamic message,
66 | {String tag = QLog.tag,
67 | dynamic error,
68 | StackTrace? stackTrace,
69 | int? methodCount}) {
70 | _printer.setTag(tag);
71 | _printer.setDynamicMethodCount(methodCount);
72 | _logger.e(message ?? "null", error: error, stackTrace: stackTrace);
73 | }
74 |
75 | static close() {
76 | _logger.close();
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:watch_together/config_device.dart';
3 | import 'package:watch_together/route/router_helper.dart';
4 | import 'package:watch_together/utils/platform_utils.dart';
5 |
6 | import 'config_window.dart';
7 |
8 | void main() async {
9 | await ConfigDevice.init();
10 | if (PlatFormUtils.isDesktop()) {
11 | await ConfigWindow.init();
12 | }
13 | runApp(RouterHelper.init());
14 | }
15 |
--------------------------------------------------------------------------------
/lib/main_web.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:watch_together/route/router_web.dart';
3 |
4 | import 'config_web.dart';
5 |
6 | void main() async {
7 | await ConfigWeb.init();
8 | runApp(RouterWeb.init());
9 | }
10 |
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_client.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:mqtt_client/mqtt_client.dart';
4 | import 'package:watch_together/logger/log_utils.dart';
5 |
6 | import 'mqtt_config.dart';
7 | import 'mqtt_observer.dart';
8 |
9 | abstract class XMqttClient {
10 | MqttClient? _client;
11 |
12 | final List _observers = [];
13 | final List _onConnectedListener = [];
14 | final List _onDisconnectedListener = [];
15 |
16 | Future buildClient();
17 |
18 | Future connect() async {
19 | MqttClient client = await buildClient();
20 | _client = client;
21 | //config
22 | client.logging(on: true);
23 | client.keepAlivePeriod = 60;
24 | client.connectTimeoutPeriod = 60;
25 | client.autoReconnect = false;
26 | client.resubscribeOnAutoReconnect = false;
27 |
28 | //callback
29 | client.onDisconnected = _onDisconnected;
30 | client.onConnected = _onConnected;
31 | client.onSubscribed = _onSubscribed;
32 |
33 | //connect
34 | try {
35 | client.setProtocolV311();
36 | //开始连接
37 | var mqttClientConnectionStatus =
38 | await client.connect(MqttConfig.username, MqttConfig.password);
39 | //检查连接结果
40 | if (MqttConnectionState.connected == mqttClientConnectionStatus?.state) {
41 | //连接成功
42 | //listener
43 | client.published?.listen(_publishListen);
44 | client.updates?.listen(_onDataArrived);
45 | return true;
46 | } else {
47 | //连接失败
48 | QLog.e(
49 | 'mqtt client connection failed - disconnecting, status is ${mqttClientConnectionStatus?.state}');
50 | client.disconnect();
51 | return false;
52 | }
53 | } on Exception catch (e) {
54 | QLog.e('mqtt client exception - $e');
55 | client.disconnect();
56 | return false;
57 | }
58 | }
59 |
60 | ///断开连接
61 | void disconnect() {
62 | if (isConnected()) {
63 | _client?.disconnect();
64 | } else {
65 | QLog.d('mqtt client already disconnected');
66 | }
67 | }
68 |
69 | ///订阅mqtt主题
70 | void _subscribe(String topic) {
71 | _client?.subscribe(topic, MqttQos.atLeastOnce);
72 | }
73 |
74 | ///取消主题订阅
75 | void unsubscribe(String topic) {
76 | _client?.unsubscribe(topic);
77 | _observers.removeWhere((element) => element.topic == topic);
78 | }
79 |
80 | ///订阅mqtt主题回调
81 | void subscribeWithObserver(XMqttObserver observer) {
82 | _observers.add(observer);
83 | _subscribe(observer.topic);
84 | }
85 |
86 | ///发送主题消息
87 | void publish(String topic, String message) {
88 | final MqttClientPayloadBuilder builder = MqttClientPayloadBuilder();
89 | builder.addUTF8String(message);
90 | _client?.publishMessage(topic, MqttQos.atLeastOnce, builder.payload!);
91 | QLog.d('mqtt client publish: $topic - $message');
92 | }
93 |
94 | ///发送回调监听
95 | void _publishListen(MqttPublishMessage message) {
96 | /*final String payload =
97 | MqttPublishPayload.bytesToStringAsString(message.payload.message);
98 | QLog.d(
99 | 'mqtt client publish listen: ${message.variableHeader?.topicName} - $payload');*/
100 | }
101 |
102 | ///接收回调监听
103 | void _onDataArrived(List> msgList) {
104 | for (var msg in msgList) {
105 | final String topic = msg.topic;
106 | final MqttMessage message = msg.payload;
107 | _onMessageArriving(topic, message);
108 | }
109 | }
110 |
111 | ///接收消息监听
112 | void _onMessageArriving(String topic, MqttMessage message) {
113 | var buffer = (message as MqttPublishMessage).payload.message;
114 | //UTF-8 解码
115 | const decoder = Utf8Decoder();
116 | final String msg = decoder.convert(buffer);
117 | //final String msg = MqttPublishPayload.bytesToStringAsString(buffer);
118 | for (var observer in _observers) {
119 | if (topic == observer.topic) {
120 | observer.onMessage(topic, msg);
121 | }
122 | }
123 | }
124 |
125 | ///是否已连接
126 | bool isConnected() {
127 | return _client?.connectionStatus?.state == MqttConnectionState.connected;
128 | }
129 |
130 | ///添加连接监听
131 | void addOnConnectedListener(OnConnected listener) {
132 | _onConnectedListener.add(listener);
133 | }
134 |
135 | ///添加断开连接监听
136 | void addOnDisconnectedListener(OnDisconnected listener) {
137 | _onDisconnectedListener.add(listener);
138 | }
139 |
140 | void _onConnected() {
141 | for (var element in _onConnectedListener) {
142 | element();
143 | }
144 | QLog.d('mqtt client Connected');
145 | }
146 |
147 | void _onDisconnected() {
148 | for (var element in _onDisconnectedListener) {
149 | element();
150 | }
151 | _observers.clear();
152 | QLog.d('mqtt client Disconnected');
153 | }
154 |
155 | void _onSubscribed(String topic) {
156 | QLog.d('mqtt client Subscribed topic: $topic');
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_client_device.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter/services.dart';
4 | import 'package:mqtt_client/mqtt_client.dart';
5 | import 'package:mqtt_client/mqtt_server_client.dart';
6 | import 'package:watch_together/mqtt/mqtt_client.dart';
7 | import 'package:watch_together/mqtt/mqtt_config.dart';
8 | import 'package:watch_together/utils/client_id_util.dart';
9 |
10 | class MqttClientDevice extends XMqttClient {
11 | @override
12 | Future buildClient() async {
13 | MqttServerClient client = MqttServerClient.withPort(
14 | MqttConfig.host, ClientIdUtil.getClientId(), MqttConfig.port);
15 | var defaultContext = SecurityContext.defaultContext;
16 | var certBytes = await rootBundle.load(MqttConfig.crtFile);
17 | defaultContext.setTrustedCertificatesBytes(certBytes.buffer.asInt8List());
18 | client.securityContext = defaultContext;
19 | client.secure = true;
20 | return client;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_client_web.dart:
--------------------------------------------------------------------------------
1 | import 'package:mqtt_client/mqtt_browser_client.dart';
2 | import 'package:mqtt_client/mqtt_client.dart';
3 | import 'package:watch_together/mqtt/mqtt_client.dart';
4 | import 'package:watch_together/mqtt/mqtt_config.dart';
5 | import 'package:watch_together/utils/client_id_util.dart';
6 |
7 | class MqttClientWeb extends XMqttClient {
8 | @override
9 | Future buildClient() async {
10 | return MqttBrowserClient.withPort(
11 | MqttConfig.hostWeb, ClientIdUtil.getClientId(), MqttConfig.portWeb);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_config.dart:
--------------------------------------------------------------------------------
1 |
2 | abstract class MqttConfig {
3 | static const String hostWeb = 'wss://xbb25d71.ala.cn-hangzhou.emqxsl.cn/mqtt';
4 | static const int portWeb = 8084;
5 | static const String host = 'xbb25d71.ala.cn-hangzhou.emqxsl.cn';
6 | static const int port = 8883;
7 | static const String username = 'watch_together';
8 | static const String password = 'watch_together_0511';
9 | static const String clientId = 'watch_together_';
10 | static const String crtFile = 'assets/watch_together.crt';
11 | }
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_observer.dart:
--------------------------------------------------------------------------------
1 | typedef OnMessage = void Function(String topic, String message);
2 | typedef OnConnected = void Function();
3 | typedef OnDisconnected = void Function();
4 |
5 | class XMqttObserver {
6 | late String topic;
7 | late OnMessage onMessage;
8 |
9 | XMqttObserver(this.topic, this.onMessage);
10 | }
11 |
--------------------------------------------------------------------------------
/lib/mqtt/mqtt_topic.dart:
--------------------------------------------------------------------------------
1 | import 'package:watch_together/info/room_info.dart';
2 |
3 | ///订阅主题
4 | enum ActionTopic {
5 | join('join'),
6 |
7 | ///加入,加入后5秒没有收到房主同步信息,则自动创建房间
8 | play('play'),
9 |
10 | ///播放
11 | pause('pause'),
12 |
13 | ///暂停
14 | seek('seek'),
15 |
16 | ///跳转 参数为进度条时间,单位秒
17 | sync('sync'),
18 |
19 | ///弹幕消息
20 | danmaku('danmaku'),
21 |
22 | ///申请同步, 5s 没有收到state信息则表示房主离线,自动接替房主;
23 | state('state');
24 |
25 | ///同步状态,参数 url,isPlaying,position
26 | final String topic;
27 |
28 | const ActionTopic(this.topic);
29 |
30 | String getTopicWithRoomId(String roomId) {
31 | return '$roomId/$topic';
32 | }
33 |
34 | ///解析包含roomId的topic对应的action
35 | static ActionTopic getActionTopic(String topic) {
36 | for (var value in ActionTopic.values) {
37 | if (value.getTopicWithRoomId(RoomInfo.roomId) == topic) {
38 | return value;
39 | }
40 | }
41 | return ActionTopic.join;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/lib/page/join/join_logic.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/cupertino.dart';
2 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
3 | import 'package:get/get.dart';
4 | import 'package:watch_together/page/main/main_service.dart';
5 | import 'package:watch_together/route/route_ext.dart';
6 | import 'package:watch_together/route/routes.dart';
7 |
8 | class JoinLogic extends GetxController {
9 | var isLoading = false.obs;
10 | var isError = false.obs;
11 | TextEditingController roomIdController = TextEditingController();
12 | late MainService mainService;
13 |
14 | @override
15 | void onInit() {
16 | super.onInit();
17 | mainService = Get.find();
18 | roomIdController.addListener(() {
19 | isError.value = false;
20 | });
21 | }
22 |
23 | void joinRoom() {
24 | var roomId = roomIdController.text;
25 | if (roomId.length != 6) {
26 | isError.value = true;
27 | return;
28 | }
29 | isLoading.value = true;
30 | mainService.join(roomId).then((value) {
31 | isLoading.value = false;
32 | if (value) {
33 | Routes.main.pagePush();
34 | } else {
35 | SmartDialog.showToast("连接服务器失败");
36 | }
37 | });
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/lib/page/join/join_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:get/get.dart';
3 |
4 | import 'join_logic.dart';
5 |
6 | class JoinPage extends StatefulWidget {
7 | const JoinPage({Key? key}) : super(key: key);
8 |
9 | @override
10 | State createState() => _JoinPageState();
11 | }
12 |
13 | class _JoinPageState extends State {
14 | final logic = Get.put(JoinLogic());
15 |
16 | @override
17 | Widget build(BuildContext context) {
18 | return Scaffold(body: Obx(() {
19 | return Center(
20 | child: logic.isLoading.value
21 | ? const CircularProgressIndicator()
22 | : buildInputWidget(context));
23 | }));
24 | }
25 |
26 | Widget buildInputWidget(BuildContext context) {
27 | return Card(
28 | child: Container(
29 | padding: const EdgeInsets.all(16),
30 | width: 300,
31 | height: 200,
32 | child: Column(
33 | mainAxisAlignment: MainAxisAlignment.spaceAround,
34 | children: [
35 | Obx(() {
36 | return TextField(
37 | controller: logic.roomIdController,
38 | textAlign: TextAlign.center,
39 | style: const TextStyle(
40 | color: Colors.black,
41 | fontSize: 20,
42 | letterSpacing: 2,
43 | ),
44 | decoration: InputDecoration(
45 | hintText: "请输入房间号",
46 | errorText: logic.isError.value ? "请输入6位数的房间号" : null,
47 | ),
48 | keyboardType: TextInputType.number,
49 | autofocus: true,
50 | maxLength: 6,
51 | onSubmitted: (text) {
52 | logic.joinRoom();
53 | });
54 | }),
55 | MaterialButton(
56 | textColor: Colors.white,
57 | color: Colors.blue,
58 | child: const Text("加入"),
59 | onPressed: () {
60 | logic.joinRoom();
61 | }),
62 | ],
63 | ),
64 | ),
65 | );
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/lib/page/main/main_ext.dart:
--------------------------------------------------------------------------------
1 |
2 | import 'package:watch_together/dlna/dlna_flutter.dart';
3 | import 'package:watch_together/page/main/main_logic.dart';
4 | import 'package:watch_together/route/router_helper.dart';
5 |
6 | mixin DlnaOnMainLogic on MainLogic {
7 | final DlnaServer dlnaServer = DlnaServer(name: RouterHelper.appName);
8 |
9 | @override
10 | void onRoomOwnerChanged(bool isRoomOwner) {
11 | super.onRoomOwnerChanged(isRoomOwner);
12 | if (isRoomOwner) {
13 | dlnaServer.start(this);
14 | } else {
15 | dlnaServer.stop();
16 | }
17 | }
18 |
19 | @override
20 | void exitRoom() {
21 | super.exitRoom();
22 | dlnaServer.stop();
23 | }
24 | }
--------------------------------------------------------------------------------
/lib/page/main/main_logic.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
2 | import 'package:watch_together/dialog/dialog_input_video_url.dart';
3 | import 'package:watch_together/dlna/dlna_flutter.dart';
4 | import 'package:watch_together/ext/string_ext.dart';
5 | import 'package:watch_together/info/room_info.dart';
6 | import 'package:watch_together/logger/log_utils.dart';
7 | import 'package:watch_together/page/main/main_service.dart';
8 |
9 | import '../../includes.dart';
10 |
11 | abstract class MainLogic extends GetxController implements PlayerAction {
12 | final MainService mainService = Get.find();
13 | var isRoomOwner = false.obs;
14 | StreamSubscription? roomOwnerSub;
15 | StreamSubscription? danmakuSub;
16 |
17 | @override
18 | void onInit() {
19 | super.onInit();
20 | mainService.setPlayerInfoCallback(this);
21 | roomOwnerSub = mainService.getRoomOwnerStream().listen(onRoomOwnerChanged);
22 | danmakuSub = mainService.getDanmakuStream().listen(onDanmakuArrived);
23 | }
24 |
25 | @override
26 | void onClose() {
27 | super.onClose();
28 | mainService.setPlayerInfoCallback(null);
29 | }
30 |
31 | void onRoomOwnerChanged(bool isRoomOwner) {
32 | this.isRoomOwner.value = isRoomOwner;
33 | if (isRoomOwner) {
34 | QLog.d("start dlna server");
35 | "您已成为房主,可以进行投屏/设置播放地址等操作".showSnackBar();
36 | } else {
37 | QLog.d("stop dlna server");
38 | }
39 | }
40 |
41 | ///收到房主的弹幕消息,子类实现
42 | void onDanmakuArrived(String danmakuText);
43 |
44 | ///退出房间
45 | void exitRoom() {
46 | mainService.exit();
47 | roomOwnerSub?.cancel();
48 | danmakuSub?.cancel();
49 | roomOwnerSub = null;
50 | danmakuSub = null;
51 | }
52 |
53 | void sync() {
54 | if (RoomInfo.isOwner) {
55 | "您是房主,无需同步".showSnackBar();
56 | } else {
57 | "正在同步房主的播放进度".showSnackBar();
58 | mainService.sync();
59 | }
60 | }
61 |
62 | @mustCallSuper
63 | @override
64 | void pause() {
65 | RoomInfo.playerInfo.isPlaying = false;
66 | mainService.pause();
67 | }
68 |
69 | @mustCallSuper
70 | @override
71 | void play() {
72 | RoomInfo.playerInfo.isPlaying = true;
73 | mainService.play();
74 | }
75 |
76 | @mustCallSuper
77 | @override
78 | void seek(int position) {
79 | RoomInfo.playerInfo.position = position;
80 | mainService.seek(position);
81 | }
82 |
83 | @mustCallSuper
84 | @override
85 | void setUrl(String url) {
86 | RoomInfo.playerInfo.url = url;
87 | mainService.setUrl(url);
88 | }
89 |
90 | @mustCallSuper
91 | @override
92 | void stop() {
93 | RoomInfo.playerInfo.url = "";
94 | RoomInfo.playerInfo.isPlaying = false;
95 | }
96 |
97 | ///发送弹幕
98 | void sendDanmaku(String danmakuText) {
99 | mainService.sendDanmaku(danmakuText);
100 | }
101 |
102 | void showInputUrlDialog() {
103 | SmartDialog.show(
104 | builder: (context) {
105 | return InputVideoUrlDialog(
106 | onInputUrlCallback: (value) {
107 | setUrl(value);
108 | },
109 | );
110 | },
111 | );
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/lib/page/main/main_service.dart:
--------------------------------------------------------------------------------
1 | import 'dart:async';
2 |
3 | import 'package:async/async.dart';
4 | import 'package:get/get.dart';
5 | import 'package:watch_together/dlna/dlna_flutter.dart';
6 | import 'package:watch_together/info/player_info.dart';
7 | import 'package:watch_together/info/room_info.dart';
8 | import 'package:watch_together/logger/log_utils.dart';
9 | import 'package:watch_together/mqtt/mqtt_client.dart';
10 | import 'package:watch_together/mqtt/mqtt_observer.dart';
11 | import 'package:watch_together/mqtt/mqtt_topic.dart';
12 | import 'package:watch_together/utils/platform_utils.dart';
13 |
14 | class MainService extends GetxService {
15 | late XMqttClient mqttClient;
16 | final StreamController _roomOwnerController =
17 | StreamController.broadcast();
18 | final StreamController _danmakuStreamController =
19 | StreamController.broadcast();
20 | PlayerAction? _callback;
21 | bool _roomHasOwner = false;
22 | CancelableOperation? _cancelableOperation;
23 |
24 | //延迟时间,发起同步请求,到获取结果的延迟,用于计算播放进度
25 | int _delayTime = 0;
26 |
27 | //发起同步的时间
28 | int _syncTime = 0;
29 |
30 | Future init() async {
31 | mqttClient = PlatFormUtils.mqttClient!;
32 | mqttClient.addOnConnectedListener(_onConnected);
33 | mqttClient.addOnDisconnectedListener(_onDisconnected);
34 | return this;
35 | }
36 |
37 | ///连接服务器成功
38 | void _onConnected() {
39 | //先以游客身份入房,如果5s没有收到房主的同步信息,自动成为房主
40 | _beGuest();
41 | _subscribe(ActionTopic.danmaku); //订阅弹幕消息
42 | _syncTime = DateTime.now().millisecondsSinceEpoch;
43 | _pushAction(ActionTopic.join);
44 | //检查房间是否有房主
45 | _checkRoomOwner();
46 | }
47 |
48 | ///服务器离线
49 | void _onDisconnected() {
50 | _beGuest();
51 | }
52 |
53 | ///订阅action topic
54 | void _subscribe(ActionTopic topic) {
55 | if (mqttClient.isConnected()) {
56 | mqttClient.subscribeWithObserver(XMqttObserver(
57 | topic.getTopicWithRoomId(RoomInfo.roomId), _onMsgArrived));
58 | }
59 | }
60 |
61 | ///取消订阅action topic
62 | void _unsubscribe(ActionTopic topic) {
63 | if (mqttClient.isConnected()) {
64 | mqttClient.unsubscribe(topic.getTopicWithRoomId(RoomInfo.roomId));
65 | }
66 | }
67 |
68 | ///解析action topic
69 | void _parseAction(String topic, String message) {
70 | var action = ActionTopic.getActionTopic(topic);
71 | switch (action) {
72 | case ActionTopic.join:
73 | //是房主,接收到他人入房信息,同步播放信息
74 | if (RoomInfo.isOwner) {
75 | _pushAction(ActionTopic.state,
76 | message: RoomInfo.playerInfo.toJsonString());
77 | }
78 | break;
79 | case ActionTopic.play:
80 | int position = int.tryParse(message) ?? 0;
81 | _callback?.play();
82 | _seek(position);
83 | break;
84 | case ActionTopic.pause:
85 | int position = int.tryParse(message) ?? 0;
86 | _callback?.pause();
87 | _seek(position);
88 | break;
89 | case ActionTopic.seek:
90 | int position = int.tryParse(message) ?? 0;
91 | _seek(position);
92 | break;
93 | case ActionTopic.sync:
94 | //是房主,接收到他人请求同步信息,同步播放信息
95 | if (RoomInfo.isOwner) {
96 | _pushAction(ActionTopic.state,
97 | message: RoomInfo.playerInfo.toJsonString());
98 | }
99 | break;
100 | case ActionTopic.state:
101 | //计算延迟
102 | _delayTime = DateTime.now().millisecondsSinceEpoch - _syncTime;
103 | //收到房主同步信息,表示房间有房主
104 | _roomHasOwner = true;
105 | //接收到房主的播放信息,同步本地播放器
106 | var playerInfo = PlayerInfo.fromJsonString(message);
107 | //如果url不一样,说明房主切换了视频,需要重新设置url
108 | if (playerInfo.url != RoomInfo.playerInfo.url) {
109 | _callback?.setUrl(playerInfo.url);
110 | }
111 | if (playerInfo.url.isEmpty) {
112 | _callback?.stop();
113 | return;
114 | }
115 | //播放暂停同步
116 | if (playerInfo.isPlaying) {
117 | _callback?.play();
118 | } else {
119 | _callback?.pause();
120 | }
121 | //同步进度
122 | int fixPosition = playerInfo.position + _delayTime ~/ 1000;
123 | _callback?.seek(fixPosition);
124 | playerInfo.position = fixPosition;
125 | RoomInfo.playerInfo = playerInfo;
126 | break;
127 | case ActionTopic.danmaku:
128 | //收到弹幕消息
129 | _danmakuStreamController.sink.add(message);
130 | break;
131 | default:
132 | break;
133 | }
134 | }
135 |
136 | ///sync remote seek
137 | void _seek(int position) {
138 | var fixPosition = position + _delayTime ~/ 1000;
139 | RoomInfo.playerInfo.position = fixPosition;
140 | _callback?.seek(fixPosition);
141 | }
142 |
143 | ///发送action topic
144 | void _pushAction(ActionTopic topic, {String message = '0'}) {
145 | if (!mqttClient.isConnected()) return;
146 | var data = message;
147 | if (message.isEmpty) {
148 | data = '0';
149 | }
150 | mqttClient.publish(topic.getTopicWithRoomId(RoomInfo.roomId), data);
151 | }
152 |
153 | void _onMsgArrived(String topic, String message) {
154 | QLog.d('mqtt client message arrived: $topic - $message');
155 | _parseAction(topic, message);
156 | }
157 |
158 | void setPlayerInfoCallback(PlayerAction? callback) {
159 | _callback = callback;
160 | }
161 |
162 | Stream getRoomOwnerStream() {
163 | return _roomOwnerController.stream;
164 | }
165 |
166 | Stream getDanmakuStream() {
167 | return _danmakuStreamController.stream;
168 | }
169 |
170 | ///加入房间
171 | Future join(String roomId) async {
172 | QLog.d("join room");
173 | RoomInfo.roomId = roomId;
174 | return mqttClient.connect();
175 | }
176 |
177 | ///退出房间
178 | void exit() {
179 | _cancelableOperation?.cancel();
180 | _cancelableOperation = null;
181 | _callback = null;
182 | mqttClient.disconnect();
183 | RoomInfo.reset();
184 | QLog.d("exit room");
185 | }
186 |
187 | ///请求房主同步播放信息,5秒没收到回复则自动成为房主
188 | void sync() {
189 | if (RoomInfo.isOwner) return;
190 | _syncTime = DateTime.now().millisecondsSinceEpoch;
191 | _pushAction(ActionTopic.sync);
192 | _checkRoomOwner();
193 | }
194 |
195 | void play() {
196 | if (!RoomInfo.isOwner) return;
197 | _pushAction(ActionTopic.play,
198 | message: RoomInfo.playerInfo.position.toString());
199 | }
200 |
201 | void pause() {
202 | if (!RoomInfo.isOwner) return;
203 | _pushAction(ActionTopic.pause,
204 | message: RoomInfo.playerInfo.position.toString());
205 | }
206 |
207 | void seek(int position) {
208 | if (!RoomInfo.isOwner) return;
209 | _pushAction(ActionTopic.seek, message: position.toString());
210 | }
211 |
212 | void setUrl(String url) {
213 | if (!RoomInfo.isOwner) return;
214 | _pushAction(ActionTopic.state, message: RoomInfo.playerInfo.toJsonString());
215 | }
216 |
217 | void _checkRoomOwner() {
218 | _roomHasOwner = false;
219 | //倒计时5秒
220 | var future = Future.delayed(const Duration(seconds: 5), () {
221 | if (_callback == null) return;
222 | if (!_roomHasOwner) {
223 | //空房间,自动成为房主
224 | _beOwner();
225 | _pushAction(ActionTopic.state,
226 | message: RoomInfo.playerInfo.toJsonString());
227 | }
228 | });
229 | _cancelableOperation = CancelableOperation.fromFuture(future, onCancel: () {
230 | QLog.d("cancel check room owner");
231 | });
232 | }
233 |
234 | ///成为房主,需监听加入房间信息,和请求同步播放进度信息,其它信息忽略
235 | void _beOwner() {
236 | RoomInfo.isOwner = true;
237 | _subscribe(ActionTopic.join);
238 | _subscribe(ActionTopic.sync);
239 | _unsubscribe(ActionTopic.play);
240 | _unsubscribe(ActionTopic.pause);
241 | _unsubscribe(ActionTopic.seek);
242 | _unsubscribe(ActionTopic.state);
243 | _roomOwnerController.sink.add(RoomInfo.isOwner);
244 | }
245 |
246 | ///成为客户端,需监听播放,暂停,跳转,同步播放进度信息,其它信息忽略
247 | void _beGuest() {
248 | RoomInfo.isOwner = false;
249 | _subscribe(ActionTopic.play);
250 | _subscribe(ActionTopic.pause);
251 | _subscribe(ActionTopic.seek);
252 | _subscribe(ActionTopic.state);
253 | _unsubscribe(ActionTopic.join);
254 | _unsubscribe(ActionTopic.sync);
255 | _roomOwnerController.sink.add(RoomInfo.isOwner);
256 | }
257 |
258 | ///发送弹幕消息
259 | void sendDanmaku(String message) {
260 | _pushAction(ActionTopic.danmaku, message: message);
261 | }
262 | }
263 |
--------------------------------------------------------------------------------
/lib/page/main/main_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:watch_together/page/video/desktop/desktop_video_page.dart';
3 | import 'package:watch_together/page/video/phone/phone_video_page.dart';
4 | import 'package:watch_together/utils/platform_utils.dart';
5 |
6 | class MainPage extends StatelessWidget {
7 | const MainPage({Key? key}) : super(key: key);
8 |
9 | @override
10 | Widget build(BuildContext context) {
11 | if (PlatFormUtils.isMobile()) {
12 | return const PhoneVideoPage();
13 | } else if (PlatFormUtils.isDesktop()) {
14 | return const DesktopVideoPage();
15 | } else {
16 | return const Center(
17 | child: Text('暂不支持该平台'),
18 | );
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/lib/page/video/desktop/desktop_video_logic.dart:
--------------------------------------------------------------------------------
1 | import 'package:dart_vlc/dart_vlc.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:wakelock/wakelock.dart';
4 | import 'package:watch_together/constants.dart';
5 | import 'package:watch_together/info/room_info.dart';
6 | import 'package:watch_together/logger/log_utils.dart';
7 | import 'package:watch_together/page/main/main_ext.dart';
8 | import 'package:watch_together/page/main/main_logic.dart';
9 |
10 | import '../../../includes.dart';
11 |
12 | class DesktopVideoLogic extends MainLogic with DlnaOnMainLogic {
13 | Player player = Player(id: 511);
14 | MediaType mediaType = MediaType.file;
15 | CurrentState current = CurrentState();
16 | PositionState position = PositionState();
17 | PlaybackState playback = PlaybackState();
18 | GeneralState general = GeneralState();
19 | VideoDimensions videoDimensions = const VideoDimensions(0, 0);
20 | List medias = [];
21 |
22 | //List devices = [];
23 | final TextEditingController controller = TextEditingController();
24 | final TextEditingController metasController = TextEditingController();
25 | double bufferingProgress = 0.0;
26 | Media? metasMedia;
27 |
28 | final BarrageWallController barrageWallController = BarrageWallController();
29 |
30 | var isDanmakuInputShow = false.obs;
31 | bool prepared = false;
32 |
33 | @override
34 | void onInit() {
35 | super.onInit();
36 | player.setVolume(0.5);
37 | player.currentStream.listen((current) {
38 | this.current = current;
39 | });
40 | player.positionStream.listen((position) {
41 | this.position = position;
42 | if (!RoomInfo.isOwner) return;
43 | var pos = position.position;
44 | if (pos != null) {
45 | //房主才记录拖拽进度,绝对值大于3秒才同步给其他人
46 | if ((pos.inSeconds - RoomInfo.playerInfo.position).abs() >
47 | Constants.diffSec) {
48 | mainService.seek(pos.inSeconds);
49 | }
50 | RoomInfo.playerInfo.position = pos.inSeconds;
51 | }
52 | });
53 | player.playbackStream.listen((playback) {
54 | bool playing = playback.isPlaying;
55 | //第一次播放,算作初始化完成
56 | if (!prepared) {
57 | prepared = true;
58 | if (!RoomInfo.isOwner) {
59 | seek(RoomInfo.playerInfo.position);
60 | if (RoomInfo.playerInfo.isPlaying) {
61 | player.play();
62 | Wakelock.enable();
63 | } else {
64 | player.pause();
65 | Wakelock.disable();
66 | }
67 | } else {
68 | super.play();
69 | Wakelock.enable();
70 | }
71 | return;
72 | }
73 | //播放暂停控制
74 | if (playing) {
75 | super.play();
76 | Wakelock.enable();
77 | } else {
78 | super.pause();
79 | Wakelock.disable();
80 | }
81 | RoomInfo.playerInfo.isPlaying = playing;
82 | });
83 | player.generalStream.listen((general) {
84 | this.general = general;
85 | });
86 | player.videoDimensionsStream.listen((videoDimensions) {
87 | this.videoDimensions = videoDimensions;
88 | });
89 | player.bufferingProgressStream.listen(
90 | (bufferingProgress) {
91 | this.bufferingProgress = bufferingProgress;
92 | },
93 | );
94 | player.errorStream.listen((event) {
95 | QLog.e('libvlc error: $event', tag: 'DesktopVideoLogic');
96 | });
97 | //devices = Devices.all;
98 | Equalizer equalizer = Equalizer.createMode(EqualizerMode.live);
99 | equalizer.setPreAmp(10.0);
100 | equalizer.setBandAmp(31.25, 10.0);
101 | player.setEqualizer(equalizer);
102 | }
103 |
104 | @override
105 | void exitRoom() {
106 | player.stop();
107 | player.dispose();
108 | super.exitRoom();
109 | }
110 |
111 | @override
112 | int getDuration() {
113 | //dlna need
114 | return player.position.duration?.inSeconds ?? 0;
115 | }
116 |
117 | @override
118 | int getPosition() {
119 | //dlna need
120 | return player.position.position?.inSeconds ?? 0;
121 | }
122 |
123 | @override
124 | int getVolume() {
125 | //dlna need
126 | return (player.general.volume * 100).toInt();
127 | }
128 |
129 | @override
130 | void pause() {
131 | super.pause();
132 | //dlna or mqtt call
133 | player.pause();
134 | }
135 |
136 | @override
137 | void play() {
138 | super.play();
139 | player.play();
140 | }
141 |
142 | @override
143 | void seek(int position) {
144 | super.seek(position);
145 | prepared = false;
146 | player.seek(Duration(seconds: position));
147 | }
148 |
149 | @override
150 | void setUrl(String url) {
151 | if (url == RoomInfo.playerInfo.url) return;
152 | super.setUrl(url);
153 | prepared = false;
154 | RoomInfo.playerInfo.isPlaying = true;
155 | var media = Media.network(url);
156 | player.open(media);
157 | }
158 |
159 | @override
160 | void stop() {
161 | super.stop();
162 | player.stop();
163 | }
164 |
165 | @override
166 | void onDanmakuArrived(String danmakuText) {
167 | _addDanmaku(danmakuText);
168 | }
169 |
170 | ///屏幕展示弹幕
171 | void _addDanmaku(String message) {
172 | barrageWallController.send([
173 | Bullet(
174 | child: Text(
175 | message,
176 | style: const TextStyle(color: Colors.white, fontSize: 16),
177 | ),
178 | ),
179 | ]);
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/lib/page/video/desktop/desktop_video_page.dart:
--------------------------------------------------------------------------------
1 | import 'package:dart_vlc/dart_vlc.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:watch_together/includes.dart';
4 | import 'package:watch_together/info/room_info.dart';
5 | import 'package:watch_together/page/video/desktop/desktop_video_logic.dart';
6 | import 'package:watch_together/widget/widget_send_danmaku.dart';
7 |
8 | class DesktopVideoPage extends StatelessWidget {
9 | const DesktopVideoPage({super.key});
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | var logic = Get.put(DesktopVideoLogic());
14 | return WillPopScope(
15 | onWillPop: () {
16 | logic.exitRoom();
17 | return Future.value(true);
18 | },
19 | child: Scaffold(
20 | appBar: AppBar(
21 | title: Obx(() {
22 | return Text(
23 | "房间号:${RoomInfo.roomId}(${logic.isRoomOwner.value
24 | ? "房主"
25 | : "观众"})");
26 | }),
27 | actions: [
28 | Obx(() {
29 | return IconButton(
30 | icon: Icon(
31 | Icons.send,
32 | color: logic.isDanmakuInputShow.value
33 | ? Colors.yellowAccent
34 | : Colors.white,
35 | ),
36 | tooltip: '发送弹幕',
37 | onPressed: () {
38 | logic.isDanmakuInputShow.value =
39 | !logic.isDanmakuInputShow.value;
40 | },
41 | );
42 | }),
43 | Obx(() {
44 | return Visibility(
45 | visible: logic.isRoomOwner.value,
46 | child: IconButton(
47 | icon: const Icon(Icons.input),
48 | tooltip: '输入视频地址',
49 | onPressed: () => logic.showInputUrlDialog(),
50 | ),
51 | );
52 | }),
53 | Obx(() {
54 | return Visibility(
55 | visible: !logic.isRoomOwner.value,
56 | child: IconButton(
57 | icon: const Icon(Icons.sync),
58 | tooltip: '同步进度',
59 | onPressed: () => logic.sync(),
60 | ),
61 | );
62 | }),
63 | ],
64 | ),
65 | body: Column(
66 | children: [
67 | Flexible(
68 | child: Stack(
69 | children: [
70 | Video(
71 | player: logic.player,
72 | volumeThumbColor: Colors.blue,
73 | volumeActiveColor: Colors.blue,
74 | ),
75 | Positioned(
76 | left: 0,
77 | right: 0,
78 | top: 0,
79 | bottom: 0,
80 | child: BarrageWall(
81 | controller: logic.barrageWallController,
82 | child: Container(),
83 | ),
84 | )
85 | ],
86 | ),
87 | ),
88 | Obx(() {
89 | return Visibility(
90 | visible: logic.isDanmakuInputShow.value,
91 | child: SendDanmakuInput(
92 | onSend: (text) => logic.sendDanmaku(text),
93 | ),
94 | );
95 | }),
96 | ],
97 | ),
98 | ),
99 | );
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/lib/page/video/phone/phone_video_logic.dart:
--------------------------------------------------------------------------------
1 | import 'package:fijkplayer/fijkplayer.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:wakelock/wakelock.dart';
4 | import 'package:watch_together/constants.dart';
5 | import 'package:watch_together/info/room_info.dart';
6 | import 'package:watch_together/logger/log_utils.dart';
7 | import 'package:watch_together/page/main/main_ext.dart';
8 | import 'package:watch_together/page/main/main_logic.dart';
9 | import 'package:watch_together/utils/task_queue_utils.dart';
10 |
11 | import '../../../includes.dart';
12 |
13 | class PhoneVideoLogic extends MainLogic with DlnaOnMainLogic {
14 | final FijkPlayer player = FijkPlayer();
15 | final BarrageWallController barrageWallController = BarrageWallController();
16 | final TaskQueueUtils taskQueueUtils = TaskQueueUtils();
17 |
18 | @override
19 | void onInit() {
20 | super.onInit();
21 | player.addListener(_playerValueChanged);
22 | player.onCurrentPosUpdate.listen((pos) {
23 | if (!RoomInfo.isOwner) return;
24 | //房主拖拽进度,绝对值大于3秒才同步
25 | if ((pos.inSeconds - RoomInfo.playerInfo.position).abs() >
26 | Constants.diffSec) {
27 | mainService.seek(pos.inSeconds);
28 | }
29 | RoomInfo.playerInfo.position = pos.inSeconds;
30 | });
31 | }
32 |
33 | @override
34 | Future onClose() async {
35 | super.onClose();
36 | await player.stop();
37 | await player.release();
38 | QLog.i("PhoneVideoLogic : onClose");
39 | }
40 |
41 | void _addTask(Future future) {
42 | taskQueueUtils.addTask(() {
43 | return future;
44 | });
45 | }
46 |
47 | @override
48 | int getDuration() {
49 | //dlna need
50 | return player.value.duration.inSeconds;
51 | }
52 |
53 | @override
54 | int getPosition() {
55 | //dlna need
56 | return player.currentPos.inSeconds;
57 | }
58 |
59 | @override
60 | int getVolume() {
61 | //dlna need
62 | return 0;
63 | }
64 |
65 | @override
66 | void pause() {
67 | super.pause();
68 | //dlna or mqtt call
69 | if (player.isPlayable()) {
70 | //player.pause();
71 | _addTask(player.pause());
72 | }
73 | }
74 |
75 | @override
76 | void play() {
77 | super.play();
78 | //player.start();
79 | _addTask(player.start());
80 | }
81 |
82 | @override
83 | void seek(int position) {
84 | super.seek(position);
85 | //player.seekTo(position * 1000);
86 | _addTask(player.seekTo(position * 1000));
87 | }
88 |
89 | @override
90 | void setUrl(String url) {
91 | if (url == RoomInfo.playerInfo.url) return;
92 | super.setUrl(url);
93 | RoomInfo.playerInfo.isPlaying = true;
94 | //player.reset();
95 | //player.setDataSource(url, autoPlay: true);
96 | _addTask(player.reset());
97 | _addTask(player.setDataSource(url, autoPlay: true));
98 | }
99 |
100 | @override
101 | void stop() {
102 | super.stop();
103 | //player.stop();
104 | //player.reset();
105 | _addTask(player.stop());
106 | _addTask(player.reset());
107 | }
108 |
109 | //播放器状态监听(同步房间其他人)
110 | void _playerValueChanged() {
111 | FijkValue value = player.value;
112 | bool playing = (value.state == FijkState.started);
113 | if (playing != RoomInfo.playerInfo.isPlaying) {
114 | //播放暂停控制
115 | if (playing) {
116 | super.play();
117 | Wakelock.enable();
118 | } else {
119 | super.pause();
120 | Wakelock.disable();
121 | }
122 | RoomInfo.playerInfo.isPlaying = playing;
123 | }
124 | //视频加载完成
125 | if (value.state == FijkState.prepared) {
126 | if (!RoomInfo.isOwner) {
127 | if (RoomInfo.playerInfo.isPlaying) {
128 | //player.start();
129 | _addTask(player.start());
130 | Wakelock.enable();
131 | } else {
132 | //player.pause();
133 | _addTask(player.pause());
134 | Wakelock.disable();
135 | }
136 | //同步进度
137 | seek(RoomInfo.playerInfo.position);
138 | } else {
139 | //房主播放器准备完成,同步房间其他人
140 | play();
141 | }
142 | }
143 | }
144 |
145 | @override
146 | void onDanmakuArrived(String danmakuText) {
147 | _addDanmaku(danmakuText);
148 | }
149 |
150 | ///屏幕展示弹幕
151 | void _addDanmaku(String message) {
152 | barrageWallController.send([
153 | Bullet(
154 | child: Text(
155 | message,
156 | style: const TextStyle(color: Colors.white, fontSize: 16),
157 | ),
158 | ),
159 | ]);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/lib/page/video/phone/phone_video_page.dart:
--------------------------------------------------------------------------------
1 | import 'package:fijkplayer/fijkplayer.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:watch_together/includes.dart';
4 | import 'package:watch_together/info/room_info.dart';
5 | import 'package:watch_together/widget/widget_send_danmaku.dart';
6 |
7 | import 'phone_video_logic.dart';
8 |
9 | class PhoneVideoPage extends StatelessWidget {
10 | const PhoneVideoPage({super.key});
11 |
12 | @override
13 | Widget build(BuildContext context) {
14 | var logic = Get.put(PhoneVideoLogic());
15 | return WillPopScope(
16 | onWillPop: () {
17 | logic.exitRoom();
18 | return Future.value(true);
19 | },
20 | child: Scaffold(
21 | appBar: AppBar(
22 | title: Obx(() {
23 | return Text(
24 | "房间号:${RoomInfo.roomId}(${logic.isRoomOwner.value
25 | ? "房主"
26 | : "观众"})");
27 | }),
28 | ),
29 | body: Column(
30 | children: [
31 | Stack(
32 | children: [
33 | AspectRatio(
34 | aspectRatio: 16.0 / 9.0,
35 | child: FijkView(
36 | panelBuilder: fijkPanel2Builder(),
37 | player: logic.player,
38 | color: Colors.black,
39 | ),
40 | ),
41 | Positioned(
42 | left: 0,
43 | right: 0,
44 | top: 0,
45 | bottom: 0,
46 | child: BarrageWall(
47 | controller: logic.barrageWallController,
48 | child: Container(),
49 | ),
50 | )
51 | ],
52 | ),
53 | SendDanmakuInput(onSend: logic.sendDanmaku),
54 | Flexible(
55 | child: Container(
56 | padding: const EdgeInsets.all(16),
57 | child: const Text('''
58 | 1.由于各主流视频平台对于投屏协议的收紧,
59 | 目前测试只有百度网盘手机app全屏播放时能投屏本app,
60 | 开发者可以自行研究其他平台的投屏协议;
61 | 2.不支持本地视频投屏;
62 | 3.支持填写视频播放地址;
63 | '''),
64 | ),
65 | ),
66 | ],
67 | ),
68 | floatingActionButton: Obx(() {
69 | return FloatingActionButton(
70 | onPressed: () {
71 | if (logic.isRoomOwner.value) {
72 | logic.showInputUrlDialog();
73 | } else {
74 | logic.sync();
75 | }
76 | },
77 | child: Icon(logic.isRoomOwner.value ? Icons.input : Icons.sync),
78 | );
79 | }),
80 | ),
81 | );
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/lib/page/video/web/web_logic.dart:
--------------------------------------------------------------------------------
1 | import 'package:appinio_video_player/appinio_video_player.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:wakelock/wakelock.dart';
4 | import 'package:watch_together/constants.dart';
5 | import 'package:watch_together/info/room_info.dart';
6 | import 'package:watch_together/page/main/main_logic.dart';
7 | import 'package:watch_together/route/route_ext.dart';
8 | import 'package:watch_together/route/routes.dart';
9 |
10 | import '../../../includes.dart';
11 |
12 | class WebLogic extends MainLogic {
13 | VideoPlayerController? videoPlayerController;
14 | CustomVideoPlayerController? customVideoPlayerController;
15 |
16 | //弹幕控制器
17 | final BarrageWallController barrageWallController = BarrageWallController();
18 | var isDanmakuInputShow = false.obs;
19 |
20 | @override
21 | void onInit() {
22 | super.onInit();
23 | videoPlayerController = VideoPlayerController.network("");
24 | videoPlayerController?.addListener(_videoListener);
25 | customVideoPlayerController = CustomVideoPlayerController(
26 | context: Get.context!,
27 | videoPlayerController: videoPlayerController!,
28 | );
29 | }
30 |
31 | @override
32 | void onReady() {
33 | super.onReady();
34 | //浏览器刷新跳转房间号输入页面
35 | if (RoomInfo.roomId.length < 6) {
36 | Routes.root.pageOffAll();
37 | }
38 | }
39 |
40 | void _switchVideoSource(String source) async {
41 | await videoPlayerController?.pause();
42 | videoPlayerController?.removeListener(_videoListener);
43 | await videoPlayerController?.dispose();
44 | videoPlayerController = VideoPlayerController.network(source);
45 | videoPlayerController?.addListener(_videoListener);
46 | customVideoPlayerController = CustomVideoPlayerController(
47 | context: Get.context!,
48 | videoPlayerController: videoPlayerController!,
49 | );
50 | await videoPlayerController?.initialize();
51 | await videoPlayerController
52 | ?.seekTo(Duration(seconds: RoomInfo.playerInfo.position));
53 | await videoPlayerController?.play();
54 | update();
55 | }
56 |
57 | void _videoListener() {
58 | if (RoomInfo.isOwner) {
59 | var pos = getPosition();
60 | //房主才记录拖拽进度,绝对值大于3秒才同步给其他人
61 | if ((pos - RoomInfo.playerInfo.position).abs() > Constants.diffSec) {
62 | mainService.seek(pos);
63 | }
64 | RoomInfo.playerInfo.position = pos;
65 | }
66 | bool playing = videoPlayerController?.value.isPlaying ?? false;
67 | if (playing != RoomInfo.playerInfo.isPlaying) {
68 | //播放暂停控制
69 | if (playing) {
70 | super.play();
71 | Wakelock.enable();
72 | } else {
73 | super.pause();
74 | Wakelock.disable();
75 | }
76 | RoomInfo.playerInfo.isPlaying = playing;
77 | }
78 | }
79 |
80 | @override
81 | void exitRoom() {
82 | videoPlayerController?.dispose();
83 | super.exitRoom();
84 | }
85 |
86 | @override
87 | int getDuration() {
88 | return videoPlayerController?.value.duration.inSeconds ?? 0;
89 | }
90 |
91 | @override
92 | int getPosition() {
93 | return videoPlayerController?.value.position.inSeconds ?? 0;
94 | }
95 |
96 | @override
97 | int getVolume() {
98 | return videoPlayerController?.value.volume.round() ?? 0;
99 | }
100 |
101 | @override
102 | void pause() {
103 | super.pause();
104 | videoPlayerController?.pause();
105 | }
106 |
107 | @override
108 | void play() {
109 | super.play();
110 | videoPlayerController?.play();
111 | }
112 |
113 | @override
114 | void seek(int position) {
115 | super.seek(position);
116 | videoPlayerController?.seekTo(Duration(seconds: position));
117 | }
118 |
119 | @override
120 | void setUrl(String url) {
121 | if (url == RoomInfo.playerInfo.url) return;
122 | super.setUrl(url);
123 | RoomInfo.playerInfo.isPlaying = true;
124 | _switchVideoSource(url);
125 | }
126 |
127 | @override
128 | void stop() {
129 | super.stop();
130 | videoPlayerController?.dispose();
131 | }
132 |
133 | @override
134 | void onDanmakuArrived(String danmakuText) {
135 | _addDanmaku(danmakuText);
136 | }
137 |
138 | ///屏幕展示弹幕
139 | void _addDanmaku(String message) {
140 | barrageWallController.send([
141 | Bullet(
142 | child: Text(
143 | message,
144 | style: const TextStyle(color: Colors.white, fontSize: 16),
145 | ),
146 | ),
147 | ]);
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/lib/page/video/web/web_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:appinio_video_player/appinio_video_player.dart';
2 | import 'package:flutter_barrage/flutter_barrage.dart';
3 | import 'package:watch_together/info/room_info.dart';
4 | import 'package:watch_together/widget/widget_send_danmaku.dart';
5 |
6 | import '../../../includes.dart';
7 | import 'web_logic.dart';
8 |
9 | class WebPage extends StatelessWidget {
10 | const WebPage({Key? key}) : super(key: key);
11 |
12 | @override
13 | Widget build(BuildContext context) {
14 | final logic = Get.put(WebLogic());
15 | return WillPopScope(
16 | onWillPop: () {
17 | logic.exitRoom();
18 | return Future.value(true);
19 | },
20 | child: Scaffold(
21 | appBar: AppBar(
22 | title: Obx(() {
23 | return Text(
24 | "房间号:${RoomInfo.roomId}(${logic.isRoomOwner.value ? "房主" : "观众"})");
25 | }),
26 | actions: [
27 | Obx(() {
28 | return IconButton(
29 | icon: Icon(
30 | Icons.send,
31 | color: logic.isDanmakuInputShow.value
32 | ? Colors.yellowAccent
33 | : Colors.white,
34 | ),
35 | tooltip: '发送弹幕',
36 | onPressed: () {
37 | logic.isDanmakuInputShow.value =
38 | !logic.isDanmakuInputShow.value;
39 | },
40 | );
41 | }),
42 | Obx(() {
43 | return Visibility(
44 | visible: logic.isRoomOwner.value,
45 | child: IconButton(
46 | icon: const Icon(Icons.input),
47 | tooltip: '输入视频地址',
48 | onPressed: () => logic.showInputUrlDialog(),
49 | ),
50 | );
51 | }),
52 | Obx(() {
53 | return Visibility(
54 | visible: !logic.isRoomOwner.value,
55 | child: IconButton(
56 | icon: const Icon(Icons.sync),
57 | tooltip: '同步进度',
58 | onPressed: () => logic.sync(),
59 | ),
60 | );
61 | }),
62 | ],
63 | ),
64 | body: Column(
65 | children: [
66 | Expanded(
67 | child: Stack(
68 | children: [
69 | SafeArea(
70 | child: GetBuilder(builder: (logic) {
71 | return CustomVideoPlayer(
72 | customVideoPlayerController:
73 | logic.customVideoPlayerController!);
74 | }),
75 | ),
76 | Positioned(
77 | left: 0,
78 | right: 0,
79 | top: 0,
80 | bottom: 0,
81 | child: BarrageWall(
82 | controller: logic.barrageWallController,
83 | child: Container(),
84 | ),
85 | )
86 | ],
87 | ),
88 | ),
89 | Obx(() {
90 | return Visibility(
91 | visible: logic.isDanmakuInputShow.value,
92 | child: SendDanmakuInput(
93 | onSend: (text) => logic.sendDanmaku(text),
94 | ),
95 | );
96 | }),
97 | ],
98 | ),
99 | ),
100 | );
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/lib/route/pages.dart:
--------------------------------------------------------------------------------
1 | import 'package:get/get.dart';
2 | import 'package:watch_together/page/join/join_view.dart';
3 | import 'package:watch_together/page/main/main_view.dart';
4 |
5 | import 'routes.dart';
6 |
7 | abstract class Pages {
8 | static final pages = [
9 | GetPage(name: Routes.root, page: () => const JoinPage()),
10 | GetPage(
11 | name: Routes.main,
12 | page: () => const MainPage(),
13 | ),
14 | ];
15 | }
16 |
--------------------------------------------------------------------------------
/lib/route/pages_web.dart:
--------------------------------------------------------------------------------
1 | import 'package:get/get.dart';
2 | import 'package:watch_together/page/join/join_view.dart';
3 | import 'package:watch_together/page/video/web/web_view.dart';
4 |
5 | import 'routes.dart';
6 |
7 | abstract class PagesWeb {
8 | static final pages = [
9 | GetPage(name: Routes.root, page: () => const JoinPage()),
10 | GetPage(
11 | name: Routes.main,
12 | page: () => const WebPage(),
13 | ),
14 | ];
15 | }
16 |
--------------------------------------------------------------------------------
/lib/route/route_ext.dart:
--------------------------------------------------------------------------------
1 | import '../includes.dart';
2 |
3 | extension OffPage on String {
4 | ///跳转下一页并关闭当前页
5 | void pageOff({
6 | dynamic arguments,
7 | int? id,
8 | Map? parameters,
9 | }) {
10 | Get.offNamed(this, arguments: arguments, id: id, parameters: parameters);
11 | }
12 |
13 | ///跳转下一页并关闭前面所有页面
14 | void pageOffAll({
15 | RoutePredicate? predicate,
16 | dynamic arguments,
17 | int? id,
18 | Map? parameters,
19 | }) {
20 | Get.offAllNamed(this,
21 | predicate: predicate,
22 | arguments: arguments,
23 | id: id,
24 | parameters: parameters);
25 | }
26 |
27 | ///跳转下一页,不关闭当前页
28 | void pagePush({
29 | dynamic arguments,
30 | dynamic id,
31 | bool preventDuplicates = true,
32 | Map? parameters,
33 | }) {
34 | Get.toNamed(this,
35 | arguments: arguments,
36 | id: id,
37 | preventDuplicates: preventDuplicates,
38 | parameters: parameters);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/lib/route/router_helper.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
2 |
3 | import '../includes.dart';
4 | import 'pages.dart';
5 | import 'routes.dart';
6 |
7 | class RouterHelper {
8 | RouterHelper._internal();
9 |
10 | factory RouterHelper() => _instance;
11 |
12 | static final RouterHelper _instance = RouterHelper._internal();
13 |
14 | static const String appName = 'Watch Together';
15 |
16 | static Widget init() {
17 | return GetMaterialApp(
18 | title: appName,
19 | initialRoute: Routes.root,
20 | getPages: Pages.pages,
21 | builder: (context, child) {
22 | return FlutterSmartDialog(
23 | child: child ??
24 | const Center(
25 | child: Text('$appName Error'),
26 | ),
27 | );
28 | },
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/route/router_web.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
2 | import 'package:watch_together/route/pages_web.dart';
3 |
4 | import '../includes.dart';
5 | import 'routes.dart';
6 |
7 | class RouterWeb {
8 | RouterWeb._internal();
9 |
10 | factory RouterWeb() => _instance;
11 |
12 | static final RouterWeb _instance = RouterWeb._internal();
13 |
14 | static const String appName = 'Watch Together';
15 |
16 | static Widget init() {
17 | return GetMaterialApp(
18 | title: appName,
19 | initialRoute: Routes.root,
20 | getPages: PagesWeb.pages,
21 | builder: (context, child) {
22 | return FlutterSmartDialog(
23 | child: child ??
24 | const Center(
25 | child: Text('$appName Error'),
26 | ),
27 | );
28 | },
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/lib/route/routes.dart:
--------------------------------------------------------------------------------
1 | abstract class Routes {
2 | static const root = '/';
3 | static const main = '/main';
4 | }
--------------------------------------------------------------------------------
/lib/utils/client_id_util.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter/foundation.dart';
4 | import 'package:get_storage/get_storage.dart';
5 | import 'package:uuid/uuid.dart';
6 | import 'package:watch_together/mqtt/mqtt_config.dart';
7 |
8 | class ClientIdUtil {
9 | static const String _keyClientId = 'key_client_id';
10 | static String? _clientId;
11 |
12 | /// Get client id from local storage, if not exist, generate one.
13 | static String getClientId() {
14 | var temp = _clientId;
15 | if (temp != null) {
16 | return temp;
17 | }
18 | GetStorage storage = GetStorage();
19 | String? clientId = storage.read(_keyClientId);
20 | if (clientId == null) {
21 | clientId = _generateClientId();
22 | storage.write(_keyClientId, clientId);
23 | }
24 | _clientId = clientId;
25 | return clientId;
26 | }
27 |
28 | static String _getPlatformName() {
29 | return kIsWeb ? "web" : Platform.operatingSystem;
30 | }
31 |
32 | static String _getUuid() {
33 | Uuid uuid = const Uuid();
34 | return uuid.v4();
35 | }
36 |
37 | static String _generateClientId() {
38 | return "${MqttConfig.clientId}${_getPlatformName()}_${_getUuid()}";
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/lib/utils/platform_utils.dart:
--------------------------------------------------------------------------------
1 | import 'dart:io';
2 |
3 | import 'package:flutter/foundation.dart';
4 | import 'package:watch_together/mqtt/mqtt_client.dart';
5 |
6 | class PlatFormUtils {
7 | static bool isMobile() {
8 | return Platform.isAndroid || Platform.isIOS;
9 | }
10 |
11 | static bool isDesktop() {
12 | return Platform.isWindows || Platform.isMacOS || Platform.isLinux;
13 | }
14 |
15 | static bool isWeb() {
16 | return kIsWeb ? true : false;
17 | }
18 |
19 | ///由不同平台初始化赋值,不依赖具体平台的包,避免报错
20 | static XMqttClient? mqttClient;
21 | }
22 |
--------------------------------------------------------------------------------
/lib/utils/task_queue_utils.dart:
--------------------------------------------------------------------------------
1 | import 'dart:async';
2 |
3 | typedef TaskCallback = void Function(bool success, dynamic result);
4 | typedef TaskFutureFuc = Future Function();
5 |
6 | ///队列任务,先进先出,一个个执行
7 | class TaskQueueUtils {
8 | bool _isTaskRunning = false;
9 | final List _taskList = [];
10 |
11 | bool get isTaskRunning => _isTaskRunning;
12 |
13 | Future addTask(TaskFutureFuc futureFunc, {dynamic param}) {
14 | Completer completer = Completer();
15 | TaskItem taskItem = TaskItem(
16 | futureFunc,
17 | (success, result) {
18 | if (success) {
19 | completer.complete(result);
20 | } else {
21 | completer.completeError(result);
22 | }
23 | _taskList.removeAt(0);
24 | _isTaskRunning = false;
25 | //递归任务
26 | _doTask();
27 | },
28 | );
29 | _taskList.add(taskItem);
30 | _doTask();
31 | return completer.future;
32 | }
33 |
34 | Future _doTask() async {
35 | if (_isTaskRunning) return;
36 | if (_taskList.isEmpty) return;
37 |
38 | //获取先进入的任务
39 | TaskItem task = _taskList[0];
40 | _isTaskRunning = true;
41 | try {
42 | //执行任务
43 | var result = await task.futureFun();
44 | //完成任务
45 | task.callback(true, result);
46 | } catch (_) {
47 | task.callback(false, _.toString());
48 | }
49 | }
50 | }
51 |
52 | ///任务封装
53 | class TaskItem {
54 | final TaskFutureFuc futureFun;
55 | final TaskCallback callback;
56 |
57 | const TaskItem(
58 | this.futureFun,
59 | this.callback,
60 | );
61 | }
62 |
--------------------------------------------------------------------------------
/lib/widget/widget_send_danmaku.dart:
--------------------------------------------------------------------------------
1 | import '../includes.dart';
2 |
3 | typedef ValueCallBack = void Function(String value);
4 |
5 | class SendDanmakuInput extends StatelessWidget {
6 | SendDanmakuInput({super.key, this.onSend});
7 |
8 | final ValueCallBack? onSend;
9 | final TextEditingController _controller = TextEditingController();
10 |
11 | @override
12 | Widget build(BuildContext context) {
13 | return Container(
14 | padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
15 | decoration: BoxDecoration(
16 | color: Theme.of(context).cardColor,
17 | borderRadius: BorderRadius.circular(8),
18 | ),
19 | child: Row(
20 | children: [
21 | Expanded(
22 | child: TextField(
23 | controller: _controller,
24 | decoration: const InputDecoration(
25 | border: InputBorder.none,
26 | hintText: '发送弹幕',
27 | ),
28 | onSubmitted: (value) {
29 | onSend?.call(value);
30 | _controller.clear();
31 | },
32 | ),
33 | ),
34 | const SizedBox(width: 8),
35 | GestureDetector(
36 | onTap: () {
37 | onSend?.call(_controller.text);
38 | _controller.clear();
39 | FocusScope.of(context).requestFocus(FocusNode());
40 | },
41 | child: Icon(
42 | Icons.send,
43 | color: Theme.of(context).primaryColor,
44 | ),
45 | ),
46 | ],
47 | ),
48 | );
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.10)
3 | project(runner LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "watch_together")
8 | # The unique GTK application identifier for this application. See:
9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID
10 | set(APPLICATION_ID "cn.leo.watch.togther.watch_together")
11 |
12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13 | # versions of CMake.
14 | cmake_policy(SET CMP0063 NEW)
15 |
16 | # Load bundled libraries from the lib/ directory relative to the binary.
17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18 |
19 | # Root filesystem for cross-building.
20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27 | endif()
28 |
29 | # Define build configuration options.
30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
31 | set(CMAKE_BUILD_TYPE "Debug" CACHE
32 | STRING "Flutter build mode" FORCE)
33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34 | "Debug" "Profile" "Release")
35 | endif()
36 |
37 | # Compilation settings that should be applied to most targets.
38 | #
39 | # Be cautious about adding new options here, as plugins use this function by
40 | # default. In most cases, you should add new options to specific targets instead
41 | # of modifying this function.
42 | function(APPLY_STANDARD_SETTINGS TARGET)
43 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
47 | endfunction()
48 |
49 | # Flutter library and tool build rules.
50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51 | add_subdirectory(${FLUTTER_MANAGED_DIR})
52 |
53 | # System-level dependencies.
54 | find_package(PkgConfig REQUIRED)
55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
56 |
57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58 |
59 | # Define the application target. To change its name, change BINARY_NAME above,
60 | # not the value here, or `flutter run` will no longer work.
61 | #
62 | # Any new source files that you add to the application should be added here.
63 | add_executable(${BINARY_NAME}
64 | "main.cc"
65 | "my_application.cc"
66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67 | )
68 |
69 | # Apply the standard set of build settings. This can be removed for applications
70 | # that need different build settings.
71 | apply_standard_settings(${BINARY_NAME})
72 |
73 | # Add dependency libraries. Add any application-specific dependencies here.
74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76 |
77 | # Run the Flutter tool portions of the build. This must not be removed.
78 | add_dependencies(${BINARY_NAME} flutter_assemble)
79 |
80 | # Only the install-generated bundle's copy of the executable will launch
81 | # correctly, since the resources must in the right relative locations. To avoid
82 | # people trying to run the unbundled copy, put it in a subdirectory instead of
83 | # the default top-level location.
84 | set_target_properties(${BINARY_NAME}
85 | PROPERTIES
86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
87 | )
88 |
89 | # Generated plugin build rules, which manage building the plugins and adding
90 | # them to the application.
91 | include(flutter/generated_plugins.cmake)
92 |
93 |
94 | # === Installation ===
95 | # By default, "installing" just makes a relocatable bundle in the build
96 | # directory.
97 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
98 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
99 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
100 | endif()
101 |
102 | # Start with a clean build bundle directory every time.
103 | install(CODE "
104 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
105 | " COMPONENT Runtime)
106 |
107 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
108 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
109 |
110 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
111 | COMPONENT Runtime)
112 |
113 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
114 | COMPONENT Runtime)
115 |
116 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
117 | COMPONENT Runtime)
118 |
119 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
120 | install(FILES "${bundled_library}"
121 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
122 | COMPONENT Runtime)
123 | endforeach(bundled_library)
124 |
125 | # Fully re-copy the assets directory on each build to avoid having stale files
126 | # from a previous install.
127 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
128 | install(CODE "
129 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
130 | " COMPONENT Runtime)
131 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
132 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
133 |
134 | # Install the AOT library on non-Debug builds only.
135 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
136 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
137 | COMPONENT Runtime)
138 | endif()
139 |
--------------------------------------------------------------------------------
/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.10)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 |
12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
13 | # which isn't available in 3.10.
14 | function(list_prepend LIST_NAME PREFIX)
15 | set(NEW_LIST "")
16 | foreach(element ${${LIST_NAME}})
17 | list(APPEND NEW_LIST "${PREFIX}${element}")
18 | endforeach(element)
19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
20 | endfunction()
21 |
22 | # === Flutter Library ===
23 | # System-level dependencies.
24 | find_package(PkgConfig REQUIRED)
25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
28 |
29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
30 |
31 | # Published to parent scope for install step.
32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
36 |
37 | list(APPEND FLUTTER_LIBRARY_HEADERS
38 | "fl_basic_message_channel.h"
39 | "fl_binary_codec.h"
40 | "fl_binary_messenger.h"
41 | "fl_dart_project.h"
42 | "fl_engine.h"
43 | "fl_json_message_codec.h"
44 | "fl_json_method_codec.h"
45 | "fl_message_codec.h"
46 | "fl_method_call.h"
47 | "fl_method_channel.h"
48 | "fl_method_codec.h"
49 | "fl_method_response.h"
50 | "fl_plugin_registrar.h"
51 | "fl_plugin_registry.h"
52 | "fl_standard_message_codec.h"
53 | "fl_standard_method_codec.h"
54 | "fl_string_codec.h"
55 | "fl_value.h"
56 | "fl_view.h"
57 | "flutter_linux.h"
58 | )
59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
60 | add_library(flutter INTERFACE)
61 | target_include_directories(flutter INTERFACE
62 | "${EPHEMERAL_DIR}"
63 | )
64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
65 | target_link_libraries(flutter INTERFACE
66 | PkgConfig::GTK
67 | PkgConfig::GLIB
68 | PkgConfig::GIO
69 | )
70 | add_dependencies(flutter flutter_assemble)
71 |
72 | # === Flutter tool backend ===
73 | # _phony_ is a non-existent file to force this command to run every time,
74 | # since currently there's no way to get a full input/output list from the
75 | # flutter tool.
76 | add_custom_command(
77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
79 | COMMAND ${CMAKE_COMMAND} -E env
80 | ${FLUTTER_TOOL_ENVIRONMENT}
81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
83 | VERBATIM
84 | )
85 | add_custom_target(flutter_assemble DEPENDS
86 | "${FLUTTER_LIBRARY}"
87 | ${FLUTTER_LIBRARY_HEADERS}
88 | )
89 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 | #include
11 | #include
12 |
13 | void fl_register_plugins(FlPluginRegistry* registry) {
14 | g_autoptr(FlPluginRegistrar) dart_vlc_registrar =
15 | fl_plugin_registry_get_registrar_for_plugin(registry, "DartVlcPlugin");
16 | dart_vlc_plugin_register_with_registrar(dart_vlc_registrar);
17 | g_autoptr(FlPluginRegistrar) screen_retriever_registrar =
18 | fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverPlugin");
19 | screen_retriever_plugin_register_with_registrar(screen_retriever_registrar);
20 | g_autoptr(FlPluginRegistrar) window_manager_registrar =
21 | fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
22 | window_manager_plugin_register_with_registrar(window_manager_registrar);
23 | }
24 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | dart_vlc
7 | screen_retriever
8 | window_manager
9 | )
10 |
11 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
12 | )
13 |
14 | set(PLUGIN_BUNDLED_LIBRARIES)
15 |
16 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
17 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
18 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
21 | endforeach(plugin)
22 |
23 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
24 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
25 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
26 | endforeach(ffi_plugin)
27 |
--------------------------------------------------------------------------------
/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen* screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "watch_together");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | } else {
47 | gtk_window_set_title(window, "watch_together");
48 | }
49 |
50 | gtk_window_set_default_size(window, 1280, 720);
51 | gtk_widget_show(GTK_WIDGET(window));
52 |
53 | g_autoptr(FlDartProject) project = fl_dart_project_new();
54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
55 |
56 | FlView* view = fl_view_new(project);
57 | gtk_widget_show(GTK_WIDGET(view));
58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
59 |
60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
61 |
62 | gtk_widget_grab_focus(GTK_WIDGET(view));
63 | }
64 |
65 | // Implements GApplication::local_command_line.
66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
67 | MyApplication* self = MY_APPLICATION(application);
68 | // Strip out the first argument as it is the binary name.
69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
70 |
71 | g_autoptr(GError) error = nullptr;
72 | if (!g_application_register(application, nullptr, &error)) {
73 | g_warning("Failed to register: %s", error->message);
74 | *exit_status = 1;
75 | return TRUE;
76 | }
77 |
78 | g_application_activate(application);
79 | *exit_status = 0;
80 |
81 | return TRUE;
82 | }
83 |
84 | // Implements GObject::dispose.
85 | static void my_application_dispose(GObject* object) {
86 | MyApplication* self = MY_APPLICATION(object);
87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
89 | }
90 |
91 | static void my_application_class_init(MyApplicationClass* klass) {
92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95 | }
96 |
97 | static void my_application_init(MyApplication* self) {}
98 |
99 | MyApplication* my_application_new() {
100 | return MY_APPLICATION(g_object_new(my_application_get_type(),
101 | "application-id", APPLICATION_ID,
102 | "flags", G_APPLICATION_NON_UNIQUE,
103 | nullptr));
104 | }
105 |
--------------------------------------------------------------------------------
/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/dgph
7 | **/xcuserdata/
8 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 | import path_provider_foundation
9 | import screen_retriever
10 | import wakelock_macos
11 | import window_manager
12 |
13 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
14 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
15 | ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
16 | WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
17 | WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
18 | }
19 |
--------------------------------------------------------------------------------
/macos/Podfile:
--------------------------------------------------------------------------------
1 | platform :osx, '10.11'
2 |
3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
5 |
6 | project 'Runner', {
7 | 'Debug' => :debug,
8 | 'Profile' => :release,
9 | 'Release' => :release,
10 | }
11 |
12 | def flutter_root
13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
14 | unless File.exist?(generated_xcode_build_settings_path)
15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
16 | end
17 |
18 | File.foreach(generated_xcode_build_settings_path) do |line|
19 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
20 | return matches[1].strip if matches
21 | end
22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
23 | end
24 |
25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
26 |
27 | flutter_macos_podfile_setup
28 |
29 | target 'Runner' do
30 | use_frameworks!
31 | use_modular_headers!
32 |
33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
34 | end
35 |
36 | post_install do |installer|
37 | installer.pods_project.targets.each do |target|
38 | flutter_additional_macos_build_settings(target)
39 | end
40 | end
41 |
--------------------------------------------------------------------------------
/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
52 |
54 |
60 |
61 |
62 |
63 |
69 |
71 |
77 |
78 |
79 |
80 |
82 |
83 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @NSApplicationMain
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info": {
3 | "version": 1,
4 | "author": "xcode"
5 | },
6 | "images": [
7 | {
8 | "size": "16x16",
9 | "idiom": "mac",
10 | "filename": "app_icon_16.png",
11 | "scale": "1x"
12 | },
13 | {
14 | "size": "16x16",
15 | "idiom": "mac",
16 | "filename": "app_icon_32.png",
17 | "scale": "2x"
18 | },
19 | {
20 | "size": "32x32",
21 | "idiom": "mac",
22 | "filename": "app_icon_32.png",
23 | "scale": "1x"
24 | },
25 | {
26 | "size": "32x32",
27 | "idiom": "mac",
28 | "filename": "app_icon_64.png",
29 | "scale": "2x"
30 | },
31 | {
32 | "size": "128x128",
33 | "idiom": "mac",
34 | "filename": "app_icon_128.png",
35 | "scale": "1x"
36 | },
37 | {
38 | "size": "128x128",
39 | "idiom": "mac",
40 | "filename": "app_icon_256.png",
41 | "scale": "2x"
42 | },
43 | {
44 | "size": "256x256",
45 | "idiom": "mac",
46 | "filename": "app_icon_256.png",
47 | "scale": "1x"
48 | },
49 | {
50 | "size": "256x256",
51 | "idiom": "mac",
52 | "filename": "app_icon_512.png",
53 | "scale": "2x"
54 | },
55 | {
56 | "size": "512x512",
57 | "idiom": "mac",
58 | "filename": "app_icon_512.png",
59 | "scale": "1x"
60 | },
61 | {
62 | "size": "512x512",
63 | "idiom": "mac",
64 | "filename": "app_icon_1024.png",
65 | "scale": "2x"
66 | }
67 | ]
68 | }
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/macos/Runner/Configs/AppInfo.xcconfig:
--------------------------------------------------------------------------------
1 | // Application-level settings for the Runner target.
2 | //
3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
4 | // future. If not, the values below would default to using the project name when this becomes a
5 | // 'flutter create' template.
6 |
7 | // The application's name. By default this is also the title of the Flutter window.
8 | PRODUCT_NAME = watch_together
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = cn.leo.watch.togther.watchTogether
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2022 cn.leo.watch.togther. All rights reserved.
15 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Warnings.xcconfig:
--------------------------------------------------------------------------------
1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
2 | GCC_WARN_UNDECLARED_SELECTOR = YES
3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
6 | CLANG_WARN_PRAGMA_PACK = YES
7 | CLANG_WARN_STRICT_PROTOTYPES = YES
8 | CLANG_WARN_COMMA = YES
9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES
10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
12 | GCC_WARN_SHADOW = YES
13 | CLANG_WARN_UNREACHABLE_CODE = YES
14 |
--------------------------------------------------------------------------------
/macos/Runner/DebugProfile.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.cs.allow-jit
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/macos/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | $(PRODUCT_COPYRIGHT)
27 | NSMainNibFile
28 | MainMenu
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/macos/Runner/MainFlutterWindow.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | class MainFlutterWindow: NSWindow {
5 | override func awakeFromNib() {
6 | let flutterViewController = FlutterViewController.init()
7 | let windowFrame = self.frame
8 | self.contentViewController = flutterViewController
9 | self.setFrame(windowFrame, display: true)
10 |
11 | RegisterGeneratedPlugins(registry: flutterViewController)
12 |
13 | super.awakeFromNib()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: watch_together
2 | description: A project can watch video together on different device.
3 |
4 | # The following line prevents the package from being accidentally published to
5 | # pub.dev using `flutter pub publish`. This is preferred for private packages.
6 | publish_to: 'none' # Remove this line if you wish to publish to pub.dev
7 |
8 | # The following defines the version and build number for your application.
9 | # A version number is three numbers separated by dots, like 1.2.43
10 | # followed by an optional build number separated by a +.
11 | # Both the version and the builder number may be overridden in flutter
12 | # build by specifying --build-name and --build-number, respectively.
13 | # In Android, build-name is used as versionName while build-number used as versionCode.
14 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
15 | # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 | # Read more about iOS versioning at
17 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 | version: 2.0.1+201
19 |
20 | environment:
21 | sdk: ">=2.17.3 <3.0.0"
22 |
23 | # Dependencies specify other packages that your package needs in order to work.
24 | # To automatically upgrade your package dependencies to the latest versions
25 | # consider running `flutter pub upgrade --major-versions`. Alternatively,
26 | # dependencies can be manually updated by changing the version numbers below to
27 | # the latest version available on pub.dev. To see which dependencies have newer
28 | # versions available, run `flutter pub outdated`.
29 | dependencies:
30 | flutter:
31 | sdk: flutter
32 | # get-x
33 | get: ^4.6.5
34 | get_storage: ^2.1.1
35 | # mqtt
36 | mqtt_client: ^10.0.0
37 | # logger
38 | logger: ^2.0.1
39 | # provider: ^6.0.2
40 | # 视频播放器
41 | appinio_video_player: ^1.2.2 # web端
42 | # cached_video_player: ^2.0.4
43 | # video_player: ^2.7.2
44 | fijkplayer: ^0.11.0 # 移动端
45 | dart_vlc: ^0.3.0 # 桌面端
46 | xml: ^6.1.0
47 |
48 | # 弹幕库
49 | flutter_barrage: ^0.5.5
50 | # 网络请求库
51 | dio: ^4.0.6
52 | # 日期格式化库
53 | intl: ^0.18.0
54 | # json转换库
55 | convert: ^3.1.1
56 | # 屏幕保持常亮
57 | wakelock: ^0.6.2
58 | window_manager: ^0.2.3
59 | flutter_smart_dialog: ^4.9.4
60 | # UUID
61 | uuid: ^3.0.7
62 |
63 | # The following adds the Cupertino Icons font to your application.
64 | # Use with the CupertinoIcons class for iOS style icons.
65 | cupertino_icons: ^1.0.2
66 | async: ^2.11.0
67 |
68 | dev_dependencies:
69 | flutter_launcher_icons: ^0.13.1
70 | flutter_test:
71 | sdk: flutter
72 |
73 | # The "flutter_lints" package below contains a set of recommended lints to
74 | # encourage good coding practices. The lint set provided by the package is
75 | # activated in the `analysis_options.yaml` file located at the root of your
76 | # package. See that file for information about deactivating specific lint
77 | # rules and activating additional ones.
78 | flutter_lints: ^2.0.0
79 |
80 | # For information on the generic Dart part of this file, see the
81 | # following page: https://dart.dev/tools/pub/pubspec
82 |
83 | # The following section is specific to Flutter packages.
84 | flutter:
85 |
86 | # The following line ensures that the Material Icons font is
87 | # included with your application, so that you can use the icons in
88 | # the material Icons class.
89 | uses-material-design: true
90 |
91 | # To add assets to your application, add an assets section, like this:
92 | # assets:
93 | # - images/a_dot_burr.jpeg
94 | # - images/a_dot_ham.jpeg
95 |
96 | # An image asset can refer to one or more resolution-specific "variants", see
97 | # https://flutter.dev/assets-and-images/#resolution-aware
98 |
99 | # For details regarding adding assets from package dependencies, see
100 | # https://flutter.dev/assets-and-images/#from-packages
101 |
102 | # To add custom fonts to your application, add a fonts section here,
103 | # in this "flutter" section. Each entry in this list should have a
104 | # "family" key with the font family name, and a "fonts" key with a
105 | # list giving the asset and other descriptors for the font. For
106 | # example:
107 | # fonts:
108 | # - family: Schyler
109 | # fonts:
110 | # - asset: fonts/Schyler-Regular.ttf
111 | # - asset: fonts/Schyler-Italic.ttf
112 | # style: italic
113 | # - family: Trajan Pro
114 | # fonts:
115 | # - asset: fonts/TrajanPro.ttf
116 | # - asset: fonts/TrajanPro_Bold.ttf
117 | # weight: 700
118 | #
119 | # For details regarding fonts from package dependencies,
120 | # see https://flutter.dev/custom-fonts/#from-packages
121 | assets:
122 | - assets/
--------------------------------------------------------------------------------
/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility in the flutter_test package. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'dart:async';
9 | import 'dart:convert';
10 | import 'dart:io';
11 |
12 | import 'package:flutter_test/flutter_test.dart';
13 | import 'package:intl/intl.dart';
14 | import 'package:watch_together/dlna/dlna_flutter.dart';
15 |
16 | void main() {
17 | test("localIp", () async {
18 | var activeIpList = List.empty(growable: true);
19 | var list = await NetworkInterface.list(type: InternetAddressType.IPv4);
20 | for (var element in list) {
21 | for (var address in element.addresses) {
22 | activeIpList.add(address.address);
23 | }
24 | }
25 | print(activeIpList);
26 | });
27 |
28 | test("dlna test", () async {
29 | final searcher = Search();
30 | final m = await searcher.start();
31 | Timer.periodic(const Duration(seconds: 3), (timer) {
32 | m.deviceList.forEach((key, value) async {
33 | print(key);
34 | if (value.info.friendlyName.contains('Wireless')) return;
35 | print(value.info.friendlyName);
36 | // final text = await value.position();
37 | // final r = await value.seekByCurrent(text, 10);
38 | // print(r);
39 | });
40 | });
41 |
42 | // close the server,the closed server can be start by call searcher.start()
43 | Timer(const Duration(seconds: 30), () {
44 | searcher.stop();
45 | print('server closed');
46 | });
47 | });
48 |
49 | test("dateFormat", () {
50 | var date = DateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", 'en_US')
51 | .format(DateTime.now());
52 | print(date);
53 | var time = const Duration(seconds: 5000).toString();
54 | var t = time.split(".")[0];
55 | print(t);
56 | });
57 |
58 | test("json", () {
59 | var data = [ 100, 200];
60 | var jsonStr = jsonEncode(data);
61 | print(jsonStr);
62 | var list = jsonDecode(jsonStr);
63 | int d1 = list[0];
64 | int d2 = list[1];
65 | print(d1);
66 | });
67 |
68 | test("http", () async {
69 | var host = InternetAddress.loopbackIPv4.host;
70 | var port = 8888;
71 | var url = "http://127.0.0.1:$port";
72 | var httpServer = await HttpServer.bind(host, port);
73 | Timer.periodic(const Duration(seconds: 1), (timer) async {
74 | print("post");
75 | // HttpClient().post(url, port,"path");
76 | var client = HttpClient();
77 | var request = await client.get(url, port, "/path");
78 | request.write("hello");
79 | client.close();
80 | });
81 | await httpServer.forEach((request) {
82 | var path = request.uri.path;
83 | print(path);
84 | });
85 | });
86 | }
87 |
--------------------------------------------------------------------------------
/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/favicon.png
--------------------------------------------------------------------------------
/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | watch_together
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/web/manifest.json:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/web/manifest.json
--------------------------------------------------------------------------------
/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.14)
3 | project(watch_together LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "watch_together")
8 |
9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10 | # versions of CMake.
11 | cmake_policy(SET CMP0063 NEW)
12 |
13 | # Define build configuration option.
14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15 | if(IS_MULTICONFIG)
16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
17 | CACHE STRING "" FORCE)
18 | else()
19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20 | set(CMAKE_BUILD_TYPE "Debug" CACHE
21 | STRING "Flutter build mode" FORCE)
22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
23 | "Debug" "Profile" "Release")
24 | endif()
25 | endif()
26 | # Define settings for the Profile build mode.
27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
31 |
32 | # Use Unicode for all projects.
33 | add_definitions(-DUNICODE -D_UNICODE)
34 |
35 | # Compilation settings that should be applied to most targets.
36 | #
37 | # Be cautious about adding new options here, as plugins use this function by
38 | # default. In most cases, you should add new options to specific targets instead
39 | # of modifying this function.
40 | function(APPLY_STANDARD_SETTINGS TARGET)
41 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
43 | target_compile_options(${TARGET} PRIVATE /EHsc)
44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
46 | endfunction()
47 |
48 | # Flutter library and tool build rules.
49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
50 | add_subdirectory(${FLUTTER_MANAGED_DIR})
51 |
52 | # Application build; see runner/CMakeLists.txt.
53 | add_subdirectory("runner")
54 |
55 | # Generated plugin build rules, which manage building the plugins and adding
56 | # them to the application.
57 | include(flutter/generated_plugins.cmake)
58 |
59 |
60 | # === Installation ===
61 | # Support files are copied into place next to the executable, so that it can
62 | # run in place. This is done instead of making a separate bundle (as on Linux)
63 | # so that building and running from within Visual Studio will work.
64 | set(BUILD_BUNDLE_DIR "$")
65 | # Make the "install" step default, as it's required to run.
66 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
67 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
68 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
69 | endif()
70 |
71 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
72 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
73 |
74 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
75 | COMPONENT Runtime)
76 |
77 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
78 | COMPONENT Runtime)
79 |
80 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
81 | COMPONENT Runtime)
82 |
83 | if(PLUGIN_BUNDLED_LIBRARIES)
84 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
85 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
86 | COMPONENT Runtime)
87 | endif()
88 |
89 | # Fully re-copy the assets directory on each build to avoid having stale files
90 | # from a previous install.
91 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
92 | install(CODE "
93 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
94 | " COMPONENT Runtime)
95 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
96 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
97 |
98 | # Install the AOT library on non-Debug builds only.
99 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
100 | CONFIGURATIONS Profile;Release
101 | COMPONENT Runtime)
102 |
--------------------------------------------------------------------------------
/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.14)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
12 |
13 | # === Flutter Library ===
14 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
15 |
16 | # Published to parent scope for install step.
17 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
18 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
19 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
20 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
21 |
22 | list(APPEND FLUTTER_LIBRARY_HEADERS
23 | "flutter_export.h"
24 | "flutter_windows.h"
25 | "flutter_messenger.h"
26 | "flutter_plugin_registrar.h"
27 | "flutter_texture_registrar.h"
28 | )
29 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
30 | add_library(flutter INTERFACE)
31 | target_include_directories(flutter INTERFACE
32 | "${EPHEMERAL_DIR}"
33 | )
34 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
35 | add_dependencies(flutter flutter_assemble)
36 |
37 | # === Wrapper ===
38 | list(APPEND CPP_WRAPPER_SOURCES_CORE
39 | "core_implementations.cc"
40 | "standard_codec.cc"
41 | )
42 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
43 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
44 | "plugin_registrar.cc"
45 | )
46 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
47 | list(APPEND CPP_WRAPPER_SOURCES_APP
48 | "flutter_engine.cc"
49 | "flutter_view_controller.cc"
50 | )
51 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
52 |
53 | # Wrapper sources needed for a plugin.
54 | add_library(flutter_wrapper_plugin STATIC
55 | ${CPP_WRAPPER_SOURCES_CORE}
56 | ${CPP_WRAPPER_SOURCES_PLUGIN}
57 | )
58 | apply_standard_settings(flutter_wrapper_plugin)
59 | set_target_properties(flutter_wrapper_plugin PROPERTIES
60 | POSITION_INDEPENDENT_CODE ON)
61 | set_target_properties(flutter_wrapper_plugin PROPERTIES
62 | CXX_VISIBILITY_PRESET hidden)
63 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
64 | target_include_directories(flutter_wrapper_plugin PUBLIC
65 | "${WRAPPER_ROOT}/include"
66 | )
67 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
68 |
69 | # Wrapper sources needed for the runner.
70 | add_library(flutter_wrapper_app STATIC
71 | ${CPP_WRAPPER_SOURCES_CORE}
72 | ${CPP_WRAPPER_SOURCES_APP}
73 | )
74 | apply_standard_settings(flutter_wrapper_app)
75 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
76 | target_include_directories(flutter_wrapper_app PUBLIC
77 | "${WRAPPER_ROOT}/include"
78 | )
79 | add_dependencies(flutter_wrapper_app flutter_assemble)
80 |
81 | # === Flutter tool backend ===
82 | # _phony_ is a non-existent file to force this command to run every time,
83 | # since currently there's no way to get a full input/output list from the
84 | # flutter tool.
85 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
86 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
87 | add_custom_command(
88 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
89 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
90 | ${CPP_WRAPPER_SOURCES_APP}
91 | ${PHONY_OUTPUT}
92 | COMMAND ${CMAKE_COMMAND} -E env
93 | ${FLUTTER_TOOL_ENVIRONMENT}
94 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
95 | windows-x64 $
96 | VERBATIM
97 | )
98 | add_custom_target(flutter_assemble DEPENDS
99 | "${FLUTTER_LIBRARY}"
100 | ${FLUTTER_LIBRARY_HEADERS}
101 | ${CPP_WRAPPER_SOURCES_CORE}
102 | ${CPP_WRAPPER_SOURCES_PLUGIN}
103 | ${CPP_WRAPPER_SOURCES_APP}
104 | )
105 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | void RegisterPlugins(flutter::PluginRegistry* registry) {
15 | DartVlcPluginRegisterWithRegistrar(
16 | registry->GetRegistrarForPlugin("DartVlcPlugin"));
17 | FlutterNativeViewPluginRegisterWithRegistrar(
18 | registry->GetRegistrarForPlugin("FlutterNativeViewPlugin"));
19 | ScreenRetrieverPluginRegisterWithRegistrar(
20 | registry->GetRegistrarForPlugin("ScreenRetrieverPlugin"));
21 | WindowManagerPluginRegisterWithRegistrar(
22 | registry->GetRegistrarForPlugin("WindowManagerPlugin"));
23 | }
24 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | dart_vlc
7 | flutter_native_view
8 | screen_retriever
9 | window_manager
10 | )
11 |
12 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
13 | )
14 |
15 | set(PLUGIN_BUNDLED_LIBRARIES)
16 |
17 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
18 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
19 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
20 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
21 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
22 | endforeach(plugin)
23 |
24 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
25 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
26 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
27 | endforeach(ffi_plugin)
28 |
--------------------------------------------------------------------------------
/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | project(runner LANGUAGES CXX)
3 |
4 | # Define the application target. To change its name, change BINARY_NAME in the
5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6 | # work.
7 | #
8 | # Any new source files that you add to the application should be added here.
9 | add_executable(${BINARY_NAME} WIN32
10 | "flutter_window.cpp"
11 | "main.cpp"
12 | "utils.cpp"
13 | "win32_window.cpp"
14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
15 | "Runner.rc"
16 | "runner.exe.manifest"
17 | )
18 |
19 | # Apply the standard set of build settings. This can be removed for applications
20 | # that need different build settings.
21 | apply_standard_settings(${BINARY_NAME})
22 |
23 | # Add preprocessor definitions for the build version.
24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
29 |
30 | # Disable Windows macros that collide with C++ standard library functions.
31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
32 |
33 | # Add dependency libraries and include directories. Add any application-specific
34 | # dependencies here.
35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
37 |
38 | # Run the Flutter tool portions of the build. This must not be removed.
39 | add_dependencies(${BINARY_NAME} flutter_assemble)
40 |
--------------------------------------------------------------------------------
/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0,0
67 | #endif
68 |
69 | #if defined(FLUTTER_VERSION)
70 | #define VERSION_AS_STRING FLUTTER_VERSION
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "cn.leo.watch.togther" "\0"
93 | VALUE "FileDescription", "watch_together" "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "watch_together" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2022 cn.leo.watch.togther. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "watch_together.exe" "\0"
98 | VALUE "ProductName", "watch_together" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8 | : project_(project) {}
9 |
10 | FlutterWindow::~FlutterWindow() {}
11 |
12 | bool FlutterWindow::OnCreate() {
13 | if (!Win32Window::OnCreate()) {
14 | return false;
15 | }
16 |
17 | RECT frame = GetClientArea();
18 |
19 | // The size here must match the window dimensions to avoid unnecessary surface
20 | // creation / destruction in the startup path.
21 | flutter_controller_ = std::make_unique(
22 | frame.right - frame.left, frame.bottom - frame.top, project_);
23 | // Ensure that basic setup of the controller was successful.
24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25 | return false;
26 | }
27 | RegisterPlugins(flutter_controller_->engine());
28 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
29 | return true;
30 | }
31 |
32 | void FlutterWindow::OnDestroy() {
33 | if (flutter_controller_) {
34 | flutter_controller_ = nullptr;
35 | }
36 |
37 | Win32Window::OnDestroy();
38 | }
39 |
40 | LRESULT
41 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
42 | WPARAM const wparam,
43 | LPARAM const lparam) noexcept {
44 | // Give Flutter, including plugins, an opportunity to handle window messages.
45 | if (flutter_controller_) {
46 | std::optional result =
47 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
48 | lparam);
49 | if (result) {
50 | return *result;
51 | }
52 | }
53 |
54 | switch (message) {
55 | case WM_FONTCHANGE:
56 | flutter_controller_->engine()->ReloadSystemFonts();
57 | break;
58 | }
59 |
60 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
61 | }
62 |
--------------------------------------------------------------------------------
/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "win32_window.h"
10 |
11 | // A window that does nothing but host a Flutter view.
12 | class FlutterWindow : public Win32Window {
13 | public:
14 | // Creates a new FlutterWindow hosting a Flutter view running |project|.
15 | explicit FlutterWindow(const flutter::DartProject& project);
16 | virtual ~FlutterWindow();
17 |
18 | protected:
19 | // Win32Window:
20 | bool OnCreate() override;
21 | void OnDestroy() override;
22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23 | LPARAM const lparam) noexcept override;
24 |
25 | private:
26 | // The project to run.
27 | flutter::DartProject project_;
28 |
29 | // The Flutter instance hosted by this window.
30 | std::unique_ptr flutter_controller_;
31 | };
32 |
33 | #endif // RUNNER_FLUTTER_WINDOW_H_
34 |
--------------------------------------------------------------------------------
/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_native_view/flutter_native_view_plugin.h"
6 | #include "flutter_window.h"
7 | #include "utils.h"
8 |
9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
10 | _In_ wchar_t *command_line, _In_ int show_command) {
11 | // Attach to console when present (e.g., 'flutter run') or create a
12 | // new console when running with a debugger.
13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
14 | CreateAndAttachConsole();
15 | }
16 |
17 | // Initialize COM, so that it is available for use in the library and/or
18 | // plugins.
19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
20 |
21 | flutter::DartProject project(L"data");
22 |
23 | std::vector command_line_arguments =
24 | GetCommandLineArguments();
25 |
26 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
27 |
28 | FlutterWindow window(project);
29 | Win32Window::Point origin(10, 10);
30 | Win32Window::Size size(800, 600);
31 | if (!window.CreateAndShow(L"watch_together", origin, size)) {
32 | return EXIT_FAILURE;
33 | }
34 | window.SetQuitOnClose(true);
35 |
36 | flutternativeview::NativeViewContainer::GetInstance()->Create();
37 |
38 | ::MSG msg;
39 | while (::GetMessage(&msg, nullptr, 0, 0)) {
40 | ::TranslateMessage(&msg);
41 | ::DispatchMessage(&msg);
42 | }
43 |
44 | ::CoUninitialize();
45 | return EXIT_SUCCESS;
46 | }
47 |
--------------------------------------------------------------------------------
/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jarryleo/watch_together/2d5fd1e8f527b1f05a3af0f4eff7c141d0681f6c/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr);
51 | std::string utf8_string;
52 | if (target_length == 0 || target_length > utf8_string.max_size()) {
53 | return utf8_string;
54 | }
55 | utf8_string.resize(target_length);
56 | int converted_length = ::WideCharToMultiByte(
57 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
58 | -1, utf8_string.data(),
59 | target_length, nullptr, nullptr);
60 | if (converted_length == 0) {
61 | return std::string();
62 | }
63 | return utf8_string;
64 | }
65 |
--------------------------------------------------------------------------------
/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/windows/runner/win32_window.cpp:
--------------------------------------------------------------------------------
1 | #include "win32_window.h"
2 |
3 | #include
4 |
5 | #include "resource.h"
6 |
7 | namespace {
8 |
9 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
10 |
11 | // The number of Win32Window objects that currently exist.
12 | static int g_active_window_count = 0;
13 |
14 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
15 |
16 | // Scale helper to convert logical scaler values to physical using passed in
17 | // scale factor
18 | int Scale(int source, double scale_factor) {
19 | return static_cast(source * scale_factor);
20 | }
21 |
22 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
23 | // This API is only needed for PerMonitor V1 awareness mode.
24 | void EnableFullDpiSupportIfAvailable(HWND hwnd) {
25 | HMODULE user32_module = LoadLibraryA("User32.dll");
26 | if (!user32_module) {
27 | return;
28 | }
29 | auto enable_non_client_dpi_scaling =
30 | reinterpret_cast(
31 | GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
32 | if (enable_non_client_dpi_scaling != nullptr) {
33 | enable_non_client_dpi_scaling(hwnd);
34 | FreeLibrary(user32_module);
35 | }
36 | }
37 |
38 | } // namespace
39 |
40 | // Manages the Win32Window's window class registration.
41 | class WindowClassRegistrar {
42 | public:
43 | ~WindowClassRegistrar() = default;
44 |
45 | // Returns the singleton registar instance.
46 | static WindowClassRegistrar* GetInstance() {
47 | if (!instance_) {
48 | instance_ = new WindowClassRegistrar();
49 | }
50 | return instance_;
51 | }
52 |
53 | // Returns the name of the window class, registering the class if it hasn't
54 | // previously been registered.
55 | const wchar_t* GetWindowClass();
56 |
57 | // Unregisters the window class. Should only be called if there are no
58 | // instances of the window.
59 | void UnregisterWindowClass();
60 |
61 | private:
62 | WindowClassRegistrar() = default;
63 |
64 | static WindowClassRegistrar* instance_;
65 |
66 | bool class_registered_ = false;
67 | };
68 |
69 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
70 |
71 | const wchar_t* WindowClassRegistrar::GetWindowClass() {
72 | if (!class_registered_) {
73 | WNDCLASS window_class{};
74 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
75 | window_class.lpszClassName = kWindowClassName;
76 | window_class.style = CS_HREDRAW | CS_VREDRAW;
77 | window_class.cbClsExtra = 0;
78 | window_class.cbWndExtra = 0;
79 | window_class.hInstance = GetModuleHandle(nullptr);
80 | window_class.hIcon =
81 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
82 | window_class.hbrBackground = 0;
83 | window_class.lpszMenuName = nullptr;
84 | window_class.lpfnWndProc = Win32Window::WndProc;
85 | RegisterClass(&window_class);
86 | class_registered_ = true;
87 | }
88 | return kWindowClassName;
89 | }
90 |
91 | void WindowClassRegistrar::UnregisterWindowClass() {
92 | UnregisterClass(kWindowClassName, nullptr);
93 | class_registered_ = false;
94 | }
95 |
96 | Win32Window::Win32Window() {
97 | ++g_active_window_count;
98 | }
99 |
100 | Win32Window::~Win32Window() {
101 | --g_active_window_count;
102 | Destroy();
103 | }
104 |
105 | bool Win32Window::CreateAndShow(const std::wstring& title,
106 | const Point& origin,
107 | const Size& size) {
108 | Destroy();
109 |
110 | const wchar_t* window_class =
111 | WindowClassRegistrar::GetInstance()->GetWindowClass();
112 |
113 | const POINT target_point = {static_cast(origin.x),
114 | static_cast(origin.y)};
115 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
116 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
117 | double scale_factor = dpi / 96.0;
118 |
119 | UINT scrWidth = GetSystemMetrics(SM_CXFULLSCREEN);//屏幕宽度
120 | UINT scrHeight = GetSystemMetrics(SM_CYFULLSCREEN);//屏幕高度
121 | UINT windowWidth = Scale(size.width, scale_factor);//缩放后的窗口宽度
122 | UINT windowHeight = Scale(size.height, scale_factor);//缩放后的窗口高度
123 | UINT windowOriginX = (scrWidth - windowWidth) / 2;//窗口原点X坐标
124 | UINT windowOriginY = (scrHeight - windowHeight) / 2;//窗口原点y坐标
125 | HWND window = CreateWindow(
126 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,
127 | windowOriginX,windowOriginY,windowWidth,windowHeight,
128 | nullptr, nullptr, GetModuleHandle(nullptr), this);
129 |
130 |
131 | if (!window) {
132 | return false;
133 | }
134 |
135 | return OnCreate();
136 | }
137 |
138 | // static
139 | LRESULT CALLBACK Win32Window::WndProc(HWND const window,
140 | UINT const message,
141 | WPARAM const wparam,
142 | LPARAM const lparam) noexcept {
143 | if (message == WM_NCCREATE) {
144 | auto window_struct = reinterpret_cast(lparam);
145 | SetWindowLongPtr(window, GWLP_USERDATA,
146 | reinterpret_cast(window_struct->lpCreateParams));
147 |
148 | auto that = static_cast(window_struct->lpCreateParams);
149 | EnableFullDpiSupportIfAvailable(window);
150 | that->window_handle_ = window;
151 | } else if (Win32Window* that = GetThisFromHandle(window)) {
152 | return that->MessageHandler(window, message, wparam, lparam);
153 | }
154 |
155 | return DefWindowProc(window, message, wparam, lparam);
156 | }
157 |
158 | LRESULT
159 | Win32Window::MessageHandler(HWND hwnd,
160 | UINT const message,
161 | WPARAM const wparam,
162 | LPARAM const lparam) noexcept {
163 | switch (message) {
164 | case WM_DESTROY:
165 | window_handle_ = nullptr;
166 | Destroy();
167 | if (quit_on_close_) {
168 | PostQuitMessage(0);
169 | }
170 | return 0;
171 |
172 | case WM_DPICHANGED: {
173 | auto newRectSize = reinterpret_cast(lparam);
174 | LONG newWidth = newRectSize->right - newRectSize->left;
175 | LONG newHeight = newRectSize->bottom - newRectSize->top;
176 |
177 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
178 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
179 |
180 | return 0;
181 | }
182 | case WM_SIZE: {
183 | RECT rect = GetClientArea();
184 | if (child_content_ != nullptr) {
185 | // Size and position the child window.
186 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
187 | rect.bottom - rect.top, TRUE);
188 | }
189 | return 0;
190 | }
191 |
192 | case WM_ACTIVATE:
193 | if (child_content_ != nullptr) {
194 | SetFocus(child_content_);
195 | }
196 | return 0;
197 | }
198 |
199 | return DefWindowProc(window_handle_, message, wparam, lparam);
200 | }
201 |
202 | void Win32Window::Destroy() {
203 | OnDestroy();
204 |
205 | if (window_handle_) {
206 | DestroyWindow(window_handle_);
207 | window_handle_ = nullptr;
208 | }
209 | if (g_active_window_count == 0) {
210 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
211 | }
212 | }
213 |
214 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
215 | return reinterpret_cast(
216 | GetWindowLongPtr(window, GWLP_USERDATA));
217 | }
218 |
219 | void Win32Window::SetChildContent(HWND content) {
220 | child_content_ = content;
221 | SetParent(content, window_handle_);
222 | RECT frame = GetClientArea();
223 |
224 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
225 | frame.bottom - frame.top, true);
226 |
227 | SetFocus(child_content_);
228 | }
229 |
230 | RECT Win32Window::GetClientArea() {
231 | RECT frame;
232 | GetClientRect(window_handle_, &frame);
233 | return frame;
234 | }
235 |
236 | HWND Win32Window::GetHandle() {
237 | return window_handle_;
238 | }
239 |
240 | void Win32Window::SetQuitOnClose(bool quit_on_close) {
241 | quit_on_close_ = quit_on_close;
242 | }
243 |
244 | bool Win32Window::OnCreate() {
245 | // No-op; provided for subclasses.
246 | return true;
247 | }
248 |
249 | void Win32Window::OnDestroy() {
250 | // No-op; provided for subclasses.
251 | }
252 |
--------------------------------------------------------------------------------
/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates and shows a win32 window with |title| and position and size using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size to will treat the width height passed in to this function
35 | // as logical pixels and scale to appropriate for the default monitor. Returns
36 | // true if the window was created successfully.
37 | bool CreateAndShow(const std::wstring& title,
38 | const Point& origin,
39 | const Size& size);
40 |
41 | // Release OS resources associated with window.
42 | void Destroy();
43 |
44 | // Inserts |content| into the window tree.
45 | void SetChildContent(HWND content);
46 |
47 | // Returns the backing Window handle to enable clients to set icon and other
48 | // window properties. Returns nullptr if the window has been destroyed.
49 | HWND GetHandle();
50 |
51 | // If true, closing this window will quit the application.
52 | void SetQuitOnClose(bool quit_on_close);
53 |
54 | // Return a RECT representing the bounds of the current client area.
55 | RECT GetClientArea();
56 |
57 | protected:
58 | // Processes and route salient window messages for mouse handling,
59 | // size change and DPI. Delegates handling of these to member overloads that
60 | // inheriting classes can handle.
61 | virtual LRESULT MessageHandler(HWND window,
62 | UINT const message,
63 | WPARAM const wparam,
64 | LPARAM const lparam) noexcept;
65 |
66 | // Called when CreateAndShow is called, allowing subclass window-related
67 | // setup. Subclasses should return false if setup fails.
68 | virtual bool OnCreate();
69 |
70 | // Called when Destroy is called.
71 | virtual void OnDestroy();
72 |
73 | private:
74 | friend class WindowClassRegistrar;
75 |
76 | // OS callback called by message pump. Handles the WM_NCCREATE message which
77 | // is passed when the non-client area is being created and enables automatic
78 | // non-client DPI scaling so that the non-client area automatically
79 | // responsponds to changes in DPI. All other messages are handled by
80 | // MessageHandler.
81 | static LRESULT CALLBACK WndProc(HWND const window,
82 | UINT const message,
83 | WPARAM const wparam,
84 | LPARAM const lparam) noexcept;
85 |
86 | // Retrieves a class instance pointer for |window|
87 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
88 |
89 | bool quit_on_close_ = false;
90 |
91 | // window handle for top level window.
92 | HWND window_handle_ = nullptr;
93 |
94 | // window handle for hosted content.
95 | HWND child_content_ = nullptr;
96 | };
97 |
98 | #endif // RUNNER_WIN32_WINDOW_H_
99 |
--------------------------------------------------------------------------------