Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 Savoir-faire Linux Inc. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Affero General Public License as |
| 6 | * published by the Free Software Foundation; either version 3 of the |
| 7 | * License, or (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Affero General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Affero General Public |
| 15 | * License along with this program. If not, see |
| 16 | * <https://www.gnu.org/licenses/>. |
| 17 | */ |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 18 | import { itMap, itRange, itToArr, itToMap, itToRecord } from './utils.js'; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 19 | |
| 20 | enum Bool { |
| 21 | False = 'false', |
| 22 | True = 'true', |
| 23 | } |
| 24 | |
| 25 | interface SwigVec<T> { |
| 26 | size(): number; |
| 27 | get(i: number): T; // TODO: | undefined; |
| 28 | } |
| 29 | |
| 30 | interface SwigMap<T, U> { |
| 31 | keys(): SwigVec<T>; |
| 32 | get(k: T): U; // TODO: | undefined; |
| 33 | set(k: T, v: U): void; |
| 34 | } |
| 35 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 36 | // TODO: Review these conversion functions |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 37 | const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i)); |
| 38 | const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]); |
| 39 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 40 | // export type IntVect = SwigVec<number>; |
| 41 | // export type UintVect = SwigVec<number>; |
| 42 | // export type FloatVect = SwigVec<number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 43 | export type StringVect = SwigVec<string>; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 44 | // export type IntegerMap = SwigMap<string, number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 45 | export type StringMap = SwigMap<string, string>; |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 46 | export type VectMap = SwigVec<StringMap>; |
| 47 | // export type Blob = SwigVec<number>; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 48 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 49 | // TODO: Consider always converting to Record rather than Map as conversion to interfaces is easier |
| 50 | export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv)); |
| 51 | export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm)); |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 52 | export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm)); |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 53 | // export const vectMapToArrayMap = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap)); |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 54 | |
| 55 | export interface JamiSwig { |
| 56 | init(args: Record<string, unknown>): void; |
Misha Krieger-Raynauld | 62a0da9 | 2022-10-22 13:46:59 -0400 | [diff] [blame] | 57 | fini(): void; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 58 | |
Misha Krieger-Raynauld | b6f1c32 | 2022-10-23 20:42:57 -0400 | [diff] [blame] | 59 | getAccountDetails(accountId: string): StringMap; |
| 60 | getVolatileAccountDetails(accountId: string): StringMap; |
| 61 | setAccountDetails(accountId: string, details: StringMap): void; |
| 62 | setAccountActive(accountId: string, active: Bool): void; |
| 63 | |
| 64 | addAccount(details: StringMap): string; |
| 65 | removeAccount(accountId: string): void; |
| 66 | |
| 67 | getAccountList(): StringVect; |
| 68 | |
| 69 | lookupName(accountId: string, nameserver: string, username: string): boolean; |
| 70 | lookupAddress(accountId: string, nameserver: string, address: string): boolean; |
| 71 | registerName(accountId: string, password: string, username: string): boolean; |
| 72 | |
| 73 | getKnownRingDevices(accountId: string): StringMap; |
| 74 | |
| 75 | getAudioOutputDeviceList(): StringVect; |
| 76 | |
| 77 | getVolume(device: string): number; |
| 78 | setVolume(device: string, value: number): void; |
| 79 | |
| 80 | addContact(accountId: string, contactId: string): void; |
| 81 | removeContact(accountId: string, contactId: string, ban: boolean): void; |
| 82 | getContacts(accountId: string): VectMap; |
| 83 | getContactDetails(accountId: string, contactId: string): StringMap; |
| 84 | |
| 85 | getDefaultModerators(accountId: string): StringVect; |
| 86 | setDefaultModerators(accountId: string, uri: string, state: boolean): void; |
| 87 | |
| 88 | getConversations(accountId: string): StringVect; |
| 89 | conversationInfos(accountId: string, conversationId: string): StringMap; |
| 90 | |
| 91 | getConversationMembers(accountId: string, conversationId: string): VectMap; |
| 92 | |
| 93 | sendMessage(accountId: string, conversationId: string, message: string, replyTo: string): void; |
| 94 | loadConversationMessages(accountId: string, conversationId: string, fromMessage: string, n: number): number; |
| 95 | |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 96 | // IntVect(): IntVect; |
| 97 | // UintVect(): UintVect; |
| 98 | // FloatVect(): FloatVect; |
| 99 | // StringVect(): StringVect; |
| 100 | // IntegerMap(): IntegerMap |
| 101 | // StringMap(): StringMap; |
| 102 | // VectMap(): VectMap; |
| 103 | // IntegerMap(): IntegerMap; |
Misha Krieger-Raynauld | addd6fe | 2022-10-22 12:46:04 -0400 | [diff] [blame] | 104 | } |