blob: c194321969f0c1a7c0d70c880ac676df964860fc [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001/*
2 * Copyright (c) 2017 Savoir-faire Linux Inc.
3 *
4 * Author: Adrien BĂ©raud <adrien.beraud@savoirfairelinux.com>
5 * Author: Asad Salman <me@asad.co>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
22"use strict";
23class RingDaemon {
24 constructor(callbackMap) {
25 if (callbackMap) {
26 this.dring = require("./dring.node");
27 this.dring.init(callbackMap);
28 }
29 }
30
31 boolToStr(bool) {
32 if (bool)
33 return "TRUE";
34 else
35 return "FALSE";
36 }
37
38 addAccount(account) {
39 var params = new this.dring.StringMap();
40 params.set("Account.type", "RING");
41 if (account.archivePassword) {
42 params.set("Account.archivePassword", account.archivePassword);
43 } else {
44 console.log("archivePassword required");
45 return;
46 }
47 if (account.alias)
48 params.set("Account.alias", account.alias);
49 if (account.displayName)
50 params.set("Account.displayName", account.displayName);
51 if (account.enable)
52 params.set("Account.enable", this.boolToStr(account.enable));
53 if (account.autoAnswer)
54 params.set("Account.autoAnswer", this.boolToStr(account.autoAnswer));
55 if (account.ringtonePath)
56 params.set("Account.ringtonePath", account.ringtonePath);
57 if (account.ringtoneEnabled)
58 params.set("Account.ringtoneEnabled", this.boolToStr(account.ringtoneEnabled));
59 if (account.videoEnabled)
60 params.set("Account.videoEnabled", this.boolToStr(account.videoEnabled));
61 if (account.useragent) {
62 params.set("Account.useragent", account.useragent);
63 params.set("Account.hasCustomUserAgent", "TRUE");
64 } else {
65 params.set("Account.hasCustomUserAgent", "FALSE");
66 }
67 if (account.audioPortMin)
68 params.set("Account.audioPortMin", account.audioPortMin);
69 if (account.audioPortMax)
70 params.set("Account.audioPortMax", account.audioPortMax);
71 if (account.videoPortMin)
72 params.set("Account.videoPortMin", account.videoPortMin);
73 if (account.videoPortMax)
74 params.set("Account.videoPortMax", account.videoPortMax);
75 if (account.localInterface)
76 params.set("Account.localInterface", account.localInterface);
77 if (account.publishedSameAsLocal)
78 params.set("Account.publishedSameAsLocal", this.boolToStr(account.publishedSameAsLocal));
79 if (account.localPort)
80 params.set("Account.localPort", account.localPort);
81 if (account.publishedPort)
82 params.set("Account.publishedPort", account.publishedPort);
83 if (account.publishedAddress)
84 params.set("Account.publishedAddress", account.publishedAddress);
85 if (account.upnpEnabled)
86 params.set("Account.upnpEnabled", this.boolToStr(account.upnpEnabled));
87
88 this.dring.addAccount(params);
89 }
90 stringVectToArr(stringvect) {
91 const outputArr = [];
92 for (let i = 0; i < stringvect.size(); i++)
93 outputArr.push(stringvect.get(i));
94 return outputArr;
95 }
96 mapToJs(m) {
97 const outputObj = {};
98 this.stringVectToArr(m.keys())
99 .forEach(k => outputObj[k] = m.get(k));
100 return outputObj;
101 }
102 getAccountList() {
103 return this.stringVectToArr(this.dring.getAccountList());
104 }
105 getAccountDetails(accountId) {
106 return this.mapToJs(this.dring.getAccountDetails(accountId));
107 }
108 getAudioOutputDeviceList() {
109 return this.stringVectToArr(this.dring.getAudioOutputDeviceList());
110 }
111 getVolume(deviceName) {
112 return this.dring.getVolume(deviceName);
113 }
114
115 setVolume(deviceName, volume) {
116 return this.dring.setVolume(deviceName, volume);
117 }
118
119 stop() {
120 clearInterval(this.pollIntervalId);
121 this.dring.fini();
122 }
123}
124
125module.exports = RingDaemon;