2024-03-29 19:05:50 +00:00
|
|
|
import TorModule from '../../native/TorModule';
|
2022-09-28 12:08:16 +00:00
|
|
|
|
|
|
|
class TorClient {
|
2022-11-07 16:45:05 +00:00
|
|
|
public get: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
|
|
|
baseUrl,
|
|
|
|
path,
|
|
|
|
headers,
|
|
|
|
) => {
|
2024-10-19 13:33:55 +00:00
|
|
|
return await new Promise<object>((resolve, reject) => {
|
2022-09-28 12:08:16 +00:00
|
|
|
try {
|
2024-10-19 13:33:55 +00:00
|
|
|
TorModule.sendRequest('GET', `${baseUrl}${path}`, JSON.stringify(headers), '{}').then(
|
|
|
|
(response) => {
|
|
|
|
resolve(JSON.parse(response));
|
|
|
|
},
|
2024-03-28 21:42:32 +00:00
|
|
|
);
|
2022-09-28 12:08:16 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public delete: (baseUrl: string, path: string, headers: object) => Promise<object> = async (
|
|
|
|
baseUrl,
|
|
|
|
path,
|
|
|
|
headers,
|
|
|
|
) => {
|
2024-10-19 13:33:55 +00:00
|
|
|
return await new Promise<object>((resolve, reject) => {
|
2022-09-28 12:08:16 +00:00
|
|
|
try {
|
2024-10-19 13:33:55 +00:00
|
|
|
TorModule.sendRequest('DELETE', `${baseUrl}${path}`, JSON.stringify(headers), '{}').then(
|
|
|
|
(response) => {
|
|
|
|
resolve(JSON.parse(response));
|
|
|
|
},
|
2024-03-28 21:42:32 +00:00
|
|
|
);
|
2022-09-28 12:08:16 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-11-07 16:45:05 +00:00
|
|
|
public post: (baseUrl: string, path: string, body: object, headers: object) => Promise<object> =
|
|
|
|
async (baseUrl, path, body, headers) => {
|
2024-10-19 13:33:55 +00:00
|
|
|
return await new Promise<object>((resolve, reject) => {
|
2022-11-07 16:45:05 +00:00
|
|
|
try {
|
|
|
|
const json = JSON.stringify(body);
|
2024-10-19 13:33:55 +00:00
|
|
|
TorModule.sendRequest('POST', `${baseUrl}${path}`, JSON.stringify(headers), json).then(
|
|
|
|
(response) => {
|
|
|
|
resolve(JSON.parse(response));
|
|
|
|
},
|
2024-03-28 21:42:32 +00:00
|
|
|
);
|
2022-11-07 16:45:05 +00:00
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2024-11-24 08:16:50 +00:00
|
|
|
|
|
|
|
public wsOpen: (path: string) => Promise<boolean> = async (path) => {
|
|
|
|
return await new Promise<boolean>((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
TorModule.sendWsOpen(path).then((response) => {
|
|
|
|
resolve(response);
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
public wsClose: (path: string) => Promise<boolean> = async (path) => {
|
|
|
|
return await new Promise<boolean>((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
TorModule.sendWsClose(path).then((response) => {
|
|
|
|
resolve(response);
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
public wsSend: (path: string, message: string) => Promise<boolean> = async (path, message) => {
|
|
|
|
return await new Promise<boolean>((resolve, reject) => {
|
|
|
|
try {
|
|
|
|
TorModule.sendWsSend(path, message).then((response) => {
|
|
|
|
resolve(response);
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
reject(error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2022-09-28 12:08:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default TorClient;
|