{"_id":"@4nathan/electron-client-sdk","name":"@4nathan/electron-client-sdk","dist-tags":{"latest":"1.1.4"},"versions":{"1.1.4":{"name":"@4nathan/electron-client-sdk","version":"1.1.4","description":"open im sdk for node","source":"src/index.ts","main":"lib/index.js","module":"lib/index.es.js","types":"lib/index.d.ts","scripts":{"build":"rimraf lib && rollup -c && tsc-alias","cm":"cz","lint":"eslint ./src/ --fix","prepare":"husky install","semantic-release":"semantic-release","test:watch":"jest --watch","test":"jest --coverage","typecheck":"tsc --noEmit"},"repository":{"type":"git","url":"git+https://github.com/nathan-club/openim-sdk-electron.git"},"license":"MIT","author":{"name":"nathan","email":"yes@4nathan.com","url":"https://github.com/nathan-club"},"engines":{"node":">=12.0"},"keywords":["openim"],"bugs":{"url":"https://github.com/OpenIMSDK/openim-sdk-electron/issues"},"homepage":"https://github.com/OpenIMSDK/openim-sdk-electron#readme","devDependencies":{"@commitlint/cli":"^16.2.4","@commitlint/config-conventional":"^16.2.4","@openim/wasm-client-sdk":"^3.8.2-1","@rollup/plugin-alias":"^5.1.0","@rollup/plugin-terser":"^0.4.4","@types/ffi-napi":"^4.0.10","@types/node":"^12.20.55","@types/uuid":"^8.3.4","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","conventional-changelog-conventionalcommits":"^5.0.0","electron":"^29.2.0","eslint":"^7.25.0","eslint-config-prettier":"^8.3.0","eslint-plugin-node":"^11.1.0","eslint-plugin-prettier":"^3.4.0","husky":"^6.0.0","jest":"^27.2.0","lint-staged":"^10.5.4","prettier":"^2.2.1","rollup":"^2.79.1","rollup-plugin-typescript2":"^0.36.0","semantic-release":"^19.0.2","tsc-alias":"^1.7.0","typescript":"^4.2.4"},"config":{"commitizen":{"path":"./node_modules/@commitlint/cz-conventional-changelog"}},"lint-staged":{"*.ts":"eslint --cache --cache-location .eslintcache --fix"},"dependencies":{"koffi":"2.8.0","uuid":"^9.0.0"},"peerDependencies":{"@openim/wasm-client-sdk":"^3.8.2-1","electron":">=12.0.0"},"_id":"@4nathan/electron-client-sdk@1.1.4","gitHead":"fd024fe39fad2eb1bf7f91c97963a2345be4e3a2","_nodeVersion":"20.19.3","_npmVersion":"10.8.2","dist":{"integrity":"sha512-DSMgUSecxTHzokqdJykA7EQk6hjWAJCjSbzVuNcf9KZb1Map9mS3WwDFih9owaNKb5t2cLgAirPaJwUXLuWJ5w==","shasum":"c54a87545a32ead3187f75255ded9635a4640bb4","tarball":"https://registry.npmjs.org/@4nathan/electron-client-sdk/-/electron-client-sdk-1.1.4.tgz","fileCount":32,"unpackedSize":131080268,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCe4/8driAGGfVMN/2iZT5srqJlfVP+dLBhm4xIHEry2gIgYyhVQA9mJkj3OkSPDgnUwSFOpCOnFsaXrFoxWfYuDQc="}]},"_npmUser":{"name":"4nathan","email":"yes@4nathan.com"},"directories":{},"maintainers":[{"name":"4nathan","email":"yes@4nathan.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/electron-client-sdk_1.1.4_1752424688303_0.20246499276316143"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-13T16:38:08.241Z","1.1.4":"2025-07-13T16:38:09.037Z","modified":"2025-07-13T16:38:09.273Z"},"maintainers":[{"name":"4nathan","email":"yes@4nathan.com"}],"description":"open im sdk for node","homepage":"https://github.com/OpenIMSDK/openim-sdk-electron#readme","keywords":["openim"],"repository":{"type":"git","url":"git+https://github.com/nathan-club/openim-sdk-electron.git"},"author":{"name":"nathan","email":"yes@4nathan.com","url":"https://github.com/nathan-club"},"bugs":{"url":"https://github.com/OpenIMSDK/openim-sdk-electron/issues"},"license":"MIT","readme":"# Electron Client SDK for OpenIM 👨‍💻💬\n\nUse this SDK to add instant messaging capabilities to your application. By connecting to a self-hosted [OpenIM](https://www.openim.online/) server, you can quickly integrate instant messaging capabilities into your app with just a few lines of code.\n\nThe underlying SDK core is implemented in [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core). Using cgo, it is exported as C interfaces and provided as dynamic libraries such as DLL, SO, and DYLIB for use by other languages, implemented in [OpenIM SDK Cpp](https://github.com/openimsdk/openim-sdk-cpp.git).The electron interacts with the [OpenIM SDK Cpp](https://github.com/openimsdk/openim-sdk-cpp.git) through JSON, using FFI (Foreign Function Interface) to communicate with the C interfaces, and the SDK exposes a re-encapsulated API for easy usage. For data storage, it utilizes the SQLite layer that is provided internally by the [OpenIM SDK Core](https://github.com/openimsdk/openim-sdk-core).\n\n## Documentation 📚\n\nVisit [https://docs.openim.io/](https://docs.openim.io/) for detailed documentation and guides.\n\nFor the SDK reference, see [https://docs.openim.io/sdks/quickstart/electron](https://docs.openim.io/sdks/quickstart/electron).\n\n## Installation 💻\n\n### Adding Dependencies\n\n```shell\nnpm install @openim/wasm-client-sdk @openim/electron-client-sdk --save\n```\n\n### Obtaining Required Static Resources for WASM\n\nFollow these steps to obtain the static resources required for WebAssembly (WASM):\n\n1. Locate the `@openim/wasm-client-sdk` subdirectory in the `node_modules` directory of your project. Copy all the files in the `assets` folder to your project's public resource directory.\n\n   The files to be copied are:\n\n   - `openIM.wasm`\n   - `sql-wasm.wasm`\n   - `wasm_exec.js`\n\n2. After copying the files, import the `wasm_exec.js` file in your `index.html` file using a `<script>` tag.\n\n### Possible Issues ❗\n\n> if you are using webpack4, you may flow this issue [How to import @openim/wasm-client-sdk in webpack4.x](https://github.com/openimsdk/open-im-sdk-web-wasm/issues/73).\n\n## Usage 🚀\n\nThe following examples demonstrate how to use the SDK. TypeScript is used, providing complete type hints.\n\n### Importing the SDK\n\n## In main process\n\n```typescript\nimport OpenIMSDKMain from '@openim/electron-client-sdk';\n\n...\nnew OpenIMSDKMain(libPath, mainWindow.webContents);\n...\n```\n\n## In preload script\n\n```typescript\nimport '@openim/electron-client-sdk/lib/preload';\n```\n\n## In renderer process\n\n```typescript\nimport { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';\n\nconst { instance } = getWithRenderProcess();\n\nexport const IMSDK = instance;\n```\n\n### Logging In and Listening for Connection Status\n\n> Note: You need to [deploy](https://github.com/openimsdk/open-im-server#rocket-quick-start) OpenIM Server first, the default port of OpenIM Server is 10001, 10002.\n\n```typescript\nimport { CbEvents, LogLevel } from '@openim/wasm-client-sdk';\nimport type { WSEvent } from '@openim/wasm-client-sdk/lib/types/entity';\n\nIMSDK.on(CbEvents.OnConnecting, handleConnecting);\nIMSDK.on(CbEvents.OnConnectFailed, handleConnectFailed);\nIMSDK.on(CbEvents.OnConnectSuccess, handleConnectSuccess);\n\n// electron\nawait IMSDK.initSDK({\n  platformID: 'your-platform-id',\n  apiAddr: 'http://your-server-ip:10002',\n  wsAddr: 'ws://your-server-ip:10001',\n  dataDir: 'your-db-dir',\n  logFilePath: 'your-log-file-path',\n  logLevel: LogLevel.Debug,\n  isLogStandardOutput: true,\n});\n\nawait IMSDK.login({\n  userID: 'your-user-id',\n  token: 'your-token',\n});\n\n// web\nawait IMSDK.login({\n  userID: 'your-user-id',\n  token: 'your-token',\n  platformID: 5,\n  apiAddr: 'http://your-server-ip:10002',\n  wsAddr: 'ws://your-server-ip:10001',\n  logLevel: LogLevel.Debug,\n});\n\nfunction handleConnecting() {\n  // Connecting...\n}\n\nfunction handleConnectFailed({ errCode, errMsg }: WSEvent) {\n  // Connection failed ❌\n  console.log(errCode, errMsg);\n}\n\nfunction handleConnectSuccess() {\n  // Connection successful ✅\n}\n```\n\nTo log into the IM server, you need to create an account and obtain a user ID and token. Refer to the [access token documentation](https://docs.openim.io/restapi/userManagement/userRegister) for details.\n\n### Receiving and Sending Messages 💬\n\nOpenIM makes it easy to send and receive messages. By default, there is no restriction on having a friend relationship to send messages (although you can configure other policies on the server). If you know the user ID of the recipient, you can conveniently send a message to them.\n\n```typescript\nimport { CbEvents } from '@openim/wasm-client-sdk';\nimport type {\n  WSEvent,\n  MessageItem,\n} from '@openim/wasm-client-sdk/lib/types/entity';\n\n// Listenfor new messages 📩\nIMSDK.on(CbEvents.OnRecvNewMessages, handleNewMessages);\n\nconst message = (await IMSDK.createTextMessage('hello openim')).data;\n\nIMSDK.sendMessage({\n  recvID: 'recv user id',\n  groupID: '',\n  message,\n})\n  .then(() => {\n    // Message sent successfully ✉️\n  })\n  .catch(err => {\n    // Failed to send message ❌\n    console.log(err);\n  });\n\nfunction handleNewMessages({ data }: WSEvent<MessageItem[]>) {\n  // New message list 📨\n  console.log(data);\n}\n```\n\n## Examples 🌟\n\nYou can find a demo web app that uses the SDK in the [openim-pc-web-demo](https://github.com/openimsdk/open-im-pc-web-demo) repository.\n\n## Community :busts_in_silhouette:\n\n- 📚 [OpenIM Community](https://github.com/OpenIMSDK/community)\n- 💕 [OpenIM Interest Group](https://github.com/Openim-sigs)\n- 🚀 [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-2ijy1ys1f-O0aEDCr7ExRZ7mwsHAVg9A)\n- :eyes: [Join our wechat (微信群)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg)\n\n## Community Meetings :calendar:\n\nWe want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night.\n\nOur conference is in the [OpenIM Slack](https://join.slack.com/t/openimsdk/shared_invite/zt-2ijy1ys1f-O0aEDCr7ExRZ7mwsHAVg9A) 🎯, then you can search the Open-IM-Server pipeline to join\n\nWe take notes of each [biweekly meeting](https://github.com/orgs/OpenIMSDK/discussions/categories/meeting) in [GitHub discussions](https://github.com/openimsdk/open-im-server/discussions/categories/meeting), Our historical meeting notes, as well as replays of the meetings are available at [Google Docs :bookmark_tabs:](https://docs.google.com/document/d/1nx8MDpuG74NASx081JcCpxPgDITNTpIIos0DS6Vr9GU/edit?usp=sharing).\n\n## Who are using OpenIM :eyes:\n\nCheck out our [user case studies](https://github.com/OpenIMSDK/community/blob/main/ADOPTERS.md) page for a list of the project users. Don't hesitate to leave a [📝comment](https://github.com/openimsdk/open-im-server/issues/379) and share your use case.\n\n## License :page_facing_up:\n\nThis software is licensed under a dual-license model:\n\n- The GNU Affero General Public License (AGPL), Version 3 or later; **OR**\n- Commercial license terms from OpenIMSDK.\n\nIf you wish to use this software under commercial terms, please contact us at: contact@openim.io\n\nFor more information, see: https://www.openim.io/en/licensing\n\n\n\n","readmeFilename":"README.md","_rev":"1-2f18d5515d287f8a3a39b800f8d63942"}