mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-29 21:32:41 +00:00
Added support for HTTPS and WSS.
This commit is contained in:
parent
f7408e48f5
commit
67e1dcc14d
@ -535,9 +535,12 @@ public class StreamingPlaybackService implements PlaybackService {
|
||||
if (track != null) {
|
||||
final long trackId = track.optLong("id", -1);
|
||||
if (trackId != -1) {
|
||||
final String protocol = prefs.getBoolean("ssl_enabled", false) ? "https" : "http";
|
||||
|
||||
return String.format(
|
||||
Locale.ENGLISH,
|
||||
"http://%s:%d/audio/id/%d",
|
||||
"%s://%s:%d/audio/id/%d",
|
||||
protocol,
|
||||
prefs.getString("address", "192.168.1.100"),
|
||||
prefs.getInt("http_port", 7906),
|
||||
trackId);
|
||||
|
@ -1,10 +1,15 @@
|
||||
package io.casey.musikcube.remote.ui.activity;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -17,7 +22,6 @@ import java.util.Locale;
|
||||
|
||||
import io.casey.musikcube.remote.R;
|
||||
import io.casey.musikcube.remote.playback.MediaPlayerWrapper;
|
||||
import io.casey.musikcube.remote.playback.PlaybackService;
|
||||
import io.casey.musikcube.remote.playback.PlaybackServiceFactory;
|
||||
import io.casey.musikcube.remote.ui.util.Views;
|
||||
import io.casey.musikcube.remote.websocket.WebSocketService;
|
||||
@ -25,6 +29,7 @@ import io.casey.musikcube.remote.websocket.WebSocketService;
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
private EditText addressText, portText, httpPortText, passwordText;
|
||||
private CheckBox albumArtCheckbox, messageCompressionCheckbox, softwareVolume;
|
||||
private CheckBox sslCheckbox;
|
||||
private Spinner playbackModeSpinner;
|
||||
private SharedPreferences prefs;
|
||||
|
||||
@ -70,6 +75,11 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
this.messageCompressionCheckbox.setChecked(this.prefs.getBoolean("message_compression_enabled", true));
|
||||
this.softwareVolume.setChecked(this.prefs.getBoolean("software_volume", false));
|
||||
|
||||
Views.setCheckWithoutEvent(
|
||||
this.sslCheckbox,
|
||||
this.prefs.getBoolean("ssl_enabled", false),
|
||||
sslCheckChanged);
|
||||
|
||||
Views.enableUpNavigation(this);
|
||||
}
|
||||
|
||||
@ -81,6 +91,14 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
return this.playbackModeSpinner.getSelectedItemPosition() == 1;
|
||||
}
|
||||
|
||||
private CheckBox.OnCheckedChangeListener sslCheckChanged = (button, value) -> {
|
||||
if (value) {
|
||||
if (getSupportFragmentManager().findFragmentByTag(SslAlertDialog.TAG) == null) {
|
||||
SslAlertDialog.newInstance().show(getSupportFragmentManager(), SslAlertDialog.TAG);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void bindEventListeners() {
|
||||
this.addressText = (EditText) this.findViewById(R.id.address);
|
||||
this.portText = (EditText) this.findViewById(R.id.port);
|
||||
@ -90,6 +108,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
this.messageCompressionCheckbox = (CheckBox) findViewById(R.id.message_compression);
|
||||
this.softwareVolume = (CheckBox) findViewById(R.id.software_volume);
|
||||
this.playbackModeSpinner = (Spinner) findViewById(R.id.playback_mode_spinner);
|
||||
this.sslCheckbox = (CheckBox) findViewById(R.id.ssl_checkbox);
|
||||
|
||||
final boolean wasStreaming = isStreamingEnabled();
|
||||
|
||||
@ -108,6 +127,7 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
.putBoolean("message_compression_enabled", messageCompressionCheckbox.isChecked())
|
||||
.putBoolean("streaming_playback", isStreamingSelected())
|
||||
.putBoolean("software_volume", softwareVolume.isChecked())
|
||||
.putBoolean("ssl_enabled", sslCheckbox.isChecked())
|
||||
.apply();
|
||||
|
||||
if (!softwareVolume.isChecked()) {
|
||||
@ -123,4 +143,30 @@ public class SettingsActivity extends AppCompatActivity {
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
public static class SslAlertDialog extends DialogFragment {
|
||||
private static final String LEARN_MORE_URL = "https://github.com/clangen/musikcube/wiki/ssl-server-setup";
|
||||
public static final String TAG = "ssl_alert_dialog_tag";
|
||||
|
||||
public static SslAlertDialog newInstance() {
|
||||
return new SslAlertDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.settings_ssl_dialog_title)
|
||||
.setMessage(R.string.settings_ssl_dialog_message)
|
||||
.setPositiveButton(R.string.button_ok, null)
|
||||
.setNeutralButton(R.string.button_learn_more, (dialog, which) -> {
|
||||
try {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(LEARN_MORE_URL));
|
||||
startActivity(intent);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
}
|
||||
})
|
||||
.create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -497,9 +497,12 @@ public class WebSocketService {
|
||||
try {
|
||||
final WebSocketFactory factory = new WebSocketFactory();
|
||||
|
||||
final String protocol = prefs.getBoolean("ssl_enabled", false) ? "wss" : "ws";
|
||||
|
||||
final String host = String.format(
|
||||
Locale.ENGLISH,
|
||||
"ws://%s:%d",
|
||||
"%s://%s:%d",
|
||||
protocol,
|
||||
prefs.getString("address", "192.168.1.100"),
|
||||
prefs.getInt("port", 7905));
|
||||
|
||||
|
@ -125,12 +125,21 @@
|
||||
android:layout_marginLeft="24dp"
|
||||
android:text="@string/settings_enable_album_art"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/ssl_checkbox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/theme_foreground"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:text="@string/settings_use_ssl"/>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/message_compression"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/theme_foreground"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:visibility="gone"
|
||||
android:text="@string/settings_enable_message_compression"/>
|
||||
|
||||
<CheckBox
|
||||
|
@ -31,6 +31,8 @@
|
||||
<string name="button_save">save</string>
|
||||
<string name="button_settings">settings</string>
|
||||
<string name="button_close">close</string>
|
||||
<string name="button_ok">ok</string>
|
||||
<string name="button_learn_more">learn more</string>
|
||||
<string name="invalid_password_dialog_title">invalid password</string>
|
||||
<string name="invalid_password_dialog_message">the server rejected your password.\n\nchange the password in the settings screen.</string>
|
||||
<string name="status_connecting">connecting</string>
|
||||
@ -50,10 +52,13 @@
|
||||
<string name="unknown_value"><unknown></string>
|
||||
<string name="settings_playback_mode">playback mode:</string>
|
||||
<string name="settings_general">general:</string>
|
||||
<string name="settings_use_ssl">use ssl for server connections</string>
|
||||
<string name="settings_enable_album_art">enable album art (uses last.fm)</string>
|
||||
<string name="settings_enable_message_compression">enable message compression</string>
|
||||
<string name="settings_enable_streaming_playback">enable streaming playback</string>
|
||||
<string name="settings_enable_software_volume">use software volume while streaming</string>
|
||||
<string name="settings_ssl_dialog_title">ssl information</string>
|
||||
<string name="settings_ssl_dialog_message">the musikcube server doesn\'t support ssl by default. it does, however, work very well with nginx and ssl termination. press \'learn more\' for configuration information.</string>
|
||||
<string name="unknown_artist">[unknown artist]</string>
|
||||
<string name="unknown_album">[unknown album]</string>
|
||||
<string name="unknown_title">[unknown title]</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user