From 5f06ff6bc9de50441ec0df8da1049bc235bb5ea9 Mon Sep 17 00:00:00 2001 From: Nicolas Pomepuy Date: Tue, 8 Nov 2022 09:26:01 +0100 Subject: [PATCH] Move the webserver in its own module --- application/app/build.gradle | 2 + .../java/org/videolan/resources/Constants.kt | 1 + .../org/videolan/resources/util/Extensions.kt | 5 ++ application/vlc-android/AndroidManifest.xml | 9 ---- .../src/org/videolan/vlc/gui/MainActivity.kt | 21 +++----- .../src/org/videolan/vlc/util/FileUtils.kt | 2 +- application/webserver/.gitignore | 1 + application/webserver/build.gradle | 48 +++++++++++++++++++ application/webserver/consumer-rules.pro | 0 application/webserver/proguard-rules.pro | 21 ++++++++ .../vlc/webserver/ExampleInstrumentedTest.kt | 48 +++++++++++++++++++ .../webserver/src/main/AndroidManifest.xml | 39 +++++++++++++++ .../vlc/webserver}/NetworkSharingServer.kt | 16 +++---- .../vlc/webserver}/WebServerService.kt | 3 +- .../videolan/vlc/webserver/ExampleUnitTest.kt | 41 ++++++++++++++++ .../network-sharing-server/webpack.config.js | 2 +- settings.gradle | 2 +- 17 files changed, 225 insertions(+), 36 deletions(-) create mode 100644 application/webserver/.gitignore create mode 100644 application/webserver/build.gradle create mode 100644 application/webserver/consumer-rules.pro create mode 100644 application/webserver/proguard-rules.pro create mode 100644 application/webserver/src/androidTest/java/org/videolan/vlc/webserver/ExampleInstrumentedTest.kt create mode 100644 application/webserver/src/main/AndroidManifest.xml rename application/{vlc-android/src/org/videolan/vlc/server => webserver/src/main/java/org/videolan/vlc/webserver}/NetworkSharingServer.kt (96%) rename application/{vlc-android/src/org/videolan/vlc => webserver/src/main/java/org/videolan/vlc/webserver}/WebServerService.kt (97%) create mode 100644 application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt diff --git a/application/app/build.gradle b/application/app/build.gradle index 4a2f9fb3e..11a1fed5c 100644 --- a/application/app/build.gradle +++ b/application/app/build.gradle @@ -137,7 +137,9 @@ android { dependencies { implementation project(':application:vlc-android') implementation project(':application:television') + implementation project(':application:webserver') testImplementation project(':application:television') + testImplementation project(':application:webserver') androidTestImplementation "androidx.test.espresso:espresso-contrib:$rootProject.espressoVersion" androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion" diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt index bcfd7f63a..a41905e08 100644 --- a/application/resources/src/main/java/org/videolan/resources/Constants.kt +++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt @@ -280,5 +280,6 @@ const val MOVIEPEDIA_ACTIVITY = "org.videolan.moviepedia.ui.MoviepediaActivity" const val TV_AUDIOPLAYER_ACTIVITY = "org.videolan.television.ui.audioplayer.AudioPlayerActivity" const val MEDIAPARSING_SERVICE = "org.videolan.vlc.MediaParsingService" const val TV_ONBOARDING_ACTIVITY = "org.videolan.television.ui.OnboardingActivity" +const val WEBSERVER_SERVICE = "org.videolan.vlc.webserver.WebServerService" const val ROOM_DATABASE = "/vlc_database.zip" \ No newline at end of file diff --git a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt index 09cd94b45..37bccd258 100644 --- a/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt +++ b/application/resources/src/main/java/org/videolan/resources/util/Extensions.kt @@ -233,3 +233,8 @@ fun PackageManager.getPackageInfoCompat(packageName: String, vararg flagArgs: In getPackageInfo(packageName, flags) } } + +fun Context.startWebserver() { + val intent = Intent(ACTION_INIT).setClassName(applicationContext, WEBSERVER_SERVICE) + launchForeground(intent) +} diff --git a/application/vlc-android/AndroidManifest.xml b/application/vlc-android/AndroidManifest.xml index f5af12c7f..5f99d37bb 100644 --- a/application/vlc-android/AndroidManifest.xml +++ b/application/vlc-android/AndroidManifest.xml @@ -20,7 +20,6 @@ - @@ -1059,14 +1058,6 @@ - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/application/vlc-android/src/org/videolan/vlc/server/NetworkSharingServer.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/NetworkSharingServer.kt similarity index 96% rename from application/vlc-android/src/org/videolan/vlc/server/NetworkSharingServer.kt rename to application/webserver/src/main/java/org/videolan/vlc/webserver/NetworkSharingServer.kt index 2883b015a..71e0b8168 100644 --- a/application/vlc-android/src/org/videolan/vlc/server/NetworkSharingServer.kt +++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/NetworkSharingServer.kt @@ -22,7 +22,7 @@ * */ -package org.videolan.vlc.server +package org.videolan.vlc.webserver import android.content.Context import android.net.Uri @@ -55,7 +55,7 @@ import org.videolan.tools.resIdByName import org.videolan.vlc.PlaybackService import org.videolan.vlc.gui.helpers.AudioUtil import org.videolan.vlc.gui.helpers.BitmapUtil -import org.videolan.vlc.server.NetworkSharingServer.init +import org.videolan.vlc.webserver.NetworkSharingServer.init import org.videolan.vlc.util.FileUtils import java.io.File import java.text.DateFormat @@ -82,11 +82,11 @@ object NetworkSharingServer: SingletonHolder({ private fun onServiceChanged(service: PlaybackService?) { if (service !== null) { - this.service = service + NetworkSharingServer.service = service service.addCallback(this) - } else this.service?.let { + } else NetworkSharingServer.service?.let { it.removeCallback(this) - this.service = null + NetworkSharingServer.service = null } } @@ -256,19 +256,19 @@ object NetworkSharingServer: SingletonHolder({ } override fun update() { - generateNowPlaying()?.let {nowPlaying -> + generateNowPlaying()?.let { nowPlaying -> AppScope.launch { websocketSession.forEach { it.send(Frame.Text(nowPlaying)) } } } } override fun onMediaEvent(event: IMedia.Event) { - generateNowPlaying()?.let {nowPlaying -> + generateNowPlaying()?.let { nowPlaying -> AppScope.launch { websocketSession.forEach {it.send(Frame.Text(nowPlaying)) }} } } override fun onMediaPlayerEvent(event: MediaPlayer.Event) { - generateNowPlaying()?.let {nowPlaying -> + generateNowPlaying()?.let { nowPlaying -> AppScope.launch { websocketSession.forEach {it.send(Frame.Text(nowPlaying)) }} } } diff --git a/application/vlc-android/src/org/videolan/vlc/WebServerService.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/WebServerService.kt similarity index 97% rename from application/vlc-android/src/org/videolan/vlc/WebServerService.kt rename to application/webserver/src/main/java/org/videolan/vlc/webserver/WebServerService.kt index 830aa1753..9b3129667 100644 --- a/application/vlc-android/src/org/videolan/vlc/WebServerService.kt +++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/WebServerService.kt @@ -17,7 +17,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. */ -package org.videolan.vlc +package org.videolan.vlc.webserver import android.annotation.SuppressLint import android.content.BroadcastReceiver @@ -34,7 +34,6 @@ import org.videolan.resources.AppContextProvider import org.videolan.resources.util.registerReceiverCompat import org.videolan.tools.getContextWithLocale import org.videolan.vlc.gui.helpers.NotificationHelper -import org.videolan.vlc.server.NetworkSharingServer private const val TAG = "VLC/PlaybackService" diff --git a/application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt b/application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt new file mode 100644 index 000000000..06a863ca0 --- /dev/null +++ b/application/webserver/src/test/java/org/videolan/vlc/webserver/ExampleUnitTest.kt @@ -0,0 +1,41 @@ +/* + * ************************************************************************ + * ExampleUnitTest.kt + * ************************************************************************* + * Copyright © 2022 VLC authors and VideoLAN + * Author: Nicolas POMEPUY + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + * ************************************************************************** + * + * + */ + +package org.videolan.vlc.webserver + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/buildsystem/network-sharing-server/webpack.config.js b/buildsystem/network-sharing-server/webpack.config.js index 80ef5f2bc..08b54a119 100644 --- a/buildsystem/network-sharing-server/webpack.config.js +++ b/buildsystem/network-sharing-server/webpack.config.js @@ -8,7 +8,7 @@ module.exports = [{ // This is necessary for webpack to compile // But we never use style-bundle.js filename: 'style-bundle.js', - path: path.join(__dirname, "../../application/vlc-android/assets/web/public"), + path: path.join(__dirname, "../../application/webserver/assets/web/public"), assetModuleFilename: 'images/[name][ext]' }, plugins: [ diff --git a/settings.gradle b/settings.gradle index effd7f515..a90303ead 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ include ':libvlcjni:libvlc', ':medialibrary' -include ':application:tools', ':application:resources', ':application:mediadb', ':application:app', ':application:live-plot-graph', ':application:television', ':application:donations' +include ':application:tools', ':application:resources', ':application:mediadb', ':application:app', ':application:live-plot-graph', ':application:television', ':application:donations', ':application:webserver' include ':application:vlc-android' include ':application:moviepedia'