Platform | Version |
Electron | v13.1.5 or later |
Node.js | v14.2.0 |
Integration Scheme | Applicable Scenario |
Using a demo | The Chat demo includes all chat features and provides open-source code. If you need to implement chat scenarios, you can use the demo for secondary development. Try it out here. |
Self implementation | Implement Chat on your own if the demo does not meet your UI requirements. |
git clone https://github.com/TencentCloud/tc-chat-demo-electron.git
// Root directory of the projectnpm install// Rendering process directorycd src/clientnpm install
// Root directory of the projectnpm start
// Build the project in macOSnpm run build:mac// Build the project in Windowsnpm run build:windows
src/app/main.js
, and the rendering process directory is src/client
. If any problem occurs during running, see the FAQs for troubleshooting first.npm install im_electron_sdk
sdkAppID
in TimMain
.// Main processconst TimMain = require('im_electron_sdk/dist/main')const sdkappid = 0;// You can apply for it in the Chat console.const tim = new TimMain({sdkappid:sdkappid})
TIMInit
to initialize the SDK.// Rendering processconst TimRender = require('im_electron_sdk/dist/render')const timRender = new TimRender();// Initialize the componenttimRender.TIMInit()
timRender.TIMLogin
method to log in as the test user.
If the returned code
is 0
, the login is successful.const TimRender = require('im_electron_sdk/dist/render')const timRender = new TimRender();let {code} = await timRender.TIMLogin({userID:"userID",userSig:"userSig" // See how to generate a userSig})
UserSig
distribution method is to integrate the calculation code of UserSig
into your server and provide an application-oriented API. When UserSig
is needed, your application can send a request to the business server for a dynamic UserSig
. For more information, see Generating UserSig.code
is 0
, the message is sent successfully.
Sample code:const TimRender = require('im_electron_sdk/dist/render')const timRender = new TimRender();let param:MsgSendMessageParamsV2 = { // param of TIMMsgSendMessageconv_id: "conv_id",conv_type: 1,params: {message_elem_array: [{elem_type: 1,text_elem_content:'Hello Tencent!',}],message_sender: "senderID",},callback: (data) => {}}let {code} = await timRender.TIMMsgSendMessageV2(param);
sdkAppID
does not support sending messages to strangers. In this case, you can disable the friend relationship chain check in the console for testing.let param:getConvList = {userData:userData,}let data:commonResult<convInfo[]> = await timRenderInstance.TIMConvGetConvList(param)
let param:MsgGetMsgListParams = {conv_id: conv_id,conv_type: conv_type,params: {msg_getmsglist_param_last_msg: msg,msg_getmsglist_param_count: 20,msg_getmsglist_param_is_remble: true,},user_data: user_data}let msgList:commonResult<Json_value_msg[]> = await timRenderInstance.TIMMsgGetMsgList(param);
let param : TIMRecvNewMsgCallbackParams = {callback: (...args)=>{},user_data: user_data}timRenderInstance.TIMAddRecvNewMsgCallback(param);
npm ERR! gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
is reported during development environment installation?gypgyp ERR!ERR
is reported during development environment installation?npm ERR! Fix the upstream dependency conflict, or retry
is reported when npm install
is run?npm install --force
Error: error:0308010C:digital envelope routines::unsupported
is reported when npm run start
is run?npm run start
on a macOS client demo?cd src/client && npm run dev:react
and npm run dev:electron
to start the rendering process and main process separately.extraFiles:[{"from": "./node_modules/im_electron_sdk/lib/","to": "./Resources","filter": ["**/*"]}]
__dirname is not defined
when using electron-vite?preload
for use. The code for Main process should be written in main process normally. For details, please refer to electron-vite documentation.//The content of the main process is written to the main process// main/index.ts (example path)const TimMain = require('im_electron_sdk/dist/main')const sdkappid = 0;const tim = new TimMain({sdkappid:sdkappid})// Use chat sdk in preload// preload/index.ts (example path)import TimRender from 'im_electron_sdk/dist/renderer'const timRender = new TimRender();
Was this page helpful?