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: "telephony"
28 property var verbs: []
29 property string payloadLength: "9999"
31 readonly property var msgid: {
38 onTextMessageReceived: {
39 var json = JSON.parse(message)
40 var request = json[2].request
41 var response = json[2].response
46 root.statusString = request.status
47 var verb = verbs.shift()
49 console.debug("Dial response")
50 } else if (verb == "hangup") {
51 console.debug("Hangup response")
55 root.statusString = "Bad return value, binding probably not installed"
58 var payload = JSON.parse(JSON.stringify(json[2]))
59 var event = payload.event
60 var data = payload.data
61 if (event == "telephony/incomingCall") {
62 callClipColp = data.clip
63 callStatus = "incoming"
64 } else if (event == "telephony/dialingCall") {
65 callClipColp = data.colp
66 callStatus = "dialing"
67 } else if (event == "telephony/terminatedCall") {
68 callStatus = "disconnected"
69 } else if (event == "telephony/callStateChanged") {
70 callStatus = data.state
81 root.statusString = "WebSocket error: " + root.errorString
86 function sendSocketMesage(verb, parameter) {
87 var requestJson = [ msgid.call, payloadLength, apiString + '/' + verb, parameter ]
89 sendTextMessage(JSON.stringify(requestJson))
92 function dial(number) {
93 var parameterJson = { value: number }
94 sendSocketMesage("dial", parameterJson)
98 var parameterJson = 'None'
99 sendSocketMesage("answer", parameterJson)
103 var parameterJson = 'None'
104 sendSocketMesage("hangup", parameterJson)