blob: 07fa2dd334ebe5e0cf00ee015b28e7220a1c60ab [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-Raynauldb933fbb2022-11-15 15:11:09 -050018import { Constructable } from '../interfaces/constructable.js';
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040019
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050020interface SwigVect<T> {
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040021 size(): number;
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050022 get(index: number): T | undefined;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040023}
24
25interface SwigMap<T, U> {
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050026 keys(): SwigVect<T>;
27 get(key: T): U | undefined;
28 set(key: T, value: U): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040029}
30
Michelle Sepkap Simedd82cbf2022-11-17 23:31:49 -050031// export type IntVect = SwigVect<number>;
32// export type UintVect = SwigVect<number>;
33// export type FloatVect = SwigVect<number>;
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050034export type StringVect = SwigVect<string>;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040035// export type IntegerMap = SwigMap<string, number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040036export type StringMap = SwigMap<string, string>;
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050037export type VectMap = SwigVect<StringMap>;
Michelle Sepkap Simedd82cbf2022-11-17 23:31:49 -050038export type Blob = SwigVect<number>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040039
Misha Krieger-Raynauldb933fbb2022-11-15 15:11:09 -050040function* swigVectToIt<T>(swigVect: SwigVect<T>) {
41 const size = swigVect.size();
42 for (let i = 0; i < size; i++) {
43 yield swigVect.get(i)!;
44 }
45}
46
47function* swigMapToIt<T, U>(swigMap: SwigMap<T, U>) {
48 const keys = swigVectToIt(swigMap.keys());
49 for (const key of keys) {
50 const value = swigMap.get(key)!;
51 yield [key, value];
52 }
53}
54
55export function stringVectToArray(stringVect: StringVect): string[] {
56 const elements = swigVectToIt(stringVect);
57 return Array.from(elements);
58}
59
60export function stringMapToRecord(stringMap: StringMap): Record<string, string> {
61 const keyValuePairs = swigMapToIt(stringMap);
62 const record: Record<string, string> = {};
63 for (const [key, value] of keyValuePairs) {
64 record[key] = value;
65 }
66 return record;
67}
68
69export function vectMapToRecordArray(vectMap: VectMap): Record<string, string>[] {
70 const stringMaps = swigVectToIt(vectMap);
71 const records = [];
72 for (const stringMap of stringMaps) {
73 const record = stringMapToRecord(stringMap);
74 records.push(record);
75 }
76 return records;
77}
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040078
Misha Krieger-Raynauld68a9b562022-10-28 19:47:46 -040079/**
80 * Non-exhaustive list of properties for JamiSwig.
81 *
82 * The full list of methods can be found in SWIG interface files (`.i`) in `daemon/bin/nodejs`.
83 */
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040084export interface JamiSwig {
85 init(args: Record<string, unknown>): void;
Misha Krieger-Raynauld62a0da92022-10-22 13:46:59 -040086 fini(): void;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -040087
idillon559ce282022-12-22 15:18:32 -050088 monitor(continuous: boolean): void;
89
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040090 getAccountDetails(accountId: string): StringMap;
91 getVolatileAccountDetails(accountId: string): StringMap;
92 setAccountDetails(accountId: string, details: StringMap): void;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -040093
94 addAccount(details: StringMap): string;
95 removeAccount(accountId: string): void;
96
97 getAccountList(): StringVect;
98
Charlieb62c6782022-10-30 15:14:56 -040099 sendAccountTextMessage(accountId: string, contactId: string, message: StringMap): void;
100
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400101 lookupName(accountId: string, nameserver: string, username: string): boolean;
102 lookupAddress(accountId: string, nameserver: string, address: string): boolean;
103 registerName(accountId: string, password: string, username: string): boolean;
104
105 getKnownRingDevices(accountId: string): StringMap;
106
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400107 addContact(accountId: string, contactId: string): void;
108 removeContact(accountId: string, contactId: string, ban: boolean): void;
109 getContacts(accountId: string): VectMap;
110 getContactDetails(accountId: string, contactId: string): StringMap;
Michelle Sepkap Simedd82cbf2022-11-17 23:31:49 -0500111 sendTrustRequest(accountId: string, to: string, payload: Blob): void;
112 acceptTrustRequest(accountId: string, from: string): boolean;
113 discardTrustRequest(accountId: string, from: string): boolean;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400114
115 getDefaultModerators(accountId: string): StringVect;
Misha Krieger-Raynauld153a1482022-11-05 12:00:41 -0400116 setDefaultModerator(accountId: string, uri: string, state: boolean): void;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400117
118 getConversations(accountId: string): StringVect;
119 conversationInfos(accountId: string, conversationId: string): StringMap;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400120 getConversationMembers(accountId: string, conversationId: string): VectMap;
Michelle Sepkap Simedd82cbf2022-11-17 23:31:49 -0500121 acceptConversationRequest(accountId: string, conversationId: string): void;
idillon07d31cc2022-12-06 22:40:14 -0500122 removeConversation(accountId: string, conversationId: string): void;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400123
Issam E. Maghni2cb239b2022-11-18 22:39:32 +0000124 sendMessage(accountId: string, conversationId: string, message: string, replyTo: string, flag: number): void;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400125 loadConversationMessages(accountId: string, conversationId: string, fromMessage: string, n: number): number;
idillon3e378fd2022-12-23 11:48:12 -0500126 setIsComposing(accountId: string, conversationId: string, isWriting: boolean): void;
Misha Krieger-Raynauldb6f1c322022-10-23 20:42:57 -0400127
Misha Krieger-Raynauld7f959332022-11-04 15:12:53 -0400128 getCallList(accountId: string): StringVect;
129 getCallDetails(accountId: string, callId: string): StringMap;
130
simon43da57b2022-10-26 18:22:22 -0400131 // IntVect: Constructable<IntVect>;
132 // UintVect: Constructable<UintVect>;
133 // FloatVect: Constructable<FloatVect>;
134 // StringVect: Constructable<StringVect>;
135 // IntegerMap: Constructable<IntegerMap>
136 StringMap: Constructable<StringMap>;
137 // VectMap: Constructable<VectMap>;
138 // IntegerMap: Constructable<IntegerMap>;
Michelle Sepkap Simedd82cbf2022-11-17 23:31:49 -0500139 Blob: Constructable<Blob>;
Misha Krieger-Raynauldaddd6fe2022-10-22 12:46:04 -0400140}