Skip to content
Zvicii edited this page Oct 28, 2021 · 11 revisions

NetEase IM Node.js addon wrapper

GitHub Test Badge codecov GitHub all releases

Table of Contents

Build Environment

If you are using node-nim under node enviroment or electron lower than 12.x.y, you will need the following tools to build addon locally, see here.

Installation

node-nim runs on Node.js and is available as a NPM package.

npm install node-nim --save-dev

Unit Test

Execute following script to run unit test, check this, and you can also get an coverage report under 'coverage'.

npm run coverage

Quick Start

const NIM = require('node-nim')
const assert = require('assert')

const result = NIM.Client.init('app_key', 'app_data_dir', 'app_install_dir', {
    db_encrypt_key: 'abcdefghijklmnopqrstuvwxyz012345'
})

NIM.Client.login('app_key', 'username', 'password_in_md5', (result) => {
    assert.strictEqual(result.err_code, 200)
}, '')

NIM.Talk.initEventHandler() // init callbacks

NIM.Talk.on('onReceiveMsg', function (result) {
    console.log(result)
})

NIM.Talk.sendMsg({
    to_type: 0, // p2p
    to_accid: 'receiver_accid',
    time: new Date().getTime(),
    msg_type: 0, // text message
    msg_body: 'Send from NIM node quick start.',
    client_msg_id: new Date().getTime().toString(), // use an uuid
}, '', function () { })

NIM.Client.logout(1, (err_code) => {
    assert.strictEqual(err_code, 200)
}, '')

NIM.Client.cleanUp('')

Documentation

For more detailed documentation, the changelog, and tech support, see https://dev.yunxin.163.com/.

Build From Source

Script 'install' will build addon from source automatically if downloading pre-built addon from yunxin server failed(bad connection/lack of certain version/etc). You can also build addon manully, just type in the following command and run.

npm run build
Clone this wiki locally