From b6123fc0f5be0b904f250e4fd6cd35e341325c20 Mon Sep 17 00:00:00 2001 From: Kevin Lee <59052025+lgz5689@users.noreply.github.com> Date: Tue, 30 Jul 2024 16:32:21 +0800 Subject: [PATCH] feat: add upload logs func (#4) --- package-lock.json | 4 ++-- package.json | 4 ++-- src/constant/callback.ts | 2 ++ src/core/index.ts | 19 ++++++++++++++++++- src/render.ts | 8 ++++++++ src/types/libOpenIMSDK.d.ts | 7 +++++++ src/types/params.ts | 6 ++++++ 7 files changed, 45 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3ea2eb4..2ed6c82 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@openim/electron-client-sdk", - "version": "1.0.0", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@openim/electron-client-sdk", - "version": "1.0.0", + "version": "1.0.2", "license": "MIT", "dependencies": { "koffi": "^2.8.0", diff --git a/package.json b/package.json index ce1c009..ceb1d5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@openim/electron-client-sdk", - "version": "1.0.5", + "version": "1.0.6", "description": "open im sdk for node", "source": "src/index.ts", "main": "lib/index.js", @@ -81,6 +81,6 @@ }, "peerDependencies": { "electron": ">=12.0.0", - "open-im-sdk-wasm": "^3.8.0-rc.6" + "open-im-sdk-wasm": "^3.8.0-rc.8" } } diff --git a/src/constant/callback.ts b/src/constant/callback.ts index 082e3f3..a4cddbe 100644 --- a/src/constant/callback.ts +++ b/src/constant/callback.ts @@ -70,6 +70,7 @@ export enum NativeEvent { ROOM_PARTICIPANT_DISCONNECTED, STREAM_CHANGE, RECEIVE_CUSTOM_SIGNAL, + ON_PROGRESS, } export const eventMapping: Record = { @@ -150,4 +151,5 @@ export const eventMapping: Record = { CbEvents.OnRoomParticipantDisconnected, [NativeEvent.STREAM_CHANGE]: CbEvents.OnStreamChange, [NativeEvent.RECEIVE_CUSTOM_SIGNAL]: CbEvents.OnReceiveCustomSignal, + [NativeEvent.ON_PROGRESS]: CbEvents.OnUploadLogsProgress, }; diff --git a/src/core/index.ts b/src/core/index.ts index 7b8d407..d7896d3 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -2,7 +2,7 @@ import koffi from 'koffi'; import { v4 as uuidV4 } from 'uuid'; import type { LibOpenIMSDK } from 'libOpenIMSDK'; import { UserModuleApi, setupUserModule } from './modules/user'; -import { InitConfig, LoginParams } from '@/types/params'; +import { InitConfig, LoginParams, UploadLogsParams } from '@/types/params'; import { BaseResponse, EmitProxy } from '@/types/entity'; import { ErrorCode } from '@/constant/api'; import { NativeEvent, eventMapping } from '@/constant/callback'; @@ -855,6 +855,12 @@ class OpenIMSDK 'void', ['baseCallback *', 'str', 'str', 'listenerCallback *'] ); + this.libOpenIMSDK.upload_logs = this.lib.func( + '__stdcall', + 'upload_logs', + 'void', + ['baseCallback *', 'str', 'int', 'str', 'listenerCallback *'] + ); // advance if (this.enterprise) { @@ -1222,6 +1228,17 @@ class OpenIMSDK ); }); + uploadLogs = (params: UploadLogsParams, opid = uuidV4()) => + new Promise>((resolve, reject) => { + this.libOpenIMSDK.upload_logs( + this.baseCallbackWrap(resolve, reject), + opid, + params.line, + params.ex || '', + this.listenerCallback + ); + }); + // implements user api getSelfUserInfo!: UserModuleApi['getSelfUserInfo']; setSelfInfo!: UserModuleApi['setSelfInfo']; diff --git a/src/render.ts b/src/render.ts index ea82b1d..7cdee05 100644 --- a/src/render.ts +++ b/src/render.ts @@ -10,6 +10,7 @@ import { FileMsgByPathParams, SoundMsgByPathParams, VideoMsgByPathParams, + UploadLogsParams, } from './types/params'; type EmitterEvents = { @@ -83,6 +84,13 @@ type IMSDKInterface = Omit & { params: FileMsgByPathParams, opid?: string ) => Promise>; + /** + * @access only for electron + */ + uploadLogs: ( + params: UploadLogsParams, + opid?: string + ) => Promise>; }; type ElectronInvoke = (method: string, ...args: any[]) => Promise; diff --git a/src/types/libOpenIMSDK.d.ts b/src/types/libOpenIMSDK.d.ts index e857de8..d98de07 100644 --- a/src/types/libOpenIMSDK.d.ts +++ b/src/types/libOpenIMSDK.d.ts @@ -745,6 +745,13 @@ declare module 'libOpenIMSDK' { cFileInfo: string, pCallback: CB_I_S ): void; + upload_logs( + cCallback: CB_S_I_S_S, + operationID: string, + line: number, + ex: string, + pCallback: CB_I_S + ): void; } const lib: LibOpenIMSDK; export default lib; diff --git a/src/types/params.ts b/src/types/params.ts index bd3f4bd..a3d8efd 100644 --- a/src/types/params.ts +++ b/src/types/params.ts @@ -8,6 +8,7 @@ export interface InitConfig { logFilePath?: string; isLogStandardOutput?: boolean; isExternalExtensions?: boolean; + systemType: string; } export interface LoginParams { @@ -31,3 +32,8 @@ export type FileMsgByPathParams = { filePath: string; fileName: string; }; + +export type UploadLogsParams = { + line: number; + ex?: string; +};