diff --git a/assets/libopenimsdk.dylib b/assets/mac_arm64/libopenimsdk.dylib similarity index 100% rename from assets/libopenimsdk.dylib rename to assets/mac_arm64/libopenimsdk.dylib diff --git a/assets/libopenimsdk.dll b/assets/win_x64/libopenimsdk.dll old mode 100755 new mode 100644 similarity index 62% rename from assets/libopenimsdk.dll rename to assets/win_x64/libopenimsdk.dll index 54b661b..67f6ef0 Binary files a/assets/libopenimsdk.dll and b/assets/win_x64/libopenimsdk.dll differ diff --git a/package-lock.json b/package-lock.json index 29c69b6..2e90362 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { - "name": "open-im-sdk-node", - "version": "1.0.0", + "name": "@openim/node-client-sdk", + "version": "1.0.6", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "open-im-sdk-node", - "version": "1.0.0", + "name": "@openim/node-client-sdk", + "version": "1.0.6", "license": "MIT", "dependencies": { - "@openim/ffi-napi": "^4.0.14", + "koffi": "^2.8.0", "uuid": "^9.0.0" }, "devDependencies": { @@ -30,6 +30,7 @@ "husky": "^6.0.0", "jest": "^27.2.0", "lint-staged": "^10.5.4", + "open-im-sdk-wasm": "^3.5.3-alpha.2", "prettier": "^2.2.1", "rollup": "^2.79.1", "rollup-plugin-typescript2": "^0.36.0", @@ -39,6 +40,9 @@ }, "engines": { "node": ">=12.0" + }, + "peerDependencies": { + "open-im-sdk-wasm": "^3.5.3-alpha.1" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -1813,38 +1817,6 @@ "@octokit/openapi-types": "^18.0.0" } }, - "node_modules/@openim/ffi-napi": { - "version": "4.0.14", - "resolved": "https://registry.npmjs.org/@openim/ffi-napi/-/ffi-napi-4.0.14.tgz", - "integrity": "sha512-LuKBOFDuV+OKnZr33zaZGKvDgNiozGVg39S++HzywyULBn8vcigW6MGZEYhkx9P5GquAu+Kh+Bkvb2FFY6XRgA==", - "hasInstallScript": true, - "dependencies": { - "@openim/ref-napi": "^4.0.11", - "debug": "^4.1.1", - "get-uv-event-loop-napi-h": "^1.0.5", - "node-addon-api": "^3.2.1", - "node-gyp-build": "^4.5.0", - "ref-struct-di": "^1.1.0" - }, - "engines": { - "node": ">=12.22.12" - } - }, - "node_modules/@openim/ref-napi": { - "version": "4.0.11", - "resolved": "https://registry.npmjs.org/@openim/ref-napi/-/ref-napi-4.0.11.tgz", - "integrity": "sha512-Rz/7M5et4AXBwoTB1Wsm6fNZPlgSs3UB8fxBv3KNZ30W2DYio4NRS3z0rcZgigMuyp/LDGZQjJvhyXCl6QSROg==", - "hasInstallScript": true, - "dependencies": { - "debug": "^4.3.4", - "get-symbol-from-current-process-h": "^1.0.2", - "node-addon-api": "^3.2.1", - "node-gyp-build": "^4.5.0" - }, - "engines": { - "node": ">= 12.22.12" - } - }, "node_modules/@pnpm/config.env-replace": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@pnpm/config.env-replace/-/config.env-replace-1.1.0.tgz", @@ -3451,6 +3423,7 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -4537,19 +4510,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-symbol-from-current-process-h": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/get-symbol-from-current-process-h/-/get-symbol-from-current-process-h-1.0.2.tgz", - "integrity": "sha512-syloC6fsCt62ELLrr1VKBM1ggOpMdetX9hTrdW77UQdcApPHLmf7CI7OKcN1c9kYuNxKcDe4iJ4FY9sX3aw2xw==" - }, - "node_modules/get-uv-event-loop-napi-h": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/get-uv-event-loop-napi-h/-/get-uv-event-loop-napi-h-1.0.6.tgz", - "integrity": "sha512-t5c9VNR84nRoF+eLiz6wFrEp1SE2Acg0wS+Ysa2zF0eROes+LzOfuTaVHxGy8AbS8rq7FHEJzjnCZo1BupwdJg==", - "dependencies": { - "get-symbol-from-current-process-h": "^1.0.1" - } - }, "node_modules/git-log-parser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/git-log-parser/-/git-log-parser-1.2.0.tgz", @@ -6249,6 +6209,12 @@ "node": ">=6" } }, + "node_modules/koffi": { + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/koffi/-/koffi-2.8.0.tgz", + "integrity": "sha512-EXhiH9Ya4f+o4+24+uV4vFAMyPEskARVUaY8VHbIYWqkQVPTDyYJCBNfxp0Kxw6WdhaMwXeR8xIUyz8R2H8Rew==", + "hasInstallScript": true + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -6869,7 +6835,8 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true }, "node_modules/mylas": { "version": "2.1.13", @@ -6902,11 +6869,6 @@ "integrity": "sha512-EZSPZB70jiVsivaBLYDCyntd5eH8NTSMOn3rB+HxwdmKThGELLdYv8qVIMWvZEFy9w8ZZpW9h9OB32l1rGtj7g==", "dev": true }, - "node_modules/node-addon-api": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", - "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==" - }, "node_modules/node-emoji": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.11.0.tgz", @@ -6958,16 +6920,6 @@ "webidl-conversions": "^3.0.0" } }, - "node_modules/node-gyp-build": { - "version": "4.7.1", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.7.1.tgz", - "integrity": "sha512-wTSrZ+8lsRRa3I3H8Xr65dLWSgCvY2l4AOnaeKdPA9TB/WYMPaTcrzf3rXvFoVvjKNVnu0CcWSx54qq9GKRUYg==", - "bin": { - "node-gyp-build": "bin.js", - "node-gyp-build-optional": "optional.js", - "node-gyp-build-test": "build-test.js" - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -9624,6 +9576,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/open-im-sdk-wasm": { + "version": "3.5.3-alpha.2", + "resolved": "https://registry.npmjs.org/open-im-sdk-wasm/-/open-im-sdk-wasm-3.5.3-alpha.2.tgz", + "integrity": "sha512-UEDq0rjMB7nFjYKFgkPaLaOlj41jjXbVTSZpIdiewlxzWTuXJmGBRyXhJyK8YFbCjpgndVxl882t62KIUsIU1w==", + "dev": true, + "engines": { + "node": ">=12.0" + } + }, "node_modules/optionator": { "version": "0.9.3", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", @@ -10417,22 +10378,6 @@ "esprima": "~4.0.0" } }, - "node_modules/ref-struct-di": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ref-struct-di/-/ref-struct-di-1.1.1.tgz", - "integrity": "sha512-2Xyn/0Qgz89VT+++WP0sTosdm9oeowLP23wRJYhG4BFdMUrLj3jhwHZNEytYNYgtPKLNTP3KJX4HEgBvM1/Y2g==", - "dependencies": { - "debug": "^3.1.0" - } - }, - "node_modules/ref-struct-di/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dependencies": { - "ms": "^2.1.1" - } - }, "node_modules/regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", diff --git a/package.json b/package.json index f37916f..d205fbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "open-im-sdk-node", - "version": "1.0.0", + "name": "@openim/node-client-sdk", + "version": "1.0.6", "description": "open im sdk for node", "source": "src/index.ts", "main": "lib/index.js", @@ -58,6 +58,7 @@ "husky": "^6.0.0", "jest": "^27.2.0", "lint-staged": "^10.5.4", + "open-im-sdk-wasm": "^3.5.3-alpha.2", "prettier": "^2.2.1", "rollup": "^2.79.1", "rollup-plugin-typescript2": "^0.36.0", @@ -74,7 +75,10 @@ "*.ts": "eslint --cache --cache-location .eslintcache --fix" }, "dependencies": { - "@openim/ffi-napi": "^4.0.14", + "koffi": "^2.8.0", "uuid": "^9.0.0" + }, + "peerDependencies": { + "open-im-sdk-wasm": "^3.5.3-alpha.1" } } diff --git a/rollup.config.js b/rollup.config.js index fa0f4fb..c347d98 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -21,5 +21,24 @@ export default [ alias(), typescript(), ] + }, + { + input: 'src/render.ts', + output: [ + { + file: 'lib/render.js', + format: 'cjs', + exports: 'auto', + sourcemap: false + }, + { + file: 'lib/render.es.js', + format: 'esm', + sourcemap: false + } + ], + plugins: [ + typescript(), + ] } ]; diff --git a/src/constant/callback.ts b/src/constant/callback.ts index e570038..8c04685 100644 --- a/src/constant/callback.ts +++ b/src/constant/callback.ts @@ -1,3 +1,4 @@ +import { CbEvents } from 'open-im-sdk-wasm'; export enum NativeEvent { CONNECTING, CONNECT_SUCCESS, @@ -56,69 +57,6 @@ export enum NativeEvent { UPLOAD_FILE_CALLBACK_COMPLETE, } -export enum CbEvents { - OnConnectFailed = 'OnConnectFailed', - OnConnectSuccess = 'OnConnectSuccess', - OnConnecting = 'OnConnecting', - OnKickedOffline = 'OnKickedOffline', - OnSelfInfoUpdated = 'OnSelfInfoUpdated', - OnUserTokenExpired = 'OnUserTokenExpired', - OnProgress = 'OnProgress', - OnRecvNewMessage = 'OnRecvNewMessage', - OnRecvNewMessages = 'OnRecvNewMessages', - OnRecvMessageRevoked = 'OnRecvMessageRevoked', - OnNewRecvMessageRevoked = 'OnNewRecvMessageRevoked', - OnRecvC2CReadReceipt = 'OnRecvC2CReadReceipt', - OnRecvGroupReadReceipt = 'OnRecvGroupReadReceipt', - OnConversationChanged = 'OnConversationChanged', - OnNewConversation = 'OnNewConversation', - OnSyncServerFailed = 'OnSyncServerFailed', - OnSyncServerFinish = 'OnSyncServerFinish', - OnSyncServerStart = 'OnSyncServerStart', - OnTotalUnreadMessageCountChanged = 'OnTotalUnreadMessageCountChanged', - OnBlackAdded = 'OnBlackAdded', - OnBlackDeleted = 'OnBlackDeleted', - OnFriendApplicationAccepted = 'OnFriendApplicationAccepted', - OnFriendApplicationAdded = 'OnFriendApplicationAdded', - OnFriendApplicationDeleted = 'OnFriendApplicationDeleted', - OnFriendApplicationRejected = 'OnFriendApplicationRejected', - OnFriendInfoChanged = 'OnFriendInfoChanged', - OnFriendAdded = 'OnFriendAdded', - OnFriendDeleted = 'OnFriendDeleted', - OnJoinedGroupAdded = 'OnJoinedGroupAdded', - OnJoinedGroupDeleted = 'OnJoinedGroupDeleted', - OnGroupDismissed = 'OnGroupDismissed', - OnGroupMemberAdded = 'OnGroupMemberAdded', - OnGroupMemberDeleted = 'OnGroupMemberDeleted', - OnGroupApplicationAdded = 'OnGroupApplicationAdded', - OnGroupApplicationDeleted = 'OnGroupApplicationDeleted', - OnGroupInfoChanged = 'OnGroupInfoChanged', - OnGroupMemberInfoChanged = 'OnGroupMemberInfoChanged', - OnGroupApplicationAccepted = 'OnGroupApplicationAccepted', - OnGroupApplicationRejected = 'OnGroupApplicationRejected', - - UploadComplete = 'UploadComplete', - OnRecvCustomBusinessMessage = 'OnRecvCustomBusinessMessage', - OnUserStatusChanged = 'OnUserStatusChanged', - UnUsedEvent = 'UnUsedEvent', - - // rtc - OnReceiveNewInvitation = 'OnReceiveNewInvitation', - OnInviteeAccepted = 'OnInviteeAccepted', - OnInviteeRejected = 'OnInviteeRejected', - OnInvitationCancelled = 'OnInvitationCancelled', - OnHangUp = 'OnHangUp', - OnInvitationTimeout = 'OnInvitationTimeout', - OnInviteeAcceptedByOtherDevice = 'OnInviteeAcceptedByOtherDevice', - OnInviteeRejectedByOtherDevice = 'OnInviteeRejectedByOtherDevice', - - // meeting - OnStreamChange = 'OnStreamChange', - OnRoomParticipantConnected = 'OnRoomParticipantConnected', - OnRoomParticipantDisconnected = 'OnRoomParticipantDisconnected', - OnReceiveCustomSignal = 'OnReceiveCustomSignal', -} - export const eventMapping: Record = { [NativeEvent.CONNECTING]: CbEvents.OnConnecting, [NativeEvent.CONNECT_SUCCESS]: CbEvents.OnConnectSuccess, diff --git a/src/core/index.ts b/src/core/index.ts index 50729d5..e677490 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,11 +1,10 @@ -import ffi from '@openim/ffi-napi'; +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 { BaseResponse, SelfUserInfo, EmitProxy } from '@/types/entity'; +import { BaseResponse, EmitProxy } from '@/types/entity'; import { ErrorCode } from '@/constant/api'; -import { LoginStatus } from '@/types/enum'; import { NativeEvent, eventMapping } from '@/constant/callback'; import Emitter from '@/utils/emitter'; import { type FriendModuleApi, setupFriendModule } from './modules/friend'; @@ -15,6 +14,12 @@ import { setupConversationModule, } from './modules/conversation'; import { type MessageModuleApi, setupMessageModule } from './modules/message'; +import { CbEvents, LoginStatus } from 'open-im-sdk-wasm'; +import { SelfUserInfo } from 'open-im-sdk-wasm/lib/types/entity'; +import { + SetConversationExParams, + SetFriendExParams, +} from 'open-im-sdk-wasm/lib/types/params'; function isObject(value: unknown) { return Object.prototype.toString.call(value) === '[object Object]'; @@ -29,302 +34,794 @@ class OpenIMSDK ConversationModuleApi, MessageModuleApi { - libOpenIMSDK: LibOpenIMSDK; - listenerCallback: Buffer; + libOpenIMSDK = {} as LibOpenIMSDK; + baseCallbackProto: koffi.IKoffiCType; + sendMessageCallbackProto: koffi.IKoffiCType; + listenerCallback: koffi.IKoffiRegisteredCallback; + lib: koffi.IKoffiLib; constructor(libPath: string, emitProxy?: EmitProxy) { super(); - this.libOpenIMSDK = ffi.Library(libPath, { - set_group_listener: ['void', ['pointer']], - set_conversation_listener: ['void', ['pointer']], - set_advanced_msg_listener: ['void', ['pointer']], - set_batch_msg_listener: ['void', ['pointer']], - set_user_listener: ['void', ['pointer']], - set_friend_listener: ['void', ['pointer']], - set_custom_business_listener: ['void', ['pointer']], - init_sdk: ['uint8', ['pointer', 'string', 'string']], - un_init_sdk: ['void', ['string']], - login: ['void', ['pointer', 'string', 'string', 'string']], - logout: ['void', ['pointer', 'string']], - set_app_background_status: ['void', ['pointer', 'string', 'int']], - network_status_changed: ['void', ['pointer', 'string']], - get_login_status: ['int', ['string']], - get_login_user: ['string', []], - create_text_message: ['string', ['string', 'string']], - create_advanced_text_message: ['string', ['string', 'string', 'string']], - create_text_at_message: [ - 'string', - ['string', 'string', 'string', 'string', 'string'], - ], - create_location_message: [ - 'string', - ['string', 'string', 'double', 'double'], - ], - create_custom_message: [ - 'string', - ['string', 'string', 'string', 'string'], - ], - create_quote_message: ['string', ['string', 'string', 'string']], - create_advanced_quote_message: [ - 'string', - ['string', 'string', 'string', 'string'], - ], - create_card_message: ['string', ['string', 'string']], - create_video_message_from_full_path: [ - 'string', - ['string', 'string', 'string', 'long long', 'string'], - ], - create_image_message_from_full_path: ['string', ['string', 'string']], - create_sound_message_from_full_path: [ - 'string', - ['string', 'string', 'long long'], - ], - create_file_message_from_full_path: [ - 'string', - ['string', 'string', 'string'], - ], - create_image_message: ['string', ['string', 'string']], - create_image_message_by_url: [ - 'string', - ['string', 'string', 'string', 'string', 'string'], - ], - create_sound_message_by_url: ['string', ['string', 'string']], - create_sound_message: ['string', ['string', 'string', 'long long']], - create_video_message_by_url: ['string', ['string', 'string']], - create_video_message: [ - 'string', - ['string', 'string', 'string', 'long long', 'string'], - ], - create_file_message_by_url: ['string', ['string', 'string']], - create_file_message: ['string', ['string', 'string', 'string']], - create_merger_message: [ - 'string', - ['string', 'string', 'string', 'string'], - ], - create_face_message: ['string', ['string', 'int', 'string']], - create_forward_message: ['string', ['string', 'string']], - get_all_conversation_list: ['void', ['pointer', 'string']], - get_conversation_list_split: [ - 'void', - ['pointer', 'string', 'int', 'int'], - ], - get_one_conversation: ['void', ['pointer', 'string', 'int', 'string']], - get_multiple_conversation: ['void', ['pointer', 'string', 'string']], - set_conversation_msg_destruct_time: [ - 'void', - ['pointer', 'string', 'string', 'long long'], - ], - set_conversation_is_msg_destruct: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - hide_conversation: ['void', ['pointer', 'string', 'string']], - get_conversation_recv_message_opt: [ - 'void', - ['pointer', 'string', 'string'], - ], - set_conversation_draft: [ - 'void', - ['pointer', 'string', 'string', 'string'], - ], - reset_conversation_group_at_type: [ - 'void', - ['pointer', 'string', 'string'], - ], - pin_conversation: ['void', ['pointer', 'string', 'string', 'int']], - set_conversation_private_chat: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - set_conversation_burn_duration: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - set_conversation_recv_message_opt: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - get_total_unread_msg_count: ['void', ['pointer', 'string']], - get_at_all_tag: ['string', ['string']], - get_conversation_id_by_session_type: [ - 'string', - ['string', 'string', 'int'], - ], - send_message: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string', 'string'], - ], - send_message_not_oss: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string', 'string'], - ], - find_message_list: ['void', ['pointer', 'string', 'string']], - get_advanced_history_message_list: [ - 'void', - ['pointer', 'string', 'string'], - ], - get_advanced_history_message_list_reverse: [ - 'void', - ['pointer', 'string', 'string'], - ], - revoke_message: ['void', ['pointer', 'string', 'string', 'string']], - typing_status_update: ['void', ['pointer', 'string', 'string', 'string']], - mark_conversation_message_as_read: [ - 'void', - ['pointer', 'string', 'string'], - ], - delete_message_from_local_storage: [ - 'void', - ['pointer', 'string', 'string', 'string'], - ], - delete_message: ['void', ['pointer', 'string', 'string', 'string']], - hide_all_conversations: ['void', ['pointer', 'string']], - delete_all_msg_from_local_and_svr: ['void', ['pointer', 'string']], - delete_all_msg_from_local: ['void', ['pointer', 'string']], - clear_conversation_and_delete_all_msg: [ - 'void', - ['pointer', 'string', 'string'], - ], - delete_conversation_and_delete_all_msg: [ - 'void', - ['pointer', 'string', 'string'], - ], - insert_single_message_to_local_storage: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - insert_group_message_to_local_storage: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - search_local_messages: ['void', ['pointer', 'string', 'string']], - set_message_local_ex: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - get_users_info: ['void', ['pointer', 'string', 'string']], - get_users_info_with_cache: [ - 'void', - ['pointer', 'string', 'string', 'string'], - ], - get_users_info_from_srv: ['void', ['pointer', 'string', 'string']], - set_self_info: ['void', ['pointer', 'string', 'string']], - set_global_recv_message_opt: ['void', ['pointer', 'string', 'int']], - get_self_user_info: ['void', ['pointer', 'string']], - update_msg_sender_info: [ - 'void', - ['pointer', 'string', 'string', 'string'], - ], - subscribe_users_status: ['void', ['pointer', 'string', 'string']], - unsubscribe_users_status: ['void', ['pointer', 'string', 'string']], - get_subscribe_users_status: ['void', ['pointer', 'string']], - get_user_status: ['void', ['pointer', 'string', 'string']], - // Friend functions - get_specified_friends_info: ['void', ['pointer', 'string', 'string']], - get_friend_list: ['void', ['pointer', 'string']], - get_friend_list_page: ['void', ['pointer', 'string', 'int', 'int']], - search_friends: ['void', ['pointer', 'string', 'string']], - check_friend: ['void', ['pointer', 'string', 'string']], - add_friend: ['void', ['pointer', 'string', 'string']], - set_friend_remark: ['void', ['pointer', 'string', 'string']], - delete_friend: ['void', ['pointer', 'string', 'string']], - get_friend_application_list_as_recipient: ['void', ['pointer', 'string']], - get_friend_application_list_as_applicant: ['void', ['pointer', 'string']], - accept_friend_application: ['void', ['pointer', 'string', 'string']], - refuse_friend_application: ['void', ['pointer', 'string', 'string']], - add_black: ['void', ['pointer', 'string', 'string']], - get_black_list: ['void', ['pointer', 'string']], - remove_black: ['void', ['pointer', 'string', 'string']], - // Group functions - create_group: ['void', ['pointer', 'string', 'string']], - join_group: ['void', ['pointer', 'string', 'string', 'string', 'int']], - quit_group: ['void', ['pointer', 'string', 'string']], - dismiss_group: ['void', ['pointer', 'string', 'string']], - change_group_mute: ['void', ['pointer', 'string', 'string', 'int']], - change_group_member_mute: [ - 'void', - ['pointer', 'string', 'string', 'string', 'int'], - ], - set_group_member_role_level: [ - 'void', - ['pointer', 'string', 'string', 'string', 'int'], - ], - set_group_member_info: ['void', ['pointer', 'string', 'string']], - get_joined_group_list: ['void', ['pointer', 'string']], - get_specified_groups_info: ['void', ['pointer', 'string', 'string']], - search_groups: ['void', ['pointer', 'string', 'string']], - set_group_info: ['void', ['pointer', 'string', 'string']], - set_group_verification: ['void', ['pointer', 'string', 'string', 'int']], - set_group_look_member_info: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - set_group_apply_member_friend: [ - 'void', - ['pointer', 'string', 'string', 'int'], - ], - get_group_member_list: [ - 'void', - ['pointer', 'string', 'string', 'int', 'int', 'int'], - ], - get_group_member_owner_and_admin: [ - 'void', - ['pointer', 'string', 'string'], - ], - get_group_member_list_by_join_time_filter: [ - 'void', - [ - 'pointer', - 'string', - 'string', - 'int', - 'int', - 'long long', - 'long long', - 'string', - ], - ], - get_specified_group_members_info: [ - 'void', - ['pointer', 'string', 'string', 'string'], - ], - kick_group_member: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - transfer_group_owner: ['void', ['pointer', 'string', 'string', 'string']], - invite_user_to_group: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - get_group_application_list_as_recipient: ['void', ['pointer', 'string']], - get_group_application_list_as_applicant: ['void', ['pointer', 'string']], - accept_group_application: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - refuse_group_application: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - set_group_member_nickname: [ - 'void', - ['pointer', 'string', 'string', 'string', 'string'], - ], - search_group_members: ['void', ['pointer', 'string', 'string']], - is_join_group: ['void', ['pointer', 'string', 'string']], - }) as LibOpenIMSDK; - - // eslint-disable-next-line - const emitFn = emitProxy ?? this.emit; - this.listenerCallback = ffi.Callback( + this.lib = koffi.load(libPath); + this.baseCallbackProto = koffi.proto('__stdcall', 'baseCallback', 'void', [ + 'str', + 'int', + 'str', + 'str', + ]); + this.sendMessageCallbackProto = koffi.proto( + '__stdcall', + 'sendMessageCallback', 'void', - ['int', 'string'], - (event: NativeEvent, data) => { + ['str', 'int', 'str', 'str', 'int'] + ); + const listenerCallbackProto = koffi.proto( + '__stdcall', + 'listenerCallback', + 'void', + ['int', 'str'] + ); + + if (emitProxy) { + // @ts-ignore eslint-disable-next-line + this.emit = emitProxy; + } + + this.listenerCallback = koffi.register( + (event: NativeEvent, data: string) => { const cbEvent = eventMapping[event]; - emitFn(cbEvent, this.generateEventResponse(data)); + this.emit(cbEvent, this.generateEventResponse(data)); console.log(`listener callback - Event: ${cbEvent}, Data: ${data}`); - } + }, + koffi.pointer(listenerCallbackProto) + ); + + this.libOpenIMSDK.set_group_listener = this.lib.func( + '__stdcall', + 'set_group_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_conversation_listener = this.lib.func( + '__stdcall', + 'set_conversation_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_advanced_msg_listener = this.lib.func( + '__stdcall', + 'set_advanced_msg_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_batch_msg_listener = this.lib.func( + '__stdcall', + 'set_batch_msg_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_user_listener = this.lib.func( + '__stdcall', + 'set_user_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_friend_listener = this.lib.func( + '__stdcall', + 'set_friend_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.set_custom_business_listener = this.lib.func( + '__stdcall', + 'set_custom_business_listener', + 'void', + ['listenerCallback *'] + ); + this.libOpenIMSDK.init_sdk = this.lib.func( + '__stdcall', + 'init_sdk', + 'uint8', + ['listenerCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.un_init_sdk = this.lib.func( + '__stdcall', + 'un_init_sdk', + 'void', + ['str'] + ); + this.libOpenIMSDK.login = this.lib.func('__stdcall', 'login', 'void', [ + 'baseCallback *', + 'str', + 'str', + 'str', + ]); + this.libOpenIMSDK.logout = this.lib.func('__stdcall', 'logout', 'void', [ + 'baseCallback *', + 'str', + ]); + this.libOpenIMSDK.set_app_background_status = this.lib.func( + '__stdcall', + 'set_app_background_status', + 'void', + ['baseCallback *', 'str', 'int'] + ); + this.libOpenIMSDK.network_status_changed = this.lib.func( + '__stdcall', + 'network_status_changed', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_login_status = this.lib.func( + '__stdcall', + 'get_login_status', + 'int', + ['str'] + ); + this.libOpenIMSDK.get_login_user = this.lib.func( + '__stdcall', + 'get_login_user', + 'str', + [] + ); + this.libOpenIMSDK.create_text_message = this.lib.func( + '__stdcall', + 'create_text_message', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_advanced_text_message = this.lib.func( + '__stdcall', + 'create_advanced_text_message', + 'str', + ['str', 'str', 'str'] + ); + this.libOpenIMSDK.create_text_at_message = this.lib.func( + '__stdcall', + 'create_text_at_message', + 'str', + ['str', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.create_location_message = this.lib.func( + '__stdcall', + 'create_location_message', + 'str', + ['str', 'str', 'double', 'double'] + ); + this.libOpenIMSDK.create_custom_message = this.lib.func( + '__stdcall', + 'create_custom_message', + 'str', + ['str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.create_quote_message = this.lib.func( + '__stdcall', + 'create_quote_message', + 'str', + ['str', 'str', 'str'] + ); + this.libOpenIMSDK.create_advanced_quote_message = this.lib.func( + '__stdcall', + 'create_advanced_quote_message', + 'str', + ['str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.create_card_message = this.lib.func( + '__stdcall', + 'create_card_message', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_video_message_from_full_path = this.lib.func( + '__stdcall', + 'create_video_message_from_full_path', + 'str', + ['str', 'str', 'str', 'long long', 'str'] + ); + this.libOpenIMSDK.create_image_message_from_full_path = this.lib.func( + '__stdcall', + 'create_image_message_from_full_path', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_sound_message_from_full_path = this.lib.func( + '__stdcall', + 'create_sound_message_from_full_path', + 'str', + ['str', 'str', 'long long'] + ); + this.libOpenIMSDK.create_file_message_from_full_path = this.lib.func( + '__stdcall', + 'create_file_message_from_full_path', + 'str', + ['str', 'str', 'str'] + ); + this.libOpenIMSDK.create_image_message = this.lib.func( + '__stdcall', + 'create_image_message', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_image_message_by_url = this.lib.func( + '__stdcall', + 'create_image_message_by_url', + 'str', + ['str', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.create_sound_message_by_url = this.lib.func( + '__stdcall', + 'create_sound_message_by_url', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_sound_message = this.lib.func( + '__stdcall', + 'create_sound_message', + 'str', + ['str', 'str', 'long long'] + ); + this.libOpenIMSDK.create_video_message_by_url = this.lib.func( + '__stdcall', + 'create_video_message_by_url', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_video_message = this.lib.func( + '__stdcall', + 'create_video_message', + 'str', + ['str', 'str', 'str', 'long long', 'str'] + ); + this.libOpenIMSDK.create_file_message_by_url = this.lib.func( + '__stdcall', + 'create_file_message_by_url', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.create_file_message = this.lib.func( + '__stdcall', + 'create_file_message', + 'str', + ['str', 'str', 'str'] + ); + this.libOpenIMSDK.create_merger_message = this.lib.func( + '__stdcall', + 'create_merger_message', + 'str', + ['str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.create_face_message = this.lib.func( + '__stdcall', + 'create_face_message', + 'str', + ['str', 'int', 'str'] + ); + this.libOpenIMSDK.create_forward_message = this.lib.func( + '__stdcall', + 'create_forward_message', + 'str', + ['str', 'str'] + ); + this.libOpenIMSDK.get_all_conversation_list = this.lib.func( + '__stdcall', + 'get_all_conversation_list', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_conversation_list_split = this.lib.func( + '__stdcall', + 'get_conversation_list_split', + 'void', + ['baseCallback *', 'str', 'int', 'int'] + ); + this.libOpenIMSDK.get_one_conversation = this.lib.func( + '__stdcall', + 'get_one_conversation', + 'void', + ['baseCallback *', 'str', 'int', 'str'] + ); + this.libOpenIMSDK.get_multiple_conversation = this.lib.func( + '__stdcall', + 'get_multiple_conversation', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_conversation_msg_destruct_time = this.lib.func( + '__stdcall', + 'set_conversation_msg_destruct_time', + 'void', + ['baseCallback *', 'str', 'str', 'long long'] + ); + this.libOpenIMSDK.set_conversation_is_msg_destruct = this.lib.func( + '__stdcall', + 'set_conversation_is_msg_destruct', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.hide_conversation = this.lib.func( + '__stdcall', + 'hide_conversation', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_conversation_recv_message_opt = this.lib.func( + '__stdcall', + 'get_conversation_recv_message_opt', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_conversation_draft = this.lib.func( + '__stdcall', + 'set_conversation_draft', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.reset_conversation_group_at_type = this.lib.func( + '__stdcall', + 'reset_conversation_group_at_type', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.pin_conversation = this.lib.func( + '__stdcall', + 'pin_conversation', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.set_conversation_private_chat = this.lib.func( + '__stdcall', + 'set_conversation_private_chat', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.set_conversation_burn_duration = this.lib.func( + '__stdcall', + 'set_conversation_burn_duration', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.set_conversation_recv_message_opt = this.lib.func( + '__stdcall', + 'set_conversation_recv_message_opt', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.get_total_unread_msg_count = this.lib.func( + '__stdcall', + 'get_total_unread_msg_count', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_at_all_tag = this.lib.func( + '__stdcall', + 'get_at_all_tag', + 'str', + ['str'] + ); + this.libOpenIMSDK.get_conversation_id_by_session_type = this.lib.func( + '__stdcall', + 'get_conversation_id_by_session_type', + 'str', + ['str', 'str', 'int'] + ); + this.libOpenIMSDK.send_message = this.lib.func( + '__stdcall', + 'send_message', + 'void', + ['sendMessageCallback *', 'str', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.send_message_not_oss = this.lib.func( + '__stdcall', + 'send_message_not_oss', + 'void', + ['sendMessageCallback *', 'str', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.find_message_list = this.lib.func( + '__stdcall', + 'find_message_list', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_advanced_history_message_list = this.lib.func( + '__stdcall', + 'get_advanced_history_message_list', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_advanced_history_message_list_reverse = this.lib.func( + '__stdcall', + 'get_advanced_history_message_list_reverse', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.revoke_message = this.lib.func( + '__stdcall', + 'revoke_message', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.typing_status_update = this.lib.func( + '__stdcall', + 'typing_status_update', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.mark_conversation_message_as_read = this.lib.func( + '__stdcall', + 'mark_conversation_message_as_read', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.delete_message_from_local_storage = this.lib.func( + '__stdcall', + 'delete_message_from_local_storage', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.delete_message = this.lib.func( + '__stdcall', + 'delete_message', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.hide_all_conversations = this.lib.func( + '__stdcall', + 'hide_all_conversations', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.delete_all_msg_from_local_and_svr = this.lib.func( + '__stdcall', + 'delete_all_msg_from_local_and_svr', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.delete_all_msg_from_local = this.lib.func( + '__stdcall', + 'delete_all_msg_from_local', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.clear_conversation_and_delete_all_msg = this.lib.func( + '__stdcall', + 'clear_conversation_and_delete_all_msg', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.delete_conversation_and_delete_all_msg = this.lib.func( + '__stdcall', + 'delete_conversation_and_delete_all_msg', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.insert_single_message_to_local_storage = this.lib.func( + '__stdcall', + 'insert_single_message_to_local_storage', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.insert_group_message_to_local_storage = this.lib.func( + '__stdcall', + 'insert_group_message_to_local_storage', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.search_local_messages = this.lib.func( + '__stdcall', + 'search_local_messages', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_message_local_ex = this.lib.func( + '__stdcall', + 'set_message_local_ex', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.get_users_info = this.lib.func( + '__stdcall', + 'get_users_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_users_info_with_cache = this.lib.func( + '__stdcall', + 'get_users_info_with_cache', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.set_self_info = this.lib.func( + '__stdcall', + 'set_self_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_global_recv_message_opt = this.lib.func( + '__stdcall', + 'set_global_recv_message_opt', + 'void', + ['baseCallback *', 'str', 'int'] + ); + this.libOpenIMSDK.get_self_user_info = this.lib.func( + '__stdcall', + 'get_self_user_info', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.subscribe_users_status = this.lib.func( + '__stdcall', + 'subscribe_users_status', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.unsubscribe_users_status = this.lib.func( + '__stdcall', + 'unsubscribe_users_status', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_subscribe_users_status = this.lib.func( + '__stdcall', + 'get_subscribe_users_status', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_user_status = this.lib.func( + '__stdcall', + 'get_user_status', + 'void', + ['baseCallback *', 'str', 'str'] + ); + // Friend functions + this.libOpenIMSDK.get_specified_friends_info = this.lib.func( + '__stdcall', + 'get_specified_friends_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_friend_list = this.lib.func( + '__stdcall', + 'get_friend_list', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_friend_list_page = this.lib.func( + '__stdcall', + 'get_friend_list_page', + 'void', + ['baseCallback *', 'str', 'int', 'int'] + ); + this.libOpenIMSDK.search_friends = this.lib.func( + '__stdcall', + 'search_friends', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.check_friend = this.lib.func( + '__stdcall', + 'check_friend', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.add_friend = this.lib.func( + '__stdcall', + 'add_friend', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_friend_remark = this.lib.func( + '__stdcall', + 'set_friend_remark', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.delete_friend = this.lib.func( + '__stdcall', + 'delete_friend', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_friend_application_list_as_recipient = this.lib.func( + '__stdcall', + 'get_friend_application_list_as_recipient', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_friend_application_list_as_applicant = this.lib.func( + '__stdcall', + 'get_friend_application_list_as_applicant', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.accept_friend_application = this.lib.func( + '__stdcall', + 'accept_friend_application', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.refuse_friend_application = this.lib.func( + '__stdcall', + 'refuse_friend_application', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.add_black = this.lib.func( + '__stdcall', + 'add_black', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_black_list = this.lib.func( + '__stdcall', + 'get_black_list', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.remove_black = this.lib.func( + '__stdcall', + 'remove_black', + 'void', + ['baseCallback *', 'str', 'str'] + ); + // Group functions + this.libOpenIMSDK.create_group = this.lib.func( + '__stdcall', + 'create_group', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.join_group = this.lib.func( + '__stdcall', + 'join_group', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.quit_group = this.lib.func( + '__stdcall', + 'quit_group', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.dismiss_group = this.lib.func( + '__stdcall', + 'dismiss_group', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.change_group_mute = this.lib.func( + '__stdcall', + 'change_group_mute', + 'void', + ['baseCallback *', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.change_group_member_mute = this.lib.func( + '__stdcall', + 'change_group_member_mute', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.set_group_member_role_level = this.lib.func( + '__stdcall', + 'set_group_member_role_level', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'int'] + ); + this.libOpenIMSDK.set_group_member_info = this.lib.func( + '__stdcall', + 'set_group_member_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_joined_group_list = this.lib.func( + '__stdcall', + 'get_joined_group_list', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_specified_groups_info = this.lib.func( + '__stdcall', + 'get_specified_groups_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.search_groups = this.lib.func( + '__stdcall', + 'search_groups', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.set_group_info = this.lib.func( + '__stdcall', + 'set_group_info', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_group_member_list = this.lib.func( + '__stdcall', + 'get_group_member_list', + 'void', + ['baseCallback *', 'str', 'str', 'int', 'int', 'int'] + ); + this.libOpenIMSDK.get_group_member_owner_and_admin = this.lib.func( + '__stdcall', + 'get_group_member_owner_and_admin', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.get_group_member_list_by_join_time_filter = this.lib.func( + '__stdcall', + 'get_group_member_list_by_join_time_filter', + 'void', + [ + 'baseCallback *', + 'str', + 'str', + 'int', + 'int', + 'long long', + 'long long', + 'str', + ] + ); + this.libOpenIMSDK.get_specified_group_members_info = this.lib.func( + '__stdcall', + 'get_specified_group_members_info', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.kick_group_member = this.lib.func( + '__stdcall', + 'kick_group_member', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.transfer_group_owner = this.lib.func( + '__stdcall', + 'transfer_group_owner', + 'void', + ['baseCallback *', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.invite_user_to_group = this.lib.func( + '__stdcall', + 'invite_user_to_group', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.get_group_application_list_as_recipient = this.lib.func( + '__stdcall', + 'get_group_application_list_as_recipient', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.get_group_application_list_as_applicant = this.lib.func( + '__stdcall', + 'get_group_application_list_as_applicant', + 'void', + ['baseCallback *', 'str'] + ); + this.libOpenIMSDK.accept_group_application = this.lib.func( + '__stdcall', + 'accept_group_application', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.refuse_group_application = this.lib.func( + '__stdcall', + 'refuse_group_application', + 'void', + ['baseCallback *', 'str', 'str', 'str', 'str'] + ); + this.libOpenIMSDK.search_group_members = this.lib.func( + '__stdcall', + 'search_group_members', + 'void', + ['baseCallback *', 'str', 'str'] + ); + this.libOpenIMSDK.is_join_group = this.lib.func( + '__stdcall', + 'is_join_group', + 'int', + ['baseCallback *', 'str', 'str'] ); Object.assign(this, setupUserModule(this)); @@ -334,7 +831,7 @@ class OpenIMSDK Object.assign(this, setupMessageModule(this)); } - generateEventResponse = (data: unknown): BaseResponse => { + generateEventResponse = (data: unknown, operationID = ''): BaseResponse => { let errCode = 0; let errMsg = ''; try { @@ -355,18 +852,20 @@ class OpenIMSDK errCode, errMsg, data, - operationID: '', + operationID, }; }; baseCallbackWrap = ( resolve: (response: BaseResponse) => void, reject: (response: BaseResponse) => void - ) => - ffi.Callback( - 'void', - ['string', 'int', 'string', 'string'], - (operationID, errCode: number, errMsg, data) => { + ) => { + const registerBaseCallback = koffi.register( + (operationID: string, errCode: number, errMsg: string, data: string) => { + console.log( + `base callback - operationID: ${operationID}, errCode: ${errCode}, errMsg: ${errMsg}, data: ${data}` + ); + let realData; try { realData = JSON.parse(data); @@ -384,8 +883,60 @@ class OpenIMSDK } else { reject(response); } - } + koffi.unregister(registerBaseCallback); + }, + koffi.pointer(this.baseCallbackProto) ); + return registerBaseCallback; + }; + + sendMessageCallbackWrap = ( + resolve: (response: BaseResponse) => void, + reject: (response: BaseResponse) => void + ) => { + const registerSendMessageCallback = koffi.register( + ( + operationID: string, + errCode: number, + errMsg: string, + data: string, + progress: number + ) => { + console.log( + `send message callback - operationID: ${operationID}, errCode: ${errCode}, errMsg: ${errMsg}, data: ${data}, progress: ${progress}` + ); + + let realData; + try { + realData = JSON.parse(data); + } catch (error) { + realData = data; + } + const response: BaseResponse = { + errCode, + errMsg, + data: realData, + operationID, + }; + if (!errCode && !errMsg && !data) { + // eslint-disable-next-line + this.emit( + CbEvents.OnProgress, + this.generateEventResponse(progress, operationID) + ); + return; + } + if (errCode === 0) { + resolve(response); + } else { + reject(response); + } + koffi.unregister(registerSendMessageCallback); + }, + koffi.pointer(this.sendMessageCallbackProto) + ); + return registerSendMessageCallback; + }; asyncRetunWrap = (operationID: string, data: unknown) => new Promise>((resolve, reject) => { @@ -495,6 +1046,10 @@ class OpenIMSDK checkFriend!: FriendModuleApi['checkFriend']; deleteFriend!: FriendModuleApi['deleteFriend']; getBlackList!: FriendModuleApi['getBlackList']; + setFriendsEx!: ( + params: SetFriendExParams, + opid?: string | undefined + ) => Promise>; getFriendApplicationListAsApplicant!: FriendModuleApi['getFriendApplicationListAsApplicant']; getFriendApplicationListAsRecipient!: FriendModuleApi['getFriendApplicationListAsRecipient']; getFriendList!: FriendModuleApi['getFriendList']; @@ -533,6 +1088,10 @@ class OpenIMSDK getAllConversationList!: ConversationModuleApi['getAllConversationList']; getConversationListSplit!: ConversationModuleApi['getConversationListSplit']; getOneConversation!: ConversationModuleApi['getOneConversation']; + setConversationEx!: ( + params: SetConversationExParams, + opid?: string | undefined + ) => Promise>; getMultipleConversation!: ConversationModuleApi['getMultipleConversation']; getConversationIDBySessionType!: ConversationModuleApi['getConversationIDBySessionType']; getTotalUnreadMsgCount!: ConversationModuleApi['getTotalUnreadMsgCount']; diff --git a/src/core/modules/conversation.ts b/src/core/modules/conversation.ts index ccedf58..0428f99 100644 --- a/src/core/modules/conversation.ts +++ b/src/core/modules/conversation.ts @@ -1,15 +1,17 @@ import { v4 as uuidV4 } from 'uuid'; -import { BaseResponse, ConversationItem } from '@/types/entity'; +import { BaseResponse } from '@/types/entity'; import OpenIMSDK from '..'; import { SplitConversationParams, GetOneConversationParams, SetConversationDraftParams, - PinConversationParams, + SetConversationPinParams, SetConversationRecvOptParams, - SetConversationPrivateParams, + SetConversationPrivateStateParams, SetBurnDurationParams, -} from '@/types/params'; + SetConversationExParams, +} from 'open-im-sdk-wasm/lib/types/params'; +import { ConversationItem } from 'open-im-sdk-wasm/lib/types/entity'; export function setupConversationModule(openIMSDK: OpenIMSDK) { return { @@ -41,6 +43,15 @@ export function setupConversationModule(openIMSDK: OpenIMSDK) { params.sourceID ); }), + setConversationEx: (params: SetConversationExParams, opid = uuidV4()) => + new Promise>((resolve, reject) => { + openIMSDK.libOpenIMSDK.set_conversation_ex( + openIMSDK.baseCallbackWrap(resolve, reject), + opid, + params.conversationID, + params.ex + ); + }), getMultipleConversation: (conversationIDList: string, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.get_multiple_conversation( @@ -88,7 +99,7 @@ export function setupConversationModule(openIMSDK: OpenIMSDK) { params.draftText ); }), - pinConversation: (params: PinConversationParams, opid = uuidV4()) => + pinConversation: (params: SetConversationPinParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.pin_conversation( openIMSDK.baseCallbackWrap(resolve, reject), @@ -110,7 +121,7 @@ export function setupConversationModule(openIMSDK: OpenIMSDK) { ); }), setConversationPrivateChat: ( - params: SetConversationPrivateParams, + params: SetConversationPrivateStateParams, opid = uuidV4() ) => new Promise>((resolve, reject) => { @@ -193,6 +204,10 @@ export interface ConversationModuleApi { params: GetOneConversationParams, opid?: string ) => Promise>; + setConversationEx: ( + params: SetConversationExParams, + opid?: string + ) => Promise>; getMultipleConversation: ( conversationIDList: string, opid?: string @@ -207,11 +222,11 @@ export interface ConversationModuleApi { opid?: string ) => Promise>; setConversationDraft: ( - params: SetConversationDraftParams, + params: SplitConversationParams, opid?: string ) => Promise>; pinConversation: ( - params: PinConversationParams, + params: SplitConversationParams, opid?: string ) => Promise>; setConversationRecvMessageOpt: ( @@ -219,7 +234,7 @@ export interface ConversationModuleApi { opid?: string ) => Promise>; setConversationPrivateChat: ( - params: SetConversationPrivateParams, + params: SetConversationPrivateStateParams, opid?: string ) => Promise>; setConversationBurnDuration: ( diff --git a/src/core/modules/friend.ts b/src/core/modules/friend.ts index 2e13075..a3ab0ab 100644 --- a/src/core/modules/friend.ts +++ b/src/core/modules/friend.ts @@ -1,24 +1,29 @@ import { v4 as uuidV4 } from 'uuid'; import OpenIMSDK from '..'; -import { - AccessFriendParams, - SearchFriendParams, - RemarkFriendParams, - AddFriendParams, -} from '@/types/params'; +import { BaseResponse } from '@/types/entity'; import { - BaseResponse, + AccessFriendApplicationParams, + AddBlackParams, + AddFriendParams, + RemarkFriendParams, + SearchFriendParams, + SetFriendExParams, +} from 'open-im-sdk-wasm/lib/types/params'; +import { + FriendshipInfo, BlackUserItem, FriendApplicationItem, - FriendshipInfo, FullUserItem, SearchedFriendsInfo, -} from '@/types/entity'; +} from 'open-im-sdk-wasm/lib/types/entity'; export function setupFriendModule(openIMSDK: OpenIMSDK) { return { - acceptFriendApplication: (params: AccessFriendParams, opid = uuidV4()) => + acceptFriendApplication: ( + params: AccessFriendApplicationParams, + opid = uuidV4() + ) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.accept_friend_application( openIMSDK.baseCallbackWrap(resolve, reject), @@ -27,12 +32,13 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) { ); }), - addBlack: (userID: string, opid = uuidV4()) => + addBlack: (params: AddBlackParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.add_black( openIMSDK.baseCallbackWrap(resolve, reject), opid, - userID + params.toUserID, + params.ex ?? '' ); }), @@ -63,6 +69,16 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) { ); }), + setFriendsEx: (params: SetFriendExParams, opid = uuidV4()) => + new Promise>((resolve, reject) => { + openIMSDK.libOpenIMSDK.set_friends_ex( + openIMSDK.baseCallbackWrap(resolve, reject), + opid, + JSON.stringify(params), + params.ex ?? '' + ); + }), + getBlackList: (opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.get_black_list( @@ -104,7 +120,10 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) { ); }), - refuseFriendApplication: (params: AccessFriendParams, opid = uuidV4()) => + refuseFriendApplication: ( + params: AccessFriendApplicationParams, + opid = uuidV4() + ) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.refuse_friend_application( openIMSDK.baseCallbackWrap(resolve, reject), @@ -144,7 +163,7 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) { export interface FriendModuleApi { acceptFriendApplication: ( - params: AccessFriendParams, + params: AccessFriendApplicationParams, opid?: string ) => Promise>; addBlack: (userID: string, opid?: string) => Promise>; @@ -154,6 +173,10 @@ export interface FriendModuleApi { opid?: string ) => Promise>; deleteFriend: (userID: string, opid?: string) => Promise>; + setFriendsEx: ( + params: SetFriendExParams, + opid?: string + ) => Promise>; getBlackList: (opid?: string) => Promise>; getFriendApplicationListAsApplicant: ( opid?: string @@ -167,7 +190,7 @@ export interface FriendModuleApi { opid?: string ) => Promise>; refuseFriendApplication: ( - params: AccessFriendParams, + params: AccessFriendApplicationParams, opid?: string ) => Promise>; removeBlack: (userID: string, opid?: string) => Promise>; diff --git a/src/core/modules/group.ts b/src/core/modules/group.ts index 6bf3160..edbae5a 100644 --- a/src/core/modules/group.ts +++ b/src/core/modules/group.ts @@ -1,27 +1,25 @@ import { v4 as uuidV4 } from 'uuid'; -import { - BaseResponse, - GroupApplicationItem, - GroupItem, - GroupMemberItem, -} from '@/types/entity'; +import { BaseResponse } from '@/types/entity'; import OpenIMSDK from '..'; +import { + GroupItem, + GroupApplicationItem, + GroupMemberItem, +} from 'open-im-sdk-wasm/lib/types/entity'; import { CreateGroupParams, JoinGroupParams, - OpreateGroupParams, SearchGroupParams, - SetGroupinfoParams, - AccessGroupParams, + AccessGroupApplicationParams, GetGroupMemberParams, - getGroupMembersInfoParams, SearchGroupMemberParams, UpdateMemberInfoParams, GetGroupMemberByTimeParams, ChangeGroupMemberMuteParams, ChangeGroupMuteParams, TransferGroupParams, -} from '@/types/params'; + AccessToGroupParams, +} from 'open-im-sdk-wasm/lib/types/params'; export function setupGroupModule(openIMSDK: OpenIMSDK) { return { @@ -41,11 +39,12 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { opid, params.groupID, params.reqMsg, - params.joinSource + params.joinSource, + params.ex ?? '' ); }), - inviteUserToGroup: (params: OpreateGroupParams, opid = uuidV4()) => + inviteUserToGroup: (params: AccessToGroupParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.invite_user_to_group( openIMSDK.baseCallbackWrap(resolve, reject), @@ -82,7 +81,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { ); }), - setGroupInfo: (params: SetGroupinfoParams, opid = uuidV4()) => + setGroupInfo: (params: Partial, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.set_group_info( openIMSDK.baseCallbackWrap(resolve, reject), @@ -107,7 +106,10 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { ); }), - acceptGroupApplication: (params: AccessGroupParams, opid = uuidV4()) => + acceptGroupApplication: ( + params: AccessGroupApplicationParams, + opid = uuidV4() + ) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.accept_group_application( openIMSDK.baseCallbackWrap(resolve, reject), @@ -118,7 +120,10 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { ); }), - refuseGroupApplication: (params: AccessGroupParams, opid = uuidV4()) => + refuseGroupApplication: ( + params: AccessGroupApplicationParams, + opid = uuidV4() + ) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.refuse_group_application( openIMSDK.baseCallbackWrap(resolve, reject), @@ -142,7 +147,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { }), getSpecifiedGroupMembersInfo: ( - params: getGroupMembersInfoParams, + params: Omit, opid = uuidV4() ) => new Promise>((resolve, reject) => { @@ -198,7 +203,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) { ); }), - kickGroupMember: (params: OpreateGroupParams, opid = uuidV4()) => + kickGroupMember: (params: AccessToGroupParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.kick_group_member( openIMSDK.baseCallbackWrap(resolve, reject), @@ -273,7 +278,7 @@ export interface GroupModuleApi { opid?: string ) => Promise>; inviteUserToGroup: ( - params: OpreateGroupParams, + params: AccessToGroupParams, opid?: string ) => Promise>; getJoinedGroupList: (opid?: string) => Promise>; @@ -286,7 +291,7 @@ export interface GroupModuleApi { opid?: string ) => Promise>; setGroupInfo: ( - params: SetGroupinfoParams, + params: Partial, opid?: string ) => Promise>; getGroupApplicationListAsRecipient: ( @@ -296,11 +301,11 @@ export interface GroupModuleApi { opid?: string ) => Promise>; acceptGroupApplication: ( - params: AccessGroupParams, + params: AccessGroupApplicationParams, opid?: string ) => Promise>; refuseGroupApplication: ( - params: AccessGroupParams, + params: AccessGroupApplicationParams, opid?: string ) => Promise>; getGroupMemberList: ( @@ -308,7 +313,7 @@ export interface GroupModuleApi { opid?: string ) => Promise>; getSpecifiedGroupMembersInfo: ( - params: getGroupMembersInfoParams, + params: Omit, opid?: string ) => Promise>; searchGroupMembers: ( @@ -328,7 +333,7 @@ export interface GroupModuleApi { opid?: string ) => Promise>; kickGroupMember: ( - params: OpreateGroupParams, + params: AccessToGroupParams, opid?: string ) => Promise>; changeGroupMemberMute: ( diff --git a/src/core/modules/message.ts b/src/core/modules/message.ts index f46edbd..8c6377c 100644 --- a/src/core/modules/message.ts +++ b/src/core/modules/message.ts @@ -1,34 +1,36 @@ import { v4 as uuidV4 } from 'uuid'; import OpenIMSDK from '..'; +import { BaseResponse } from '@/types/entity'; import { - AdvancedGetMessageResult, - BaseResponse, - CardElem, MessageItem, -} from '@/types/entity'; + CardElem, + AdvancedGetMessageResult, +} from 'open-im-sdk-wasm/lib/types/entity'; import { AtMsgParams, + LocationMsgParams, CustomMsgParams, + QuoteMsgParams, + MergerMsgParams, FaceMessageParams, - FileMsgByPathParams, - FileMsgByUrlParams, - FindMessageParams, + SendMsgParams, + TypingUpdateParams, + SearchLocalParams, GetAdvancedHistoryMsgParams, - ImageMsgByUrlParams, + FindMessageParams, InsertGroupMsgParams, InsertSingleMsgParams, - LocationMsgParams, - MergerMsgParams, - OpreateMessageParams, - QuoteMsgParams, - SearchLocalParams, - SendMsgParams, SetMessageLocalExParams, - SoundMsgByPathParams, - SoundMsgByUrlParams, - TypingUpdateParams, + AccessMessageParams, + ImageMsgParamsByURL, + VideoMsgParamsByURL, + FileMsgParamsByURL, + SoundMsgParamsByURL, +} from 'open-im-sdk-wasm/lib/types/params'; +import { VideoMsgByPathParams, - VideoMsgByUrlParams, + SoundMsgByPathParams, + FileMsgByPathParams, } from '@/types/params'; export function setupMessageModule(openIMSDK: OpenIMSDK) { @@ -134,7 +136,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ) ), - createImageMessageByUrl: (params: ImageMsgByUrlParams, opid = uuidV4()) => + createImageMessageByUrl: (params: ImageMsgParamsByURL, opid = uuidV4()) => openIMSDK.asyncRetunWrap( opid, openIMSDK.libOpenIMSDK.create_image_message_by_url( @@ -173,7 +175,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ) ), - createVideoMessageByUrl: (params: VideoMsgByUrlParams, opid = uuidV4()) => + createVideoMessageByUrl: (params: VideoMsgParamsByURL, opid = uuidV4()) => openIMSDK.asyncRetunWrap( opid, openIMSDK.libOpenIMSDK.create_video_message_by_url( @@ -205,7 +207,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ) ), - createSoundMessageByUrl: (params: SoundMsgByUrlParams, opid = uuidV4()) => + createSoundMessageByUrl: (params: SoundMsgParamsByURL, opid = uuidV4()) => openIMSDK.asyncRetunWrap( opid, openIMSDK.libOpenIMSDK.create_sound_message_by_url( @@ -237,7 +239,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ) ), - createFileMessageByUrl: (params: FileMsgByUrlParams, opid = uuidV4()) => + createFileMessageByUrl: (params: FileMsgParamsByURL, opid = uuidV4()) => openIMSDK.asyncRetunWrap( opid, openIMSDK.libOpenIMSDK.create_file_message_by_url( @@ -256,12 +258,13 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { iOSBadgeCount: true, }; openIMSDK.libOpenIMSDK.send_message( - openIMSDK.baseCallbackWrap(resolve, reject), + openIMSDK.sendMessageCallbackWrap(resolve, reject), opid, JSON.stringify(params.message), params.recvID, params.groupID, - JSON.stringify(offlinePushInfo) + JSON.stringify(offlinePushInfo), + params.isOnlineOnly ?? false ); }), @@ -275,12 +278,13 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { iOSBadgeCount: true, }; openIMSDK.libOpenIMSDK.send_message_not_oss( - openIMSDK.baseCallbackWrap(resolve, reject), + openIMSDK.sendMessageCallbackWrap(resolve, reject), opid, JSON.stringify(params.message), params.recvID, params.groupID, - JSON.stringify(offlinePushInfo) + JSON.stringify(offlinePushInfo), + params.isOnlineOnly ?? false ); }), @@ -294,7 +298,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ); }), - revokeMessage: (params: OpreateMessageParams, opid = uuidV4()) => + revokeMessage: (params: AccessMessageParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.revoke_message( openIMSDK.baseCallbackWrap(resolve, reject), @@ -304,7 +308,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { ); }), - deleteMessage: (params: OpreateMessageParams, opid = uuidV4()) => + deleteMessage: (params: AccessMessageParams, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.delete_message( openIMSDK.baseCallbackWrap(resolve, reject), @@ -315,7 +319,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) { }), deleteMessageFromLocalStorage: ( - params: OpreateMessageParams, + params: AccessMessageParams, opid = uuidV4() ) => new Promise>((resolve, reject) => { @@ -468,7 +472,7 @@ export interface MessageModuleApi { opid?: string ) => Promise>; createImageMessageByUrl: ( - params: ImageMsgByUrlParams, + params: ImageMsgParamsByURL, opid?: string ) => Promise>; createVideoMessage: ( @@ -480,7 +484,7 @@ export interface MessageModuleApi { opid?: string ) => Promise>; createVideoMessageByUrl: ( - params: VideoMsgByUrlParams, + params: VideoMsgParamsByURL, opid?: string ) => Promise>; createSoundMessage: ( @@ -492,7 +496,7 @@ export interface MessageModuleApi { opid?: string ) => Promise>; createSoundMessageByUrl: ( - params: SoundMsgByUrlParams, + params: SoundMsgParamsByURL, opid?: string ) => Promise>; createFileMessage: ( @@ -504,7 +508,7 @@ export interface MessageModuleApi { opid?: string ) => Promise>; createFileMessageByUrl: ( - params: FileMsgByUrlParams, + params: FileMsgParamsByURL, opid?: string ) => Promise>; sendMessage: ( @@ -520,15 +524,15 @@ export interface MessageModuleApi { opid?: string ) => Promise>; revokeMessage: ( - params: OpreateMessageParams, + params: AccessMessageParams, opid?: string ) => Promise>; deleteMessage: ( - params: OpreateMessageParams, + params: AccessMessageParams, opid?: string ) => Promise>; deleteMessageFromLocalStorage: ( - params: OpreateMessageParams, + params: AccessMessageParams, opid?: string ) => Promise>; deleteAllMsgFromLocal: (opid?: string) => Promise>; diff --git a/src/core/modules/user.ts b/src/core/modules/user.ts index dab85a6..7ede519 100644 --- a/src/core/modules/user.ts +++ b/src/core/modules/user.ts @@ -1,13 +1,16 @@ import { v4 as uuidV4 } from 'uuid'; -import { - BaseResponse, - FullUserItemWithCache, - SelfUserInfo, - UserOnlineState, -} from '@/types/entity'; +import { BaseResponse } from '@/types/entity'; import OpenIMSDK from '..'; -import { GetUserInfoWithCacheParams, SetSelfInfoParams } from '@/types/params'; -import { MessageReceiveOptType } from '@/types/enum'; +import { MessageReceiveOptType } from 'open-im-sdk-wasm'; +import { + SelfUserInfo, + FullUserItemWithCache, + UserOnlineState, +} from 'open-im-sdk-wasm/lib/types/entity'; +import { + GetUserInfoWithCacheParams, + PartialUserItem, +} from 'open-im-sdk-wasm/lib/types/params'; export function setupUserModule(openIMSDK: OpenIMSDK) { return { @@ -19,7 +22,7 @@ export function setupUserModule(openIMSDK: OpenIMSDK) { ); }), - setSelfInfo: (params: SetSelfInfoParams, opid = uuidV4()) => + setSelfInfo: (params: PartialUserItem, opid = uuidV4()) => new Promise>((resolve, reject) => { openIMSDK.libOpenIMSDK.set_self_info( openIMSDK.baseCallbackWrap(resolve, reject), @@ -84,7 +87,7 @@ export function setupUserModule(openIMSDK: OpenIMSDK) { export interface UserModuleApi { getSelfUserInfo: (opid?: string) => Promise>; setSelfInfo: ( - params: SetSelfInfoParams, + params: PartialUserItem, opid?: string ) => Promise>; getUsersInfoWithCache: ( diff --git a/src/render.ts b/src/render.ts new file mode 100644 index 0000000..d52773a --- /dev/null +++ b/src/render.ts @@ -0,0 +1,159 @@ +import { CbEvents, getSDK as WasmGetSDK } from 'open-im-sdk-wasm'; +import { MessageItem, WsResponse } from 'open-im-sdk-wasm/lib/types/entity'; +import { + WasmPathConfig, + InitAndLoginConfig, +} from 'open-im-sdk-wasm/lib/types/params'; +import Emitter from './utils/emitter'; +import { + InitConfig, + FileMsgByPathParams, + SoundMsgByPathParams, + VideoMsgByPathParams, +} from './types/params'; + +type EmitterEvents = { + [key in CbEvents]: any; +}; + +type WasmInterface = ReturnType; + +type IMSDKInterface = Omit & { + login: ( + params: Partial, + operationID?: string + ) => Promise; + /** + * @access only for electron + */ + initSDK: (param: InitConfig, opid?: string) => Promise; + /** + * @access only for electron + */ + createImageMessage: ( + imagePath: string, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createImageMessageFromFullPath: ( + imagePath: string, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createVideoMessage: ( + params: VideoMsgByPathParams, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createVideoMessageFromFullPath: ( + params: VideoMsgByPathParams, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createSoundMessage: ( + params: SoundMsgByPathParams, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createSoundMessageFromFullPath: ( + params: SoundMsgByPathParams, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createFileMessage: ( + params: FileMsgByPathParams, + opid?: string + ) => Promise>; + /** + * @access only for electron + */ + createFileMessageFromFullPath: ( + params: FileMsgByPathParams, + opid?: string + ) => Promise>; +}; + +type ElectronInvoke = (method: string, ...args: any[]) => Promise; + +type CreateElectronOptions = { + wasmConfig?: WasmPathConfig; + invoke?: ElectronInvoke; +}; + +let wasmSDK: IMSDKInterface | undefined; +const sdkEmitter = new Emitter(); + +// eslint-disable-next-line +const methodCache = new WeakMap(); + +async function createWasmSDK(wasmConfig?: WasmPathConfig): Promise { + if (!wasmSDK) { + const { getSDK } = await import('open-im-sdk-wasm'); + wasmSDK = getSDK(wasmConfig) as unknown as IMSDKInterface; + } +} + +export function getWithRenderProcess({ + wasmConfig, + invoke, +}: CreateElectronOptions) { + const subscribeCallback = (event: keyof EmitterEvents, data: any) => + sdkEmitter.emit(event, data); + + const sdkProxyHandler: ProxyHandler = { + get(_, prop: keyof IMSDKInterface) { + return async (...args: any[]) => { + try { + if (!invoke) { + await createWasmSDK(wasmConfig); + if (!wasmSDK) throw new Error('WASM SDK is not available'); + const cachedMethod = methodCache.get(wasmSDK[prop]); + if (cachedMethod) { + // eslint-disable-next-line + return cachedMethod(...args); + } + // @ts-ignore + const method = async (...args: any[]) => wasmSDK![prop](...args); + methodCache.set(wasmSDK[prop], method); + return method(...args); + } + + if (!subscribeCallback) { + console.warn('No subscribeCallback method provided'); + } + + if (prop === 'on' || prop === 'off') { + // @ts-ignore + return sdkEmitter[prop](...args); + } + + const result = await invoke(prop, ...args); + if (result?.errCode) { + throw result; + } + return result; + } catch (error) { + console.error(`Error invoking ${prop}:`, error); + throw error; + } + }; + }, + }; + + return { + subscribeCallback, + proxy: new Proxy({} as IMSDKInterface, sdkProxyHandler), + }; +} diff --git a/src/types/entity.ts b/src/types/entity.ts index 09597f6..201be26 100644 --- a/src/types/entity.ts +++ b/src/types/entity.ts @@ -1,21 +1,4 @@ -import { CbEvents } from '@/constant/callback'; -import { - GroupType, - ApplicationHandleResult, - GroupJoinSource, - GroupStatus, - MessageReceiveOptType, - Relationship, - GroupVerificationType, - AllowType, - GroupMemberRole, - SessionType, - GroupAtType, - MessageType, - Platform, - MessageStatus, - OnlineState, -} from './enum'; +import { CbEvents } from 'open-im-sdk-wasm'; export type EmitProxy = (event: CbEvents, ...args: any[]) => void; @@ -35,425 +18,3 @@ export interface BaseResponse { data: T; operationID: string; } - -export type MessageEntity = { - type: string; - offset: number; - length: number; - url?: string; - info?: string; -}; -export type PicBaseInfo = { - uuid: string; - type: string; - size: number; - width: number; - height: number; - url: string; -}; -export type AtUsersInfoItem = { - atUserID: string; - groupNickname: string; -}; -export type GroupApplicationItem = { - createTime: number; - creatorUserID: string; - ex: string; - groupFaceURL: string; - groupID: string; - groupName: string; - groupType: GroupType; - handleResult: ApplicationHandleResult; - handleUserID: string; - handledMsg: string; - handledTime: number; - introduction: string; - memberCount: number; - nickname: string; - notification: string; - ownerUserID: string; - reqMsg: string; - reqTime: number; - joinSource: GroupJoinSource; - status: GroupStatus; - userFaceURL: string; - userID: string; -}; -export type FriendApplicationItem = { - createTime: number; - ex: string; - fromFaceURL: string; - fromNickname: string; - fromUserID: string; - handleMsg: string; - handleResult: ApplicationHandleResult; - handleTime: number; - handlerUserID: string; - reqMsg: string; - toFaceURL: string; - toNickname: string; - toUserID: string; -}; -export type FullUserItem = { - blackInfo: BlackUserItem | null; - friendInfo: FriendUserItem | null; - publicInfo: PublicUserItem | null; -}; -export type FullUserItemWithCache = { - blackInfo: BlackUserItem | null; - friendInfo: FriendUserItem | null; - publicInfo: PublicUserItem | null; - groupMemberInfo: GroupMemberItem | null; -}; -export type PublicUserItem = { - nickname: string; - userID: string; - faceURL: string; - ex: string; -}; -export type SelfUserInfo = { - createTime: number; - ex: string; - faceURL: string; - nickname: string; - userID: string; - globalRecvMsgOpt: MessageReceiveOptType; -}; -export type PartialUserInfo = { - userID: string; -} & Partial>; -export type FriendUserItem = { - addSource: number; - createTime: number; - ex: string; - faceURL: string; - userID: string; - nickname: string; - operatorUserID: string; - ownerUserID: string; - remark: string; - attachedInfo: string; -}; -export type SearchedFriendsInfo = FriendUserItem & { - relationship: Relationship; -}; -export type FriendshipInfo = { - result: number; - userID: string; -}; -export type BlackUserItem = { - addSource: number; - userID: string; - createTime: number; - ex: string; - faceURL: string; - nickname: string; - operatorUserID: string; - ownerUserID: string; -}; -export type GroupItem = { - groupID: string; - groupName: string; - notification: string; - notificationUserID: string; - notificationUpdateTime: number; - introduction: string; - faceURL: string; - ownerUserID: string; - createTime: number; - memberCount: number; - status: GroupStatus; - creatorUserID: string; - groupType: GroupType; - needVerification: GroupVerificationType; - ex: string; - applyMemberFriend: AllowType; - lookMemberInfo: AllowType; -}; -export type GroupMemberItem = { - groupID: string; - userID: string; - nickname: string; - faceURL: string; - roleLevel: GroupMemberRole; - muteEndTime: number; - joinTime: number; - joinSource: GroupJoinSource; - inviterUserID: string; - operatorUserID: string; - ex: string; -}; -export type ConversationItem = { - conversationID: string; - conversationType: SessionType; - userID: string; - groupID: string; - showName: string; - faceURL: string; - recvMsgOpt: MessageReceiveOptType; - unreadCount: number; - groupAtType: GroupAtType; - latestMsg: string; - latestMsgSendTime: number; - draftText: string; - draftTextTime: number; - burnDuration: number; - msgDestructTime: number; - isPinned: boolean; - isNotInGroup: boolean; - isPrivateChat: boolean; - isMsgDestruct: boolean; - attachedInfo: string; - ex: string; -}; -export type MessageItem = { - clientMsgID: string; - serverMsgID: string; - createTime: number; - sendTime: number; - sessionType: SessionType; - sendID: string; - recvID: string; - msgFrom: number; - contentType: MessageType; - senderPlatformID: Platform; - senderNickname: string; - senderFaceUrl: string; - groupID: string; - content: string; - seq: number; - isRead: boolean; - status: MessageStatus; - isReact: boolean; - isExternalExtensions: boolean; - offlinePush: OfflinePush; - attachedInfo: string; - ex: string; - localEx: string; - textElem: TextElem; - cardElem: CardElem; - pictureElem: PictureElem; - soundElem: SoundElem; - videoElem: VideoElem; - fileElem: FileElem; - mergeElem: MergeElem; - atTextElem: AtTextElem; - faceElem: FaceElem; - locationElem: LocationElem; - customElem: CustomElem; - quoteElem: QuoteElem; - notificationElem: NotificationElem; - advancedTextElem: AdvancedTextElem; - typingElem: TypingElem; - attachedInfoElem: AttachedInfoElem; -}; -export type TextElem = { - content: string; -}; -export type CardElem = { - userID: string; - nickname: string; - faceURL: string; - ex: string; -}; -export type AtTextElem = { - text: string; - atUserList: string[]; - atUsersInfo?: AtUsersInfoItem[]; - quoteMessage?: MessageItem; - isAtSelf?: boolean; -}; -export type NotificationElem = { - detail: string; -}; -export type AdvancedTextElem = { - text: string; - messageEntityList: MessageEntity[]; -}; -export type TypingElem = { - msgTips: string; -}; -export type CustomElem = { - data: string; - description: string; - extension: string; -}; -export type FileElem = { - filePath: string; - uuid: string; - sourceUrl: string; - fileName: string; - fileSize: number; -}; -export type FaceElem = { - index: number; - data: string; -}; -export type LocationElem = { - description: string; - longitude: number; - latitude: number; -}; -export type MergeElem = { - title: string; - abstractList: string[]; - multiMessage: MessageItem[]; - messageEntityList: MessageEntity[]; -}; -export type OfflinePush = { - title: string; - desc: string; - ex: string; - iOSPushSound: string; - iOSBadgeCount: boolean; -}; -export type PictureElem = { - sourcePath: string; - sourcePicture: Picture; - bigPicture: Picture; - snapshotPicture: Picture; -}; -export type AttachedInfoElem = { - groupHasReadInfo: GroupHasReadInfo; - isPrivateChat: boolean; - isEncryption: boolean; - inEncryptStatus: boolean; - burnDuration: number; - hasReadTime: number; - notSenderNotificationPush: boolean; - messageEntityList: MessageEntity[]; - uploadProgress: UploadProgress; -}; -export type UploadProgress = { - total: number; - save: number; - current: number; -}; -export type GroupHasReadInfo = { - hasReadCount: number; - unreadCount: number; - hasReadUserIDList: string[]; - groupMemberCount: number; -}; -export type Picture = { - uuid: string; - type: string; - size: number; - width: number; - height: number; - url: string; -}; -export type QuoteElem = { - text: string; - quoteMessage: MessageItem; -}; -export type SoundElem = { - uuid: string; - soundPath: string; - sourceUrl: string; - dataSize: number; - duration: number; -}; -export type VideoElem = { - videoPath: string; - videoUUID: string; - videoUrl: string; - videoType: string; - videoSize: number; - duration: number; - snapshotPath: string; - snapshotUUID: string; - snapshotSize: number; - snapshotUrl: string; - snapshotWidth: number; - snapshotHeight: number; -}; -export type AdvancedRevokeContent = { - clientMsgID: string; - revokeTime: number; - revokerID: string; - revokerNickname: string; - revokerRole: number; - seq: number; - sessionType: SessionType; - sourceMessageSendID: string; - sourceMessageSendTime: number; - sourceMessageSenderNickname: string; -}; - -export type RevokedInfo = { - revokerID: string; - revokerRole: number; - clientMsgID: string; - revokerNickname: string; - revokeTime: number; - sourceMessageSendTime: number; - sourceMessageSendID: string; - sourceMessageSenderNickname: string; - sessionType: number; - seq: number; - ex: string; -}; - -export type ReceiptInfo = { - userID: string; - groupID: string; - msgIDList: string[]; - readTime: number; - msgFrom: number; - contentType: MessageType; - sessionType: SessionType; -}; - -export type SearchMessageResult = { - totalCount: number; - searchResultItems: SearchMessageResultItem[]; -}; - -export type SearchMessageResultItem = { - conversationID: string; - messageCount: number; - conversationType: SessionType; - showName: string; - faceURL: string; - messageList: MessageItem[]; -}; - -export type AdvancedGetMessageResult = { - isEnd: boolean; - lastMinSeq: number; - errCode: number; - errMsg: string; - messageList: MessageItem[]; -}; - -export type RtcInvite = { - inviterUserID: string; - inviteeUserIDList: string[]; - customData?: string; - groupID: string; - roomID: string; - timeout: number; - mediaType: string; - sessionType: number; - platformID: number; - initiateTime?: number; - busyLineUserIDList?: string[]; -}; - -export type UserOnlineState = { - platformIDs?: Platform[]; - status: OnlineState; - userID: string; -}; - -export type GroupMessageReceiptInfo = { - conversationID: string; - groupMessageReadInfo: GroupMessageReadInfo[]; -}; -export type GroupMessageReadInfo = { - clientMsgID: string; - hasReadCount: number; - unreadCount: number; - readMembers: GroupMemberItem[]; -}; diff --git a/src/types/enum.ts b/src/types/enum.ts deleted file mode 100644 index 2e77da4..0000000 --- a/src/types/enum.ts +++ /dev/null @@ -1,135 +0,0 @@ -export enum MessageReceiveOptType { - Nomal = 0, - NotReceive = 1, - NotNotify = 2, -} -export enum AllowType { - Allowed = 0, - NotAllowed = 1, -} -export enum GroupType { - Group = 2, - WorkingGroup = 2, -} -export enum GroupJoinSource { - Invitation = 2, - Search = 3, - QrCode = 4, -} -export enum GroupMemberRole { - Nomal = 20, - Admin = 60, - Owner = 100, -} -export enum GroupVerificationType { - ApplyNeedInviteNot = 0, - AllNeed = 1, - AllNot = 2, -} -export enum MessageStatus { - Sending = 1, - Succeed = 2, - Failed = 3, -} -export enum Platform { - iOS = 1, - Android = 2, - Windows = 3, - MacOSX = 4, - Web = 5, - Linux = 7, - AndroidPad = 8, - iPad = 9, -} -export enum LogLevel { - Debug = 5, - Info = 4, - Warn = 3, - Error = 2, - Fatal = 1, - Panic = 0, -} -export enum ApplicationHandleResult { - Unprocessed = 0, - Agree = 1, - Reject = -1, -} -export enum MessageType { - TextMessage = 101, - PictureMessage = 102, - VoiceMessage = 103, - VideoMessage = 104, - FileMessage = 105, - AtTextMessage = 106, - MergeMessage = 107, - CardMessage = 108, - LocationMessage = 109, - CustomMessage = 110, - TypingMessage = 113, - QuoteMessage = 114, - FaceMessage = 115, - FriendAdded = 1201, - OANotification = 1400, - - GroupCreated = 1501, - MemberQuit = 1504, - GroupOwnerTransferred = 1507, - MemberKicked = 1508, - MemberInvited = 1509, - MemberEnter = 1510, - GroupDismissed = 1511, - GroupMemberMuted = 1512, - GroupMemberCancelMuted = 1513, - GroupMuted = 1514, - GroupCancelMuted = 1515, - GroupAnnouncementUpdated = 1519, - GroupNameUpdated = 1520, - BurnMessageChange = 1701, - - // notification - RevokeMessage = 2101, -} -export enum SessionType { - Single = 1, - Group = 3, - WorkingGroup = 3, - Notification = 4, -} -export enum GroupStatus { - Nomal = 0, - Baned = 1, - Dismissed = 2, - Muted = 3, -} -export enum GroupAtType { - AtNormal = 0, - AtMe = 1, - AtAll = 2, - AtAllAtMe = 3, - AtGroupNotice = 4, -} -export enum GroupMemberFilter { - All = 0, - Owner = 1, - Admin = 2, - Nomal = 3, - AdminAndNomal = 4, - AdminAndOwner = 5, -} -export enum Relationship { - isBlack = 0, - isFriend = 1, -} -export enum LoginStatus { - Logout = 1, - Logging = 2, - Logged = 3, -} -export enum OnlineState { - Online = 1, - Offline = 0, -} -export enum GroupMessageReaderFilter { - Readed = 0, - UnRead = 1, -} diff --git a/src/types/ffi-napi.d.ts b/src/types/ffi-napi.d.ts deleted file mode 100644 index aac781b..0000000 --- a/src/types/ffi-napi.d.ts +++ /dev/null @@ -1,792 +0,0 @@ -/* eslint-disable @typescript-eslint/ban-types */ - -/// -declare module '@openim/ffi-napi' { - import ref = require('ref-napi'); - import ref_struct = require('ref-struct-di'); - import StructType = ref_struct.StructType; - - /** - * This is a marker type that causes TypeScript to use string literal inference when inferring a generic from an array of {@link ref.TypeLike}. - */ - export type ArgTypesInferenceMarker = ['void']; - - export interface LibraryFunctionOptions { - abi?: number | undefined; - async?: boolean | undefined; - varargs?: boolean | undefined; - } - - /** - * Base constraint for an object-based library type definition. - */ - export type LibraryObjectDefinitionBase = Record< - string, - [ - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - opts?: LibraryFunctionOptions - ] - >; - - /** - * This is a marker type that causes TypeScript to use string literal inference when inferring a generic from {@link LibraryObjectDefinitionBase}. - * If it is not used, `new Library(..., { x: ["int", ["int"]] })` will be inferred as `new Library<{ x: [string, string[]] }>(...)` instead of `new UnionType<{ x: ["int", ["int"]] }>(...)`. - */ - export type LibraryObjectDefinitionInferenceMarker = Record< - string, - [retType: 'void', argTypes: ArgTypesInferenceMarker] - >; - - /** - * Converts a {@link LibraryObjectDefinitionBase} into a consistent subtype of {@link LibraryDefinitionBase}. If `any` is used, it is passed along - * to be interpreted to use a fallback definition for a union. - */ - export type LibraryObjectDefinitionToLibraryDefinition< - T extends LibraryObjectDefinitionBase - > = [T] extends [never] | [0] - ? any // catches T extends never/any (since `0` doesn't overlap with our constraint) - : { - [P in keyof T]: [ - retType: ref.CoerceType, - argTypes: ref.CoerceTypes, - opts: T[P][2] - ]; - }; - - /** - * Base constraint for a consistent library type definition. - */ - export type LibraryDefinitionBase = Record< - string, - [ - retType: ref.Type, - argTypes: ref.Type[], - opts: LibraryFunctionOptions | undefined - ] - >; - - /** - * Represents a {@link Library} instance created from a {@link LibraryDefinitionBase}. - */ - export type LibraryObject = [T] extends - | [never] - | [0] - ? any // catches T extends never/any (since `0` doesn't overlap with our constraint) - : { - [P in keyof T]: T[P][2] extends undefined - ? ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - > - : T[P][2] extends { varargs: true } - ? VariadicForeignFunction - : T[P][2] extends { async: true } - ? ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >['async'] - : ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - }; - - /** Provides a friendly API on-top of `DynamicLibrary` and `ForeignFunction`. */ - export interface Library { - /** The extension to use on libraries. */ - EXT: string; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - new < - TDefinition extends - | LibraryObjectDefinitionBase - | LibraryObjectDefinitionInferenceMarker, - T - >( - libFile: string | null, - funcs: TDefinition, - lib: T - ): T & - LibraryObject>; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - new < - TDefinition extends - | LibraryObjectDefinitionBase - | LibraryObjectDefinitionInferenceMarker - >( - libFile: string | null, - funcs: TDefinition, - lib?: object - ): LibraryObject>; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - new ( - libFile: string | null, - funcs?: Record< - string, - [ - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - opts?: LibraryFunctionOptions - ] - >, - lib?: object - ): any; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - < - TDefinition extends - | LibraryObjectDefinitionBase - | LibraryObjectDefinitionInferenceMarker, - T - >( - libFile: string | null, - funcs: TDefinition, - lib: T - ): T & - LibraryObject>; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - < - TDefinition extends - | LibraryObjectDefinitionBase - | LibraryObjectDefinitionInferenceMarker - >( - libFile: string | null, - funcs: TDefinition, - lib?: object - ): LibraryObject>; - - /** - * @param libFile name of library - * @param funcs hash of [retType, [...argType], opts?: {abi?, async?, varargs?}] - * @param lib hash that will be extended - */ - ( - libFile: string | null, - funcs?: Record< - string, - [ - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - opts?: LibraryFunctionOptions - ] - >, - lib?: object - ): any; - } - export const Library: Library; - - /** Get value of errno. */ - export function errno(): number; - - export interface Function< - TReturnType extends ref.Type = ref.Type, - TArgTypes extends ref.Type[] = ref.Type[] - > extends ref.Type< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - > { - /** The type of return value. */ - retType: TReturnType; - /** The type of arguments. */ - argTypes: TArgTypes; - /** Is set for node-ffi functions. */ - ffi_type: PFFI_TYPE; - abi: number; - - /** Get a `Callback` pointer of this function type. */ - toPointer( - fn: ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - /** Get a `ForeignFunction` of this function type. */ - toFunction( - buf: Buffer - ): ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - } - - /** Creates and returns a type for a C function pointer. */ - export const Function: { - // NOTE: This overload is a subtype of the next overload, but provides better completions. - new < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] | ArgTypesInferenceMarker - >( - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): Function, ref.CoerceTypes>; - new < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): Function, ref.CoerceTypes>; - - new ( - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - abi?: number - ): Function; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] | ArgTypesInferenceMarker - >( - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): Function, ref.CoerceTypes>; - < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.Type[] | ArgTypesInferenceMarker - >( - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): Function, ref.CoerceTypes>; - - (retType: ref.TypeLike, argTypes: ref.TypeLike[], abi?: number): Function; - }; - - export interface ForeignFunction { - (...args: TArgs): TReturn; - async(...args: [...TArgs, (err: any, value: TReturn) => void]): void; - } - - /** - * Represents a foreign function in another library. Manages all of the aspects - * of function execution, including marshalling the data parameters for the - * function into native types and also unmarshalling the return from function - * execution. - */ - export const ForeignFunction: { - // NOTE: This overload is a subtype of the next overload, but provides better completions. - new < - TReturnType extends ref.NamedType, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - new < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - - new ( - ptr: Buffer, - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - abi?: number - ): ForeignFunction; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - < - TReturnType extends ref.NamedType, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - retType: TReturnType, - argTypes: TArgTypes, - abi?: number - ): ForeignFunction< - ref.UnderlyingType, - ref.UnderlyingTypes - >; - - ( - ptr: Buffer, - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - abi?: number - ): ForeignFunction; - }; - - export interface VariadicForeignFunction< - TReturnType extends ref.Type = ref.Type, - TArgTypes extends ref.Type[] = ref.Type[] - > { - /** - * What gets returned is another function that needs to be invoked with the rest - * of the variadic types that are being invoked from the function. - */ - // NOTE: This overload is a subtype of the next overload, but provides better completions. - (...args: A): ForeignFunction< - ref.UnderlyingType, - [...ref.UnderlyingTypes, ...ref.UnderlyingTypes] - >; - /** - * What gets returned is another function that needs to be invoked with the rest - * of the variadic types that are being invoked from the function. - */ - (...args: A): ForeignFunction< - ref.UnderlyingType, - [...ref.UnderlyingTypes, ...ref.UnderlyingTypes] - >; - - /** - * Return type as a property of the function generator to - * allow for monkey patching the return value in the very rare case where the - * return type is variadic as well - */ - returnType: TReturnType; - } - - /** - * For when you want to call to a C function with variable amount of arguments. - * i.e. `printf`. - * - * This function takes care of caching and reusing `ForeignFunction` instances that - * contain the same ffi_type argument signature. - */ - export const VariadicForeignFunction: { - // NOTE: This overload is a subtype of the next overload, but provides better completions. - new < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - ret: TReturnType, - fixedArgs: TArgTypes, - abi?: number - ): VariadicForeignFunction< - ref.CoerceType, - ref.CoerceTypes - >; - new < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - ret: TReturnType, - fixedArgs: TArgTypes, - abi?: number - ): VariadicForeignFunction< - ref.CoerceType, - ref.CoerceTypes - >; - - new ( - ptr: Buffer, - ret: ref.TypeLike, - fixedArgs: ref.TypeLike[], - abi?: number - ): VariadicForeignFunction; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - ret: TReturnType, - fixedArgs: TArgTypes, - abi?: number - ): VariadicForeignFunction< - ref.CoerceType, - ref.CoerceTypes - >; - < - TReturnType extends ref.TypeLike, - TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker - >( - ptr: Buffer, - ret: TReturnType, - fixedArgs: TArgTypes, - abi?: number - ): VariadicForeignFunction< - ref.CoerceType, - ref.CoerceTypes - >; - - ( - ptr: Buffer, - ret: ref.TypeLike, - fixedArgs: ref.TypeLike[], - abi?: number - ): VariadicForeignFunction; - }; - - /** - * This class loads and fetches function pointers for dynamic libraries - * (`.so`, `.dylib`, `etc`). After the libray's function pointer is acquired, then you - * call {@link DynamicLibrary.get} to retreive a pointer to an exported symbol. You need to - * call `get___` on the pointer to dereference it into its actual value, or - * turn the pointer into a callable function with {@link ForeignFunction}. - */ - export class DynamicLibrary { - /** - * @param mode One of the numeric {@link DynamicLibrary.FLAGS} values. - */ - constructor(path?: string, mode?: number); - - /** - * Close library, returns the result of the `dlclose` system function. - */ - close(): number; - - /** - * Get a symbol from this library. - */ - get(symbol: string): Buffer; - - /** - * Get the result of the `dlerror` system function. - */ - error(): string; - - /** - * Returns the path originally passed to the constructor. - */ - path(): string; - } - - /** - * This class loads and fetches function pointers for dynamic libraries - * (`.so`, `.dylib`, etc). After the libray's function pointer is acquired, then you - * call {@link DynamicLibrary.get} to retreive a pointer to an exported symbol. You need to - * call `get___` on the pointer to dereference it into its actual value, or - * turn the pointer into a callable function with {@link ForeignFunction}. - * - * @param mode One of the numeric {@link DynamicLibrary.FLAGS} values. - */ - export function DynamicLibrary(path?: string, mode?: number): DynamicLibrary; - export namespace DynamicLibrary { - /** - * Exported flags from "dlfcn.h" - */ - namespace FLAGS { - // flags for dlopen() - const RTLD_LAZY: number; - const RTLD_NOW: number; - const RTLD_LOCAL: number; - const RTLD_GLOBAL: number; - const RTLD_NOLOAD: number | undefined; // not defined on Windows - const RTLD_NODELETE: number | undefined; // not defined on Windows - const RTLD_FIRST: number | undefined; // not defined on Windows - - // flags for dlsym() - const RTLD_NEXT: ref.Pointer; - const RTLD_DEFAULT: ref.Pointer; - const RTLD_SELF: ref.Pointer | undefined; // not defined on Windows - const RTLD_MAIN_ONLY: ref.Pointer | undefined; // not defined on Windows - } - } - - /** - * Turns a JavaScript function into a C function pointer. - * The function pointer may be used in other C functions that - * accept C callback functions. - */ - export interface Callback { - // NOTE: This overload is a subtype of the next overload, but provides better completions. - new < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] - >( - retType: TReturnType, - argTypes: TArgTypes, - abi: number, - fn: ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - new ( - retType: TReturnType, - argTypes: TArgTypes, - abi: number, - fn: ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - new < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] - >( - retType: TReturnType, - argTypes: TArgTypes, - fn: ( - ...ags: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - new ( - retType: TReturnType, - argTypes: TArgTypes, - fn: ( - ...ags: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - - new ( - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - abi: number, - fn: (...args: any[]) => any - ): Buffer; - new ( - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - fn: (...args: any[]) => any - ): Buffer; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] - >( - retType: TReturnType, - argTypes: TArgTypes, - abi: number, - fn: ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - ( - retType: TReturnType, - argTypes: TArgTypes, - abi: number, - fn: ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - - // NOTE: This overload is a subtype of the next overload, but provides better completions. - < - TReturnType extends ref.NamedTypeLike, - TArgTypes extends ref.NamedTypeLike[] - >( - retType: TReturnType, - argTypes: TArgTypes, - fn: ( - ...ags: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - ( - retType: TReturnType, - argTypes: TArgTypes, - fn: ( - ...ags: ref.UnderlyingTypes - ) => ref.UnderlyingType - ): ref.Pointer< - ( - ...args: ref.UnderlyingTypes - ) => ref.UnderlyingType - >; - - ( - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - abi: number, - fn: (...args: any[]) => any - ): Buffer; - ( - retType: ref.TypeLike, - argTypes: ref.TypeLike[], - fn: (...args: any[]) => any - ): Buffer; - } - export const Callback: Callback; - - /** Get a `ffi_type *` Buffer appropriate for the given type. */ - export function ffiType(type: ref.TypeLike): ref.Pointer; - export namespace ffiType { - /** - * Define the `ffi_type` struct (see deps/libffi/include/ffi.h) for use in JS. - * This struct type is used internally to define custom struct ret/arg types. - */ - const FFI_TYPE: StructType<{ - size: typeof ref.types.size_t; - alignment: typeof ref.types.ushort; - type: typeof ref.types.ushort; - elements: ref.Type>; - }>; - - type FFI_TYPE = ReturnType; - } - - export function CIF( - retType: ref.TypeLike, - types: ref.TypeLike[], - abi?: number - ): Buffer; - export function CIF_var( - retType: ref.TypeLike, - types: ref.TypeLike[], - numFixedArgs: number, - abi?: number - ): Buffer; - - export const HAS_OBJC: boolean; - - /** - * Represents an opaque pointer to an {@link FFI_TYPE} struct used for marshalling types to native code. - */ - export type PFFI_TYPE = ref.Pointer; - - // declare module 'ref-napi' { - // interface Type { - // /** - // * Determines the FFI_TYPE set for a type. - // */ - // ffi_type?: PFFI_TYPE | undefined; - // } - // } - - export interface FfiTypesRegistry { - void: PFFI_TYPE; - uint8: PFFI_TYPE; - int8: PFFI_TYPE; - uint16: PFFI_TYPE; - int16: PFFI_TYPE; - uint32: PFFI_TYPE; - int32: PFFI_TYPE; - uint64: PFFI_TYPE; - int64: PFFI_TYPE; - uchar: PFFI_TYPE; - char: PFFI_TYPE; - ushort: PFFI_TYPE; - short: PFFI_TYPE; - uint: PFFI_TYPE; - int: PFFI_TYPE; - float: PFFI_TYPE; - double: PFFI_TYPE; - pointer: PFFI_TYPE; - ulonglong: PFFI_TYPE; - longlong: PFFI_TYPE; - ulong: PFFI_TYPE; - long: PFFI_TYPE; - } - - export const FFI_TYPES: FfiTypesRegistry; - export const FFI_OK: number; - export const FFI_BAD_TYPEDEF: number; - export const FFI_BAD_ABI: number; - export const FFI_DEFAULT_ABI: number; - export const FFI_FIRST_ABI: number; - export const FFI_LAST_ABI: number; - - // NOTE: These are defined depending on the platform ffi-napi was compiled on: - export const FFI_SYSV: number | undefined; // __arm__, Intel x86 Win32, __aarch64__, Intel x86 and AMD x86/x64 - export const FFI_VFP: number | undefined; // __arm__ - export const FFI_UNIX64: number | undefined; // All unix variants - export const FFI_STDCALL: number | undefined; // Intel x86 Win32 - export const FFI_THISCALL: number | undefined; // Intel x86 Win32 - export const FFI_FASTCALL: number | undefined; // Intel x86 Win32 - export const FFI_MS_CDECL: number | undefined; // Intel x86 Win32 - export const FFI_WIN64: number | undefined; // Intel x86 Win64 - - export import RTLD_LAZY = DynamicLibrary.FLAGS.RTLD_LAZY; - export import RTLD_NOW = DynamicLibrary.FLAGS.RTLD_NOW; - export import RTLD_LOCAL = DynamicLibrary.FLAGS.RTLD_LOCAL; - export import RTLD_GLOBAL = DynamicLibrary.FLAGS.RTLD_GLOBAL; - export import RTLD_NOLOAD = DynamicLibrary.FLAGS.RTLD_NOLOAD; - export import RTLD_NODELETE = DynamicLibrary.FLAGS.RTLD_NODELETE; - export import RTLD_FIRST = DynamicLibrary.FLAGS.RTLD_FIRST; - export import RTLD_NEXT = DynamicLibrary.FLAGS.RTLD_NEXT; - export import RTLD_DEFAULT = DynamicLibrary.FLAGS.RTLD_DEFAULT; - export import RTLD_SELF = DynamicLibrary.FLAGS.RTLD_SELF; - export import RTLD_MAIN_ONLY = DynamicLibrary.FLAGS.RTLD_MAIN_ONLY; - - export const FFI_ARG_SIZE: number; - export const FFI_SARG_SIZE: number; - export const FFI_TYPE_SIZE: number; - export const FFI_CIF_SIZE: number; - - export const LIB_EXT: string; - - export import FFI_TYPE = ffiType.FFI_TYPE; - - /** Default types. */ - export import types = ref.types; -} diff --git a/src/types/libOpenIMSDK.d.ts b/src/types/libOpenIMSDK.d.ts index 052f6dc..5b62b40 100644 --- a/src/types/libOpenIMSDK.d.ts +++ b/src/types/libOpenIMSDK.d.ts @@ -1,24 +1,11 @@ // libOpenIMSDK.d.ts declare module 'libOpenIMSDK' { - export type CB_S = Buffer | ((data: string) => void); - export type CB_I_S = Buffer | ((event: number, data: string) => void); - export type CB_S_I_S_S = - | Buffer - | (( - operationID: string, - errCode: number, - errMsg: string, - data: string - ) => void); - export type CB_S_I_S_S_I = - | Buffer - | (( - operationID: string, - errCode: number, - errMsg: string, - data: string, - progress: number - ) => void); + import { IKoffiRegisteredCallback } from 'koffi'; + + export type CB_S = IKoffiRegisteredCallback; + export type CB_I_S = IKoffiRegisteredCallback; + export type CB_S_I_S_S = IKoffiRegisteredCallback; + export type CB_S_I_S_S_I = IKoffiRegisteredCallback; export interface LibOpenIMSDK { set_group_listener(cCallback: CB_I_S): void; @@ -232,6 +219,12 @@ declare module 'libOpenIMSDK' { operationID: string ): void; get_at_all_tag(operationID: string): string; + set_conversation_ex( + cCallback: CB_S_I_S_S, + operationID: string, + conversationID: string, + ex: string + ): void; get_conversation_id_by_session_type( operationID: string, sourceID: string, @@ -243,7 +236,8 @@ declare module 'libOpenIMSDK' { message: string, recvID: string, groupID: string, - offlinePushInfo: string + offlinePushInfo: string, + isOnlineOnly: boolean ): void; send_message_not_oss( cCallback: CB_S_I_S_S_I, @@ -251,7 +245,8 @@ declare module 'libOpenIMSDK' { message: string, recvID: string, groupID: string, - offlinePushInfo: string + offlinePushInfo: string, + isOnlineOnly: boolean ): void; find_message_list( cCallback: CB_S_I_S_S, @@ -409,6 +404,12 @@ declare module 'libOpenIMSDK' { operationID: string, searchParam: string ): void; + set_friends_ex( + cCallback: CB_S_I_S_S, + operationID: string, + toUserIDs: string, + ex: string + ): void; check_friend( cCallback: CB_S_I_S_S, operationID: string, @@ -450,7 +451,8 @@ declare module 'libOpenIMSDK' { add_black( cCallback: CB_S_I_S_S, operationID: string, - blackUserID: string + blackUserID: string, + ex: string ): void; get_black_list(cCallback: CB_S_I_S_S, operationID: string): void; remove_black( @@ -469,7 +471,8 @@ declare module 'libOpenIMSDK' { operationID: string, cGroupID: string, cReqMsg: string, - cJoinSource: number + cJoinSource: number, + ex: string ): void; quit_group( cCallback: CB_S_I_S_S, diff --git a/src/types/params.ts b/src/types/params.ts index d336756..bd3f4bd 100644 --- a/src/types/params.ts +++ b/src/types/params.ts @@ -1,25 +1,11 @@ -import { - AtUsersInfoItem, - GroupItem, - MessageItem, - OfflinePush, - PicBaseInfo, - SelfUserInfo, -} from './entity'; -import { - MessageReceiveOptType, - GroupJoinSource, - GroupMemberFilter, - GroupMemberRole, - MessageType, - LogLevel, -} from './enum'; - +import { LogLevel } from 'open-im-sdk-wasm'; export interface InitConfig { apiAddr: string; wsAddr: string; logLevel?: LogLevel; platformID: number; + dataDir: string; + logFilePath?: string; isLogStandardOutput?: boolean; isExternalExtensions?: boolean; } @@ -29,201 +15,11 @@ export interface LoginParams { token: string; } -export type SetSelfInfoParams = Partial; - -export type GetUserInfoWithCacheParams = { - userIDList: string[]; - groupID?: string; -}; - -export type SplitConversationParams = { - offset: number; - count: number; -}; - -export type GetOneConversationParams = { - sourceID: string; - sessionType: number; -}; - -export type SetConversationDraftParams = { - conversationID: string; - draftText: string; -}; - -export type PinConversationParams = { - conversationID: string; - isPinned: boolean; -}; - -export type SetConversationRecvOptParams = { - conversationID: string; - opt: MessageReceiveOptType; -}; - -export type SetConversationPrivateParams = { - conversationID: string; - isPrivate: boolean; -}; - -export type SetBurnDurationParams = { - conversationID: string; - burnDuration: number; -}; - -export type AccessFriendParams = { - toUserID: string; - handleMsg: string; -}; - -export type AddFriendParams = { - toUserID: string; - reqMsg: string; -}; - -export type SearchFriendParams = { - keywordList: string[]; - isSearchUserID: boolean; - isSearchNickname: boolean; - isSearchRemark: boolean; -}; - -export type RemarkFriendParams = { - toUserID: string; - remark: string; -}; - -export type CreateGroupParams = { - memberUserIDs: string[]; - groupInfo: Partial; - adminUserIDs?: string[]; - ownerUserID?: string; -}; - -export type JoinGroupParams = { - groupID: string; - reqMsg: string; - joinSource: GroupJoinSource; -}; - -export type OpreateGroupParams = { - groupID: string; - reason: string; - userIDList: string[]; -}; - -export type SearchGroupParams = { - keywordList: string[]; - isSearchGroupID: boolean; - isSearchGroupName: boolean; -}; - -export type SetGroupinfoParams = Partial & { groupID: string }; - -export type AccessGroupParams = { - groupID: string; - fromUserID: string; - handleMsg: string; -}; - -export declare type GetGroupMemberParams = { - groupID: string; - filter: GroupMemberFilter; - offset: number; - count: number; -}; - -export type getGroupMembersInfoParams = { - groupID: string; - userIDList: string[]; -}; - -export type SearchGroupMemberParams = { - groupID: string; - keywordList: string[]; - isSearchUserID: boolean; - isSearchMemberNickname: boolean; - offset: number; - count: number; -}; - -export type UpdateMemberInfoParams = { - groupID: string; - userID: string; - nickname?: string; - faceURL?: string; - roleLevel?: GroupMemberRole; - ex?: string; -}; - -export type GetGroupMemberByTimeParams = { - groupID: string; - filterUserIDList: string[]; - offset: number; - count: number; - joinTimeBegin: number; - joinTimeEnd: number; -}; - -export type ChangeGroupMemberMuteParams = { - groupID: string; - userID: string; - mutedSeconds: number; -}; - -export type ChangeGroupMuteParams = { - groupID: string; - isMute: boolean; -}; - -export type TransferGroupParams = { - groupID: string; - newOwnerUserID: string; -}; - -export type AtMsgParams = { - text: string; - atUserIDList: string[]; - atUsersInfo?: AtUsersInfoItem[]; - message?: MessageItem; -}; - -export type ImageMsgByUrlParams = { - sourcePicture: PicBaseInfo; - bigPicture: PicBaseInfo; - snapshotPicture: PicBaseInfo; - sourcePath: string; -}; - -export type SoundMsgByUrlParams = { - uuid: string; - soundPath: string; - sourceUrl: string; - dataSize: number; - duration: number; - soundType?: string; -}; export type SoundMsgByPathParams = { soundPath: string; duration: number; }; -export type VideoMsgByUrlParams = { - videoPath: string; - duration: number; - videoType: string; - snapshotPath: string; - videoUUID: string; - videoUrl: string; - videoSize: number; - snapshotUUID: string; - snapshotSize: number; - snapshotUrl: string; - snapshotWidth: number; - snapshotHeight: number; - snapShotType?: string; -}; - export type VideoMsgByPathParams = { videoPath: string; videoType: string; @@ -235,101 +31,3 @@ export type FileMsgByPathParams = { filePath: string; fileName: string; }; - -export type FileMsgByUrlParams = { - filePath: string; - fileName: string; - uuid: string; - sourceUrl: string; - fileSize: number; - fileType?: string; -}; - -export type MergerMsgParams = { - messageList: MessageItem[]; - title: string; - summaryList: string[]; -}; - -export type LocationMsgParams = { - description: string; - longitude: number; - latitude: number; -}; - -export type QuoteMsgParams = { - text: string; - message: string; -}; - -export type CustomMsgParams = { - data: string; - extension: string; - description: string; -}; - -export type FaceMessageParams = { - index: number; - data: string; -}; - -export type SendMsgParams = { - recvID: string; - groupID: string; - offlinePushInfo?: OfflinePush; - message: MessageItem; -}; - -export type TypingUpdateParams = { - recvID: string; - msgTip: string; -}; - -export type OpreateMessageParams = { - conversationID: string; - clientMsgID: string; -}; - -export type SearchLocalParams = { - conversationID: string; - keywordList: string[]; - keywordListMatchType?: number; - senderUserIDList?: string[]; - messageTypeList?: MessageType[]; - searchTimePosition?: number; - searchTimePeriod?: number; - pageIndex?: number; - count?: number; -}; - -export type GetAdvancedHistoryMsgParams = { - userID?: string; - groupID?: string; - lastMinSeq: number; - count: number; - startClientMsgID: string; - conversationID: string; -}; - -export type FindMessageParams = { - conversationID: string; - clientMsgIDList: string[]; -}; - -export type InsertGroupMsgParams = { - message: MessageItem; - groupID: string; - sendID: string; -}; - -export type InsertSingleMsgParams = { - message: MessageItem; - recvID: string; - sendID: string; -}; - -export type SetMessageLocalExParams = { - conversationID: string; - clientMsgID: string; - localEx: string; -}; diff --git a/src/utils/emitter.ts b/src/utils/emitter.ts index 6e6a305..08bea04 100644 --- a/src/utils/emitter.ts +++ b/src/utils/emitter.ts @@ -1,4 +1,4 @@ -import { CbEvents } from '@/constant/callback'; +import { CbEvents } from 'open-im-sdk-wasm'; interface Events { [key: string]: Cbfn[];