refactor: replace ffi with koffi

This commit is contained in:
Bloomingg
2024-04-08 16:54:02 +08:00
parent 9d20806d51
commit fbcae7866b
19 changed files with 1248 additions and 2239 deletions

Binary file not shown.

109
package-lock.json generated
View File

@@ -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",

View File

@@ -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"
}
}

View File

@@ -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(),
]
}
];

View File

@@ -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, CbEvents> = {
[NativeEvent.CONNECTING]: CbEvents.OnConnecting,
[NativeEvent.CONNECT_SUCCESS]: CbEvents.OnConnectSuccess,

File diff suppressed because it is too large Load Diff

View File

@@ -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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.set_conversation_ex(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
opid,
params.conversationID,
params.ex
);
}),
getMultipleConversation: (conversationIDList: string, opid = uuidV4()) =>
new Promise<BaseResponse<ConversationItem[]>>((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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.pin_conversation(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -110,7 +121,7 @@ export function setupConversationModule(openIMSDK: OpenIMSDK) {
);
}),
setConversationPrivateChat: (
params: SetConversationPrivateParams,
params: SetConversationPrivateStateParams,
opid = uuidV4()
) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
@@ -193,6 +204,10 @@ export interface ConversationModuleApi {
params: GetOneConversationParams,
opid?: string
) => Promise<BaseResponse<ConversationItem>>;
setConversationEx: (
params: SetConversationExParams,
opid?: string
) => Promise<BaseResponse<void>>;
getMultipleConversation: (
conversationIDList: string,
opid?: string
@@ -207,11 +222,11 @@ export interface ConversationModuleApi {
opid?: string
) => Promise<BaseResponse<void>>;
setConversationDraft: (
params: SetConversationDraftParams,
params: SplitConversationParams,
opid?: string
) => Promise<BaseResponse<void>>;
pinConversation: (
params: PinConversationParams,
params: SplitConversationParams,
opid?: string
) => Promise<BaseResponse<void>>;
setConversationRecvMessageOpt: (
@@ -219,7 +234,7 @@ export interface ConversationModuleApi {
opid?: string
) => Promise<BaseResponse<void>>;
setConversationPrivateChat: (
params: SetConversationPrivateParams,
params: SetConversationPrivateStateParams,
opid?: string
) => Promise<BaseResponse<void>>;
setConversationBurnDuration: (

View File

@@ -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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.accept_friend_application(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -27,12 +32,13 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) {
);
}),
addBlack: (userID: string, opid = uuidV4()) =>
addBlack: (params: AddBlackParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.add_black(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
opid,
userID
params.toUserID,
params.ex ?? ''
);
}),
@@ -63,6 +69,16 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) {
);
}),
setFriendsEx: (params: SetFriendExParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.set_friends_ex(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
opid,
JSON.stringify(params),
params.ex ?? ''
);
}),
getBlackList: (opid = uuidV4()) =>
new Promise<BaseResponse<BlackUserItem[]>>((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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.refuse_friend_application(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -144,7 +163,7 @@ export function setupFriendModule(openIMSDK: OpenIMSDK) {
export interface FriendModuleApi {
acceptFriendApplication: (
params: AccessFriendParams,
params: AccessFriendApplicationParams,
opid?: string
) => Promise<BaseResponse<void>>;
addBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
@@ -154,6 +173,10 @@ export interface FriendModuleApi {
opid?: string
) => Promise<BaseResponse<FriendshipInfo[]>>;
deleteFriend: (userID: string, opid?: string) => Promise<BaseResponse<void>>;
setFriendsEx: (
params: SetFriendExParams,
opid?: string
) => Promise<BaseResponse<void>>;
getBlackList: (opid?: string) => Promise<BaseResponse<BlackUserItem[]>>;
getFriendApplicationListAsApplicant: (
opid?: string
@@ -167,7 +190,7 @@ export interface FriendModuleApi {
opid?: string
) => Promise<BaseResponse<FullUserItem[]>>;
refuseFriendApplication: (
params: AccessFriendParams,
params: AccessFriendApplicationParams,
opid?: string
) => Promise<BaseResponse<void>>;
removeBlack: (userID: string, opid?: string) => Promise<BaseResponse<void>>;

View File

@@ -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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.invite_user_to_group(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -82,7 +81,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) {
);
}),
setGroupInfo: (params: SetGroupinfoParams, opid = uuidV4()) =>
setGroupInfo: (params: Partial<GroupItem>, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.set_group_info(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -107,7 +106,10 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) {
);
}),
acceptGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
acceptGroupApplication: (
params: AccessGroupApplicationParams,
opid = uuidV4()
) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.accept_group_application(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -118,7 +120,10 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) {
);
}),
refuseGroupApplication: (params: AccessGroupParams, opid = uuidV4()) =>
refuseGroupApplication: (
params: AccessGroupApplicationParams,
opid = uuidV4()
) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.refuse_group_application(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -142,7 +147,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) {
}),
getSpecifiedGroupMembersInfo: (
params: getGroupMembersInfoParams,
params: Omit<AccessToGroupParams, 'reason'>,
opid = uuidV4()
) =>
new Promise<BaseResponse<GroupMemberItem[]>>((resolve, reject) => {
@@ -198,7 +203,7 @@ export function setupGroupModule(openIMSDK: OpenIMSDK) {
);
}),
kickGroupMember: (params: OpreateGroupParams, opid = uuidV4()) =>
kickGroupMember: (params: AccessToGroupParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.kick_group_member(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -273,7 +278,7 @@ export interface GroupModuleApi {
opid?: string
) => Promise<BaseResponse<void>>;
inviteUserToGroup: (
params: OpreateGroupParams,
params: AccessToGroupParams,
opid?: string
) => Promise<BaseResponse<void>>;
getJoinedGroupList: (opid?: string) => Promise<BaseResponse<GroupItem[]>>;
@@ -286,7 +291,7 @@ export interface GroupModuleApi {
opid?: string
) => Promise<BaseResponse<GroupItem[]>>;
setGroupInfo: (
params: SetGroupinfoParams,
params: Partial<GroupItem>,
opid?: string
) => Promise<BaseResponse<void>>;
getGroupApplicationListAsRecipient: (
@@ -296,11 +301,11 @@ export interface GroupModuleApi {
opid?: string
) => Promise<BaseResponse<GroupApplicationItem[]>>;
acceptGroupApplication: (
params: AccessGroupParams,
params: AccessGroupApplicationParams,
opid?: string
) => Promise<BaseResponse<void>>;
refuseGroupApplication: (
params: AccessGroupParams,
params: AccessGroupApplicationParams,
opid?: string
) => Promise<BaseResponse<void>>;
getGroupMemberList: (
@@ -308,7 +313,7 @@ export interface GroupModuleApi {
opid?: string
) => Promise<BaseResponse<GroupMemberItem[]>>;
getSpecifiedGroupMembersInfo: (
params: getGroupMembersInfoParams,
params: Omit<AccessToGroupParams, 'reason'>,
opid?: string
) => Promise<BaseResponse<GroupMemberItem[]>>;
searchGroupMembers: (
@@ -328,7 +333,7 @@ export interface GroupModuleApi {
opid?: string
) => Promise<BaseResponse<GroupMemberItem[]>>;
kickGroupMember: (
params: OpreateGroupParams,
params: AccessToGroupParams,
opid?: string
) => Promise<BaseResponse<void>>;
changeGroupMemberMute: (

View File

@@ -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<MessageItem>(
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<MessageItem>(
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<MessageItem>(
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<MessageItem>(
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<MessageItem>(resolve, reject),
openIMSDK.sendMessageCallbackWrap<MessageItem>(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<MessageItem>(resolve, reject),
openIMSDK.sendMessageCallbackWrap<MessageItem>(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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.revoke_message(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -304,7 +308,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) {
);
}),
deleteMessage: (params: OpreateMessageParams, opid = uuidV4()) =>
deleteMessage: (params: AccessMessageParams, opid = uuidV4()) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.delete_message(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -315,7 +319,7 @@ export function setupMessageModule(openIMSDK: OpenIMSDK) {
}),
deleteMessageFromLocalStorage: (
params: OpreateMessageParams,
params: AccessMessageParams,
opid = uuidV4()
) =>
new Promise<BaseResponse<void>>((resolve, reject) => {
@@ -468,7 +472,7 @@ export interface MessageModuleApi {
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createImageMessageByUrl: (
params: ImageMsgByUrlParams,
params: ImageMsgParamsByURL,
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createVideoMessage: (
@@ -480,7 +484,7 @@ export interface MessageModuleApi {
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createVideoMessageByUrl: (
params: VideoMsgByUrlParams,
params: VideoMsgParamsByURL,
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createSoundMessage: (
@@ -492,7 +496,7 @@ export interface MessageModuleApi {
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createSoundMessageByUrl: (
params: SoundMsgByUrlParams,
params: SoundMsgParamsByURL,
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createFileMessage: (
@@ -504,7 +508,7 @@ export interface MessageModuleApi {
opid?: string
) => Promise<BaseResponse<MessageItem>>;
createFileMessageByUrl: (
params: FileMsgByUrlParams,
params: FileMsgParamsByURL,
opid?: string
) => Promise<BaseResponse<MessageItem>>;
sendMessage: (
@@ -520,15 +524,15 @@ export interface MessageModuleApi {
opid?: string
) => Promise<BaseResponse<void>>;
revokeMessage: (
params: OpreateMessageParams,
params: AccessMessageParams,
opid?: string
) => Promise<BaseResponse<void>>;
deleteMessage: (
params: OpreateMessageParams,
params: AccessMessageParams,
opid?: string
) => Promise<BaseResponse<void>>;
deleteMessageFromLocalStorage: (
params: OpreateMessageParams,
params: AccessMessageParams,
opid?: string
) => Promise<BaseResponse<void>>;
deleteAllMsgFromLocal: (opid?: string) => Promise<BaseResponse<void>>;

View File

@@ -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<BaseResponse<void>>((resolve, reject) => {
openIMSDK.libOpenIMSDK.set_self_info(
openIMSDK.baseCallbackWrap<void>(resolve, reject),
@@ -84,7 +87,7 @@ export function setupUserModule(openIMSDK: OpenIMSDK) {
export interface UserModuleApi {
getSelfUserInfo: (opid?: string) => Promise<BaseResponse<SelfUserInfo>>;
setSelfInfo: (
params: SetSelfInfoParams,
params: PartialUserItem,
opid?: string
) => Promise<BaseResponse<void>>;
getUsersInfoWithCache: (

159
src/render.ts Normal file
View File

@@ -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<typeof WasmGetSDK>;
type IMSDKInterface = Omit<WasmInterface, 'login'> & {
login: (
params: Partial<InitAndLoginConfig>,
operationID?: string
) => Promise<WsResponse>;
/**
* @access only for electron
*/
initSDK: (param: InitConfig, opid?: string) => Promise<boolean>;
/**
* @access only for electron
*/
createImageMessage: (
imagePath: string,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createImageMessageFromFullPath: (
imagePath: string,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createVideoMessage: (
params: VideoMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createVideoMessageFromFullPath: (
params: VideoMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createSoundMessage: (
params: SoundMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createSoundMessageFromFullPath: (
params: SoundMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createFileMessage: (
params: FileMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
/**
* @access only for electron
*/
createFileMessageFromFullPath: (
params: FileMsgByPathParams,
opid?: string
) => Promise<WsResponse<MessageItem>>;
};
type ElectronInvoke = (method: string, ...args: any[]) => Promise<WsResponse>;
type CreateElectronOptions = {
wasmConfig?: WasmPathConfig;
invoke?: ElectronInvoke;
};
let wasmSDK: IMSDKInterface | undefined;
const sdkEmitter = new Emitter();
// eslint-disable-next-line
const methodCache = new WeakMap<Function, any>();
async function createWasmSDK(wasmConfig?: WasmPathConfig): Promise<void> {
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<IMSDKInterface> = {
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),
};
}

View File

@@ -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<T = unknown> {
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<Omit<SelfUserInfo, 'userID'>>;
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[];
};

View File

@@ -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,
}

View File

@@ -1,792 +0,0 @@
/* eslint-disable @typescript-eslint/ban-types */
/// <reference types="node" />
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<T[P][0]>,
argTypes: ref.CoerceTypes<T[P][1]>,
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 LibraryDefinitionBase> = [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<T[P][0]>,
ref.UnderlyingTypes<T[P][1]>
>
: T[P][2] extends { varargs: true }
? VariadicForeignFunction<T[P][0], T[P][1]>
: T[P][2] extends { async: true }
? ForeignFunction<
ref.UnderlyingType<T[P][0]>,
ref.UnderlyingTypes<T[P][1]>
>['async']
: ForeignFunction<
ref.UnderlyingType<T[P][0]>,
ref.UnderlyingTypes<T[P][1]>
>;
};
/** 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<LibraryObjectDefinitionToLibraryDefinition<TDefinition>>;
/**
* @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<LibraryObjectDefinitionToLibraryDefinition<TDefinition>>;
/**
* @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<LibraryObjectDefinitionToLibraryDefinition<TDefinition>>;
/**
* @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<LibraryObjectDefinitionToLibraryDefinition<TDefinition>>;
/**
* @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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
> {
/** 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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
/** Get a `ForeignFunction` of this function type. */
toFunction(
buf: Buffer
): ForeignFunction<
ref.UnderlyingType<TReturnType>,
ref.UnderlyingTypes<TArgTypes>
>;
}
/** 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.CoerceType<TReturnType>, ref.CoerceTypes<TArgTypes>>;
new <
TReturnType extends ref.TypeLike,
TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker
>(
retType: TReturnType,
argTypes: TArgTypes,
abi?: number
): Function<ref.CoerceType<TReturnType>, ref.CoerceTypes<TArgTypes>>;
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.CoerceType<TReturnType>, ref.CoerceTypes<TArgTypes>>;
<
TReturnType extends ref.TypeLike,
TArgTypes extends ref.Type[] | ArgTypesInferenceMarker
>(
retType: TReturnType,
argTypes: TArgTypes,
abi?: number
): Function<ref.CoerceType<TReturnType>, ref.CoerceTypes<TArgTypes>>;
(retType: ref.TypeLike, argTypes: ref.TypeLike[], abi?: number): Function;
};
export interface ForeignFunction<TReturn = any, TArgs extends any[] = any[]> {
(...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<TReturnType>,
ref.UnderlyingTypes<TArgTypes>
>;
new <
TReturnType extends ref.TypeLike,
TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker
>(
ptr: Buffer,
retType: TReturnType,
argTypes: TArgTypes,
abi?: number
): ForeignFunction<
ref.UnderlyingType<TReturnType>,
ref.UnderlyingTypes<TArgTypes>
>;
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<TReturnType>,
ref.UnderlyingTypes<TArgTypes>
>;
<
TReturnType extends ref.TypeLike,
TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker
>(
ptr: Buffer,
retType: TReturnType,
argTypes: TArgTypes,
abi?: number
): ForeignFunction<
ref.UnderlyingType<TReturnType>,
ref.UnderlyingTypes<TArgTypes>
>;
(
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.
<A extends ref.NamedTypeLike[]>(...args: A): ForeignFunction<
ref.UnderlyingType<TReturnType>,
[...ref.UnderlyingTypes<TArgTypes>, ...ref.UnderlyingTypes<A>]
>;
/**
* 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.
*/
<A extends ref.TypeLike[]>(...args: A): ForeignFunction<
ref.UnderlyingType<TReturnType>,
[...ref.UnderlyingTypes<TArgTypes>, ...ref.UnderlyingTypes<A>]
>;
/**
* 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<TReturnType>,
ref.CoerceTypes<TArgTypes>
>;
new <
TReturnType extends ref.TypeLike,
TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker
>(
ptr: Buffer,
ret: TReturnType,
fixedArgs: TArgTypes,
abi?: number
): VariadicForeignFunction<
ref.CoerceType<TReturnType>,
ref.CoerceTypes<TArgTypes>
>;
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<TReturnType>,
ref.CoerceTypes<TArgTypes>
>;
<
TReturnType extends ref.TypeLike,
TArgTypes extends ref.TypeLike[] | ArgTypesInferenceMarker
>(
ptr: Buffer,
ret: TReturnType,
fixedArgs: TArgTypes,
abi?: number
): VariadicForeignFunction<
ref.CoerceType<TReturnType>,
ref.CoerceTypes<TArgTypes>
>;
(
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<unknown>;
const RTLD_DEFAULT: ref.Pointer<unknown>;
const RTLD_SELF: ref.Pointer<unknown> | undefined; // not defined on Windows
const RTLD_MAIN_ONLY: ref.Pointer<unknown> | 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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
new <TReturnType extends ref.TypeLike, TArgTypes extends ref.TypeLike[]>(
retType: TReturnType,
argTypes: TArgTypes,
abi: number,
fn: (
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
// 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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
new <TReturnType extends ref.TypeLike, TArgTypes extends ref.TypeLike[]>(
retType: TReturnType,
argTypes: TArgTypes,
fn: (
...ags: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
<TReturnType extends ref.TypeLike, TArgTypes extends ref.TypeLike[]>(
retType: TReturnType,
argTypes: TArgTypes,
abi: number,
fn: (
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
// 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<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
<TReturnType extends ref.TypeLike, TArgTypes extends ref.TypeLike[]>(
retType: TReturnType,
argTypes: TArgTypes,
fn: (
...ags: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
): ref.Pointer<
(
...args: ref.UnderlyingTypes<TArgTypes>
) => ref.UnderlyingType<TReturnType>
>;
(
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<FFI_TYPE>;
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<ref.Pointer<PFFI_TYPE>>;
}>;
type FFI_TYPE = ReturnType<typeof FFI_TYPE>;
}
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<FFI_TYPE>;
// 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;
}

View File

@@ -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,

View File

@@ -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<SelfUserInfo>;
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<GroupItem>;
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<GroupItem> & { 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;
};

View File

@@ -1,4 +1,4 @@
import { CbEvents } from '@/constant/callback';
import { CbEvents } from 'open-im-sdk-wasm';
interface Events {
[key: string]: Cbfn[];