Passed
Push — master ( 998e10...1efe83 )
by Marcel
06:10
created

js/sonos.js (1 issue)

1
/**
2
 * Audio Player
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the LICENSE.md file.
6
 *
7
 * @author Marcel Scherello <[email protected]>
8
 * @copyright 2016-2019 Marcel Scherello
9
 */
10
11
/* global Audios */
12
// OK because ./js/app.js is sourced before in html
13
14
'use strict';
0 ignored issues
show
Use the function form of "use strict".
Loading history...
15
16
Audios.prototype.PlaySonos = function (liIndex) {
17
18
    var playIndicator = $('#sonos_play');
19
    var trackids = [];
20
21
    $( '.albumwrapper li' ).each(function() {
22
        var trackid = $(this).data('trackid');
23
        trackids.push(trackid);
24
    });
25
26
    $.ajax({
27
        type: 'POST',
28
        url: OC.generateUrl('apps/audioplayer/sonosqueue'),
29
        data: {
30
            'trackArray': trackids,
31
            'fileIndex': liIndex
32
        },
33
        success: function (jsondata) {
34
            if (jsondata === false) {
35
                OCA.Audioplayer.audiosInstance.SonosGone();
36
            }
37
            playIndicator.addClass('playing');
38
        },
39
        error: function(){
40
            OCA.Audioplayer.audiosInstance.SonosGone();
41
        },
42
        timeout: 3000
43
    });
44
};
45
46
Audios.prototype.SonosGone = function () {
47
    OC.dialogs.alert(t('audioplayer', 'SONOS Player not availble.'), t('audioplayer', 'Error'), function(){
48
        window.location = OC.linkTo('settings','user/audioplayer');
49
    });
50
};
51
52
Audios.prototype.SonosAction = function (action) {
53
    $.ajax({
54
        type: 'POST',
55
        url: OC.generateUrl('apps/audioplayer/sonosaction'),
56
        data: {
57
            'action': action
58
        },
59
        success: function (jsondata) {
60
            if (jsondata === false) {
61
                OCA.Audioplayer.audiosInstance.SonosGone();
62
            }
63
            return true;
64
        },
65
        error: function(){
66
            OCA.Audioplayer.audiosInstance.SonosGone();
67
        },
68
        timeout: 3000
69
    });
70
};
71
72
$(document).ready(function () {
73
    $('#sonos_play').on('click', function () {
74
        var playIndicator = $('#sonos_play');
75
        var action;
76
77
        if (playIndicator.hasClass('playing')) {
78
            playIndicator.removeClass('playing');
79
            action = 'pause';
80
        } else {
81
            action = 'play';
82
        }
83
        if(OCA.Audioplayer.audiosInstance.SonosAction(action)) playIndicator.addClass('playing');
84
    });
85
86
    $('#sonos_prev').on('click', function () {
87
        OCA.Audioplayer.audiosInstance.SonosAction('previous');
88
    });
89
90
    $('#sonos_next').on('click', function () {
91
        OCA.Audioplayer.audiosInstance.SonosAction('next');
92
    });
93
94
    $('#sonos_up').on('click', function () {
95
        OCA.Audioplayer.audiosInstance.SonosAction('up');
96
    });
97
98
    $('#sonos_down').on('click', function () {
99
        OCA.Audioplayer.audiosInstance.SonosAction('down');
100
    });
101
102
});
103