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