mirror of
https://github.com/SuperBFG7/ympd
synced 2025-05-05 00:44:06 +00:00
Fix: websocket url if connected by ip
This commit is contained in:
parent
74921eb8bc
commit
e550601aa8
@ -542,6 +542,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<p>Connection to myMPD failed. Trying to reconnect.</p>
|
<p>Connection to myMPD failed. Trying to reconnect.</p>
|
||||||
|
<p id="wsUrl"></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -685,12 +685,13 @@ function playlistMoveTrack(from, to) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function webSocketConnect() {
|
function webSocketConnect() {
|
||||||
socket = new WebSocket(getWsUrl());
|
var wsUrl = getWsUrl();
|
||||||
|
socket = new WebSocket(wsUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
socket.onopen = function() {
|
socket.onopen = function() {
|
||||||
console.log('connected');
|
console.log('connected');
|
||||||
showNotification('Connected to myMPD', '', '', 'success');
|
showNotification('Connected to myMPD: ' + wsUrl, '', '', 'success');
|
||||||
modalConnectionError.hide();
|
modalConnectionError.hide();
|
||||||
appRoute();
|
appRoute();
|
||||||
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
|
sendAPI({"cmd": "MPD_API_PLAYER_STATE"}, parseState);
|
||||||
@ -711,7 +712,7 @@ function webSocketConnect() {
|
|||||||
parseState(obj);
|
parseState(obj);
|
||||||
break;
|
break;
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
showNotification('myMPD lost connection to MPD', '', '', 'danger');
|
showNotification('Lost connection to myMPD: ' + wsUrl, '', '', 'danger');
|
||||||
break;
|
break;
|
||||||
case 'update_queue':
|
case 'update_queue':
|
||||||
if (app.current.app === 'Queue')
|
if (app.current.app === 'Queue')
|
||||||
@ -754,26 +755,18 @@ function webSocketConnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getWsUrl() {
|
function getWsUrl() {
|
||||||
var pcol;
|
var hostname = window.location.hostname;
|
||||||
var u = document.URL;
|
var protocol = window.location.protocol;
|
||||||
var separator;
|
var port = window.location.port;
|
||||||
|
|
||||||
if (u.substring(0, 5) == 'https') {
|
if (protocol == 'https:')
|
||||||
pcol = 'wss://';
|
protocol = 'wss://';
|
||||||
u = u.substr(8);
|
|
||||||
} else {
|
|
||||||
pcol = 'ws://';
|
|
||||||
if (u.substring(0, 4) == 'http')
|
|
||||||
u = u.substr(7);
|
|
||||||
}
|
|
||||||
|
|
||||||
u = u.split('#');
|
|
||||||
if (/\/$/.test(u[0]))
|
|
||||||
separator = '';
|
|
||||||
else
|
else
|
||||||
separator = '/';
|
protocol = 'ws://';
|
||||||
|
|
||||||
return pcol + u[0] + separator + 'ws';
|
var wsUrl = protocol + hostname + (port != '' ? ':' + port : '') + '/ws';
|
||||||
|
document.getElementById('wsUrl').innerText = wsUrl;
|
||||||
|
return wsUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStats(obj) {
|
function parseStats(obj) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user