2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2017 Konsulko Group
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 import QtWebSockets 1.0
26 property string statusString: "waiting..."
27 property string apiString: "media-manager"
28 property var verbs: []
29 property string payloadLength: "9999"
31 readonly property var msgid: {
38 onTextMessageReceived: {
39 var json = JSON.parse(message)
40 console.debug("Raw response: " + message)
41 var request = json[2].request
42 var response = json[2].response
43 console.debug("response: " + JSON.stringify(response))
48 root.statusString = request.status
49 var verb = verbs.shift()
50 if (verb == "media_result") {
51 console.debug("Media result returned")
52 playlist.addItems(response.Media)
56 root.statusString = "Bad return value, binding probably not installed"
59 var payload = JSON.parse(JSON.stringify(json[2]))
60 var event = payload.event
61 if (event == "media-manager/media_added") {
62 console.debug("Media is inserted")
63 playlist.addItems(json[2].data.Media)
64 } else if (event == "media-manager/media_removed") {
65 console.debug("Media is removed")
76 console.debug("onStatusChanged: Open")
77 sendSocketMessage("subscribe", { value: "media_added" })
78 sendSocketMessage("subscribe", { value: "media_removed" })
79 root.populateMediaPlaylist()
82 root.statusString = "WebSocket error: " + root.errorString
87 function sendSocketMessage(verb, parameter) {
88 var requestJson = [ msgid.call, payloadLength, apiString + '/'
90 console.debug("sendSocketMessage: " + JSON.stringify(requestJson))
92 sendTextMessage(JSON.stringify(requestJson))
95 function populateMediaPlaylist() {
96 sendSocketMessage("media_result", 'None')