blob: 6ce5a71aaa418282f2242931c2523a2dff1de175 [file] [log] [blame]
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -04001/*
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-Raynauldb6f1c322022-10-23 20:42:57 -040018import { itMap, itRange, itToArr, itToMap, itToRecord } from './utils.js';
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040019
20enum Bool {
21 False = 'false',
22 True = 'true',
23}
24
25interface SwigVec<T> {
26 size(): number;
27 get(i: number): T; // TODO: | undefined;
28}
29
30interface 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-Raynauldb6f1c322022-10-23 20:42:57 -040036// TODO: Review these conversion functions
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040037const swigVecToIt = <T>(v: SwigVec<T>) => itMap(itRange(0, v.size()), (i) => v.get(i));
38const swigMapToIt = <T, U>(m: SwigMap<T, U>) => itMap(swigVecToIt(m.keys()), (k): [T, U] => [k, m.get(k)]);
39
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040040// export type IntVect = SwigVec<number>;
41// export type UintVect = SwigVec<number>;
42// export type FloatVect = SwigVec<number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040043export type StringVect = SwigVec<string>;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040044// export type IntegerMap = SwigMap<string, number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040045export type StringMap = SwigMap<string, string>;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040046export type VectMap = SwigVec<StringMap>;
47// export type Blob = SwigVec<number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040048
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040049// TODO: Consider always converting to Record rather than Map as conversion to interfaces is easier
50export const stringVectToArray = (sv: StringVect) => itToArr(swigVecToIt(sv));
51export const stringMapToRecord = (sm: StringMap) => itToRecord(swigMapToIt(sm));
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040052export const stringMapToMap = (sm: StringMap) => itToMap(swigMapToIt(sm));
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040053// export const vectMapToArrayMap = (vm: VectMap) => itToArr(itMap(swigVecToIt(vm), stringMapToMap));
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040054
55export interface JamiSwig {
56 init(args: Record<string, unknown>): void;
Misha Krieger-Raynauld62a0da92022-10-22 13:46:59 -040057 fini(): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040058
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040059 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-Raynauldaddd6fe2022-10-22 12:46:04 -040096 // 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-Raynauldaddd6fe2022-10-22 12:46:04 -0400104}