Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2021 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 | */ |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 20 | "use strict" |
Adrien Béraud | 947e879 | 2021-04-15 18:32:44 -0400 | [diff] [blame] | 21 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 22 | import Account from './model/Account.js' |
| 23 | import Conversation from './model/Conversation.js' |
| 24 | import { createRequire } from 'module'; |
| 25 | const require = createRequire(import.meta.url); |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 26 | |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 27 | class JamiDaemon { |
| 28 | constructor() { |
| 29 | this.accounts = [] |
| 30 | this.dring = require("./dring.node") |
| 31 | this.dring.init({ |
| 32 | "AccountsChanged": () => { |
| 33 | console.log("AccountsChanged") |
| 34 | const newAccounts = [] |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 35 | JamiDaemon.vectToJs(this.dring.getAccountList()).forEach(accountId => { |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 36 | for (const account in this.accounts) { |
| 37 | if (account.id === accountId) { |
| 38 | newAccounts.push(account) |
| 39 | return |
| 40 | } |
| 41 | } |
| 42 | newAccounts.push(new Account(accountId, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 43 | JamiDaemon.mapToJs(this.dring.getAccountDetails(accountId)), |
| 44 | JamiDaemon.mapToJs(this.dring.getVolatileAccountDetails(accountId)) |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 45 | )) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 46 | }) |
| 47 | this.accounts = newAccounts |
| 48 | }, |
| 49 | "AccountDetailsChanged": (accountId, details) => { |
| 50 | console.log(`AccountDetailsChanged ${accountId}`) |
| 51 | const account = this.getAccount(accountId) |
| 52 | if (!account) { |
| 53 | console.log(`Unknown account ${accountId}`) |
| 54 | return |
| 55 | } |
| 56 | account.details = details |
| 57 | }, |
| 58 | "VolatileDetailsChanged": (accountId, details) => { |
| 59 | console.log(`VolatileDetailsChanged ${accountId}`) |
| 60 | const account = this.getAccount(accountId) |
| 61 | if (!account) { |
| 62 | console.log(`Unknown account ${accountId}`) |
| 63 | return |
| 64 | } |
| 65 | account.volatileDetails = details |
| 66 | }, |
| 67 | "IncomingAccountMessage": (accountId, from, message) => { |
| 68 | console.log(`Received message: ${accountId} ${from} ${message["text/plain"]}`) |
| 69 | /* |
| 70 | if (parser.validate(message["text/plain"]) === true) { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 71 | console.log(message["text/plain"]) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 72 | } else { |
| 73 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 74 | user = connectedUsers[accountId] |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 75 | console.log(user.socketId) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 76 | io.to(user.socketId).emit('receivedMessage', message["text/plain"]) |
| 77 | //io.emit('receivedMessage', message["text/plain"]) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 78 | }*/ |
| 79 | }, |
| 80 | "RegistrationStateChanged": (accountId, state, /*int*/ code, detail) => { |
| 81 | const account = this.getAccount(accountId) |
| 82 | if (!account) { |
| 83 | console.log(`Unknown account ${accountId}`) |
| 84 | return |
| 85 | } |
| 86 | account.registrationState = state |
| 87 | console.log("RegistrationStateChanged: " + accountId + " " + state + " " + code + " " + detail) |
| 88 | if (state === "REGISTERED") { |
| 89 | /*if (tempAccounts[accountId]) { |
| 90 | |
| 91 | const ctx = tempAccounts[accountId] |
| 92 | ctx.newUser.accountId = accountId |
| 93 | ctx.newUser.jamiId = jami.dring.getAccountDetails(accountId).get("Account.username") |
| 94 | //connectedUsers[accountId] = ctx.newUser |
| 95 | ctx.done(null, ctx.newUser) |
| 96 | delete tempAccounts[accountId] |
| 97 | }*/ |
| 98 | } else if (state === "ERROR_AUTH") { |
| 99 | //done(null, false) |
| 100 | //remove account |
| 101 | } |
| 102 | }, |
| 103 | "RegisteredNameFound": (accountId, state, address, name) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 104 | console.log(`RegisteredNameFound: ${accountId} ${state} ${address} ${name}`) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 105 | const account = this.getAccount(accountId) |
| 106 | if (!account) { |
| 107 | console.log(`Unknown account ${accountId}`) |
| 108 | return |
| 109 | } |
| 110 | if (state == 0) { |
| 111 | const contact = account.getContactFromCache(address) |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 112 | if (!contact.isRegisteredNameResolved()) |
| 113 | contact.setRegisteredName(name) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 114 | } |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 115 | let index = account.lookups.length - 1 |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 116 | while (index >= 0) { |
| 117 | const lookup = account.lookups[index] |
| 118 | if ((lookup.address && lookup.address === address) || (lookup.name && lookup.name === name)) { |
| 119 | lookup.resolve({address, name, state}) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 120 | account.lookups.splice(index, 1) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 121 | } |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 122 | index -= 1 |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 123 | } |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 124 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 125 | "ConversationReady": (accountId, conversationId) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 126 | console.log(`conversationReady: ${accountId} ${conversationId}`) |
| 127 | const account = this.getAccount(accountId) |
| 128 | if (!account) { |
| 129 | console.log(`Unknown account ${accountId}`) |
| 130 | return |
| 131 | } |
| 132 | let conversation = account.getConversation(conversationId) |
| 133 | if (!conversation) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 134 | const members = JamiDaemon.vectMapToJs(this.dring.getConversationMembers(accountId, conversationId)) |
| 135 | members.forEach(member => member.contact = account.getContactFromCache(member.uri)) |
| 136 | conversation = new Conversation(conversationId, accountId, members) |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 137 | account.addConversation(conversation) |
| 138 | } |
| 139 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 140 | "ConversationRemoved": (accountId, conversationId) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 141 | console.log(`conversationRemoved: ${accountId} ${conversationId}`) |
| 142 | const account = this.getAccount(accountId) |
| 143 | if (!account) { |
| 144 | console.log(`Unknown account ${accountId}`) |
| 145 | return |
| 146 | } |
| 147 | account.removeConversation(conversationId) |
| 148 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 149 | "ConversationLoaded": (accountId, conversationId) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 150 | console.log(`conversationLoaded: ${accountId} ${conversationId}`) |
| 151 | const account = this.getAccount(accountId) |
| 152 | if (!account) { |
| 153 | console.log(`Unknown account ${accountId}`) |
| 154 | return |
| 155 | } |
| 156 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 157 | "MessageReceived": (accountId, conversationId, message) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 158 | console.log(`messageReceived: ${accountId} ${conversationId}`) |
| 159 | const account = this.getAccount(accountId) |
| 160 | if (!account) { |
| 161 | console.log(`Unknown account ${accountId}`) |
| 162 | return |
| 163 | } |
| 164 | const conversation = account.getConversation(conversationId) |
| 165 | if (!conversation) { |
| 166 | conversation.addMessage(message) |
| 167 | } |
| 168 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 169 | "ConversationRequestReceived": (accountId, conversationId, request) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 170 | console.log(`conversationRequestReceived: ${accountId} ${conversationId}`) |
| 171 | const account = this.getAccount(accountId) |
| 172 | if (!account) { |
| 173 | console.log(`Unknown account ${accountId}`) |
| 174 | return |
| 175 | } |
| 176 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 177 | "ConversationMemberEvent": (accountId, conversationId, member, event) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 178 | console.log(`conversationMemberEvent: ${accountId} ${conversationId}`) |
| 179 | const account = this.getAccount(accountId) |
| 180 | if (!account) { |
| 181 | console.log(`Unknown account ${accountId}`) |
| 182 | return |
| 183 | } |
| 184 | }, |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 185 | "OnConversationError": (accountId, conversationId, code, what) => { |
Adrien Béraud | 0cb76c9 | 2021-04-07 19:59:08 -0400 | [diff] [blame] | 186 | console.log(`onConversationError: ${accountId} ${conversationId}`) |
| 187 | const account = this.getAccount(accountId) |
| 188 | if (!account) { |
| 189 | console.log(`Unknown account ${accountId}`) |
| 190 | return |
| 191 | } |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 192 | } |
| 193 | }) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 194 | |
| 195 | JamiDaemon.vectToJs(this.dring.getAccountList()).forEach(accountId => { |
| 196 | const account = new Account(accountId, |
| 197 | JamiDaemon.mapToJs(this.dring.getAccountDetails(accountId)), |
| 198 | JamiDaemon.mapToJs(this.dring.getVolatileAccountDetails(accountId)) |
| 199 | ) |
| 200 | JamiDaemon.vectToJs(this.dring.getConversations(accountId)).forEach(conversationId => { |
| 201 | const members = JamiDaemon.vectMapToJs(this.dring.getConversationMembers(accountId, conversationId)) |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 202 | members.forEach(member => { |
| 203 | member.contact = account.getContactFromCache(member.uri) |
| 204 | if (!member.contact.isRegisteredNameResolved()) { |
| 205 | if (!member.uri) return |
| 206 | console.log(`lookupAddress ${accountId} ${member.uri}`) |
| 207 | member.contact.setRegisteredName(new Promise((resolve, reject) => |
| 208 | account.lookups.push({address: member.uri, resolve, reject}) |
| 209 | ).then(result => { |
| 210 | if (result.state == 0) |
| 211 | return result.name |
| 212 | else if (result.state == 1) |
| 213 | return undefined |
| 214 | else |
| 215 | return null |
| 216 | })) |
| 217 | this.dring.lookupAddress(accountId, "", member.uri) |
| 218 | } |
| 219 | }) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 220 | const conversation = new Conversation(conversationId, accountId, members) |
| 221 | account.addConversation(conversation) |
| 222 | }) |
| 223 | this.accounts.push(account) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 224 | }) |
| 225 | } |
| 226 | |
| 227 | addAccount(account) { |
| 228 | const params = accountDetailsToNative(account) |
| 229 | params.set("Account.type", "RING") |
| 230 | return this.dring.addAccount(params) |
| 231 | } |
| 232 | getAccount(accountId) { |
| 233 | for (let i = 0; i < this.accounts.length; i++) { |
| 234 | const account = this.accounts[i] |
| 235 | if (account.getId() === accountId) |
| 236 | return account |
| 237 | } |
| 238 | return undefined |
| 239 | } |
| 240 | getAccountList() { |
| 241 | return this.accounts |
| 242 | } |
| 243 | /*getAccountDetails(accountId) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 244 | return this.mapToJs(this.dring.getAccountDetails(accountId)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 245 | }*/ |
| 246 | setAccountDetails(accountId, details) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 247 | this.dring.setAccountDetails(accountId, mapToNative(details)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 248 | } |
| 249 | getAudioOutputDeviceList() { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 250 | return JamiDaemon.vectToJs(this.dring.getAudioOutputDeviceList()) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 251 | } |
| 252 | getVolume(deviceName) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 253 | return this.dring.getVolume(deviceName) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 254 | } |
| 255 | setVolume(deviceName, volume) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 256 | return this.dring.setVolume(deviceName, volume) |
| 257 | } |
| 258 | |
| 259 | lookupName(accountId, name) { |
| 260 | const p = new Promise((resolve, reject) => { |
| 261 | const account = this.getAccount(accountId) |
| 262 | if (!account) { |
| 263 | reject(new Error("Can't find account")) |
| 264 | } else { |
| 265 | account.lookups.push({name, resolve, reject}) |
| 266 | } |
| 267 | }) |
| 268 | this.dring.lookupName(accountId, "", name) |
| 269 | return p |
| 270 | } |
| 271 | |
| 272 | lookupAddress(accountId, address) { |
| 273 | console.log(`lookupAddress ${accountId} ${address}`) |
| 274 | const p = new Promise((resolve, reject) => { |
| 275 | const account = this.getAccount(accountId) |
| 276 | if (!account) { |
| 277 | reject(new Error("Can't find account")) |
| 278 | } else { |
| 279 | account.lookups.push({address, resolve, reject}) |
| 280 | } |
| 281 | }) |
| 282 | this.dring.lookupAddress(accountId, "", address) |
| 283 | return p |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | stop() { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 287 | this.dring.fini() |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 290 | addContact(accountId, contactId) { |
| 291 | this.dring.addContact(accountId, contactId) |
| 292 | const details = JamiDaemon.mapToJs(this.dring.getContactDetails(accountId, contactId)) |
| 293 | if (details.conversationId) { |
| 294 | const account = this.getAccount(accountId) |
| 295 | if (account) { |
| 296 | let conversation = account.getConversation(details.conversationId) |
| 297 | if (!conversation) { |
| 298 | const members = JamiDaemon.vectMapToJs(this.dring.getConversationMembers(accountId, details.conversationId)) |
| 299 | members.forEach(member => member.contact = account.getContactFromCache(member.uri)) |
| 300 | conversation = new Conversation(details.conversationId, accountId, members) |
| 301 | account.addConversation(conversation) |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | return details |
| 306 | } |
| 307 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 308 | getDefaultModerators(accountId) { |
| 309 | const account = this.getAccount(accountId) |
| 310 | if (!account) { |
| 311 | console.log(`Unknown account ${accountId}`) |
| 312 | return {} |
| 313 | } |
| 314 | return JamiDaemon.vectToJs(this.dring.getDefaultModerators(accountId)) |
| 315 | .map(contactId => account.getContactFromCache(contctId)) |
| 316 | } |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 317 | |
Adrien Béraud | 150b478 | 2021-04-21 19:40:59 -0400 | [diff] [blame] | 318 | setDefaultModerators(accountId, moderators) { |
| 319 | |
| 320 | } |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 321 | |
| 322 | boolToStr(bool) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 323 | return bool ? "true" : "false" |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | accountDetailsToNative(account) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 327 | const params = new this.dring.StringMap() |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 328 | if (account.managerUri) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 329 | params.set("Account.managerUri", account.managerUri) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 330 | if (account.managerUsername) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 331 | params.set("Account.managerUsername", account.managerUsername) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 332 | if (account.archivePassword) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 333 | params.set("Account.archivePassword", account.archivePassword) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 334 | } else { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 335 | console.log("archivePassword required") |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 336 | return |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 337 | } |
| 338 | if (account.alias) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 339 | params.set("Account.alias", account.alias) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 340 | if (account.displayName) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 341 | params.set("Account.displayName", account.displayName) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 342 | if (account.enable) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 343 | params.set("Account.enable", this.boolToStr(account.enable)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 344 | if (account.autoAnswer) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 345 | params.set("Account.autoAnswer", this.boolToStr(account.autoAnswer)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 346 | if (account.ringtonePath) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 347 | params.set("Account.ringtonePath", account.ringtonePath) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 348 | if (account.ringtoneEnabled) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 349 | params.set("Account.ringtoneEnabled", this.boolToStr(account.ringtoneEnabled)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 350 | if (account.videoEnabled) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 351 | params.set("Account.videoEnabled", this.boolToStr(account.videoEnabled)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 352 | if (account.useragent) { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 353 | params.set("Account.useragent", account.useragent) |
| 354 | params.set("Account.hasCustomUserAgent", "TRUE") |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 355 | } else { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 356 | params.set("Account.hasCustomUserAgent", "FALSE") |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 357 | } |
| 358 | if (account.audioPortMin) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 359 | params.set("Account.audioPortMin", account.audioPortMin) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 360 | if (account.audioPortMax) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 361 | params.set("Account.audioPortMax", account.audioPortMax) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 362 | if (account.videoPortMin) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 363 | params.set("Account.videoPortMin", account.videoPortMin) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 364 | if (account.videoPortMax) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 365 | params.set("Account.videoPortMax", account.videoPortMax) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 366 | if (account.localInterface) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 367 | params.set("Account.localInterface", account.localInterface) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 368 | if (account.publishedSameAsLocal) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 369 | params.set("Account.publishedSameAsLocal", this.boolToStr(account.publishedSameAsLocal)) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 370 | if (account.localPort) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 371 | params.set("Account.localPort", account.localPort) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 372 | if (account.publishedPort) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 373 | params.set("Account.publishedPort", account.publishedPort) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 374 | if (account.publishedAddress) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 375 | params.set("Account.publishedAddress", account.publishedAddress) |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 376 | if (account.upnpEnabled) |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 377 | params.set("Account.upnpEnabled", this.boolToStr(account.upnpEnabled)) |
| 378 | return params |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 379 | } |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 380 | static vectToJs(vect) { |
| 381 | const len = vect.size() |
| 382 | const outputArr = new Array(len) |
| 383 | for (let i = 0; i < len; i++) |
| 384 | outputArr[i] = vect.get(i) |
| 385 | return outputArr |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 386 | } |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 387 | static mapToJs(m) { |
| 388 | const outputObj = {} |
| 389 | JamiDaemon.vectToJs(m.keys()) |
| 390 | .forEach(k => outputObj[k] = m.get(k)) |
| 391 | return outputObj |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 392 | } |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 393 | static vectMapToJs(vectMap) { |
| 394 | const len = vectMap.size() |
| 395 | const outputArr = new Array(len) |
| 396 | for (let i = 0; i < len; i++) |
| 397 | outputArr[i] = JamiDaemon.mapToJs(vectMap.get(i)) |
| 398 | return outputArr |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 401 | mapToNative(map){ |
| 402 | const ret = new this.dring.StringMap() |
| 403 | map.forEach((value, key) => ret.set(key, value)) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 404 | return ret |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 405 | } |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 406 | } |
| 407 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 408 | export default JamiDaemon |