39 lines
888 B
TypeScript
39 lines
888 B
TypeScript
import OpenIMSDK, { MessageItem } from "@openim/rn-client-sdk";
|
|
import RNFS from "react-native-fs";
|
|
|
|
const OPENIM_DIR = `${RNFS.DocumentDirectoryPath}/openim`;
|
|
|
|
let initialized = false;
|
|
let ensureDirPromise: Promise<void> | null = null;
|
|
|
|
function ensureOpenIMDir() {
|
|
if (!ensureDirPromise) {
|
|
ensureDirPromise = RNFS.mkdir(OPENIM_DIR).then(() => undefined);
|
|
}
|
|
|
|
return ensureDirPromise;
|
|
}
|
|
|
|
export async function bootstrapOpenIM() {
|
|
if (initialized) {
|
|
return;
|
|
}
|
|
|
|
await ensureOpenIMDir();
|
|
|
|
OpenIMSDK.initSDK({
|
|
apiAddr: "https://openim-api.riwsan.com/api",
|
|
wsAddr: "wss://openim-api.riwsan.com/msg_gateway",
|
|
dataDir: OPENIM_DIR,
|
|
logFilePath: OPENIM_DIR,
|
|
logLevel: 5,
|
|
isLogStandardOutput: true,
|
|
});
|
|
|
|
OpenIMSDK.on("onRecvNewMessages", (messages: MessageItem[]) => {
|
|
console.log("onRecvNewMessages", messages);
|
|
});
|
|
|
|
initialized = true;
|
|
}
|