Skip to content

nim.client.NIMClient

Zvicii edited this page Jul 11, 2022 · 6 revisions

Class: NIMClient

nim/client.NIMClient

Hierarchy

Table of contents

Methods

Properties

Constructors

Methods

eventNames

eventNames(): keyof NIMClientEvents[]

Return an array listing the events for which the emitter has registered listeners.

Returns

keyof NIMClientEvents[]

Inherited from

EventEmitter.eventNames


listeners

listeners<T>(event): (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void[]

Return the listeners registered for a given event.

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T

Returns

(...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void[]

Inherited from

EventEmitter.listeners


listenerCount

listenerCount(event): number

Return the number of listeners listening to a given event.

Parameters

Name Type
event keyof NIMClientEvents

Returns

number

Inherited from

EventEmitter.listenerCount


emit

emit<T>(event, ...args): boolean

Calls each of the listeners registered for a given event.

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
...args ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]

Returns

boolean

Inherited from

EventEmitter.emit


on

on<T>(event, fn, context?): NIMClient

Add a listener for a given event.

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
fn (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void
context? any

Returns

NIMClient

Inherited from

EventEmitter.on


addListener

addListener<T>(event, fn, context?): NIMClient

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
fn (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void
context? any

Returns

NIMClient

Inherited from

EventEmitter.addListener


once

once<T>(event, fn, context?): NIMClient

Add a one-time listener for a given event.

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
fn (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void
context? any

Returns

NIMClient

Inherited from

EventEmitter.once


removeListener

removeListener<T>(event, fn?, context?, once?): NIMClient

Remove the listeners of a given event.

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
fn? (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void
context? any
once? boolean

Returns

NIMClient

Inherited from

EventEmitter.removeListener


off

off<T>(event, fn?, context?, once?): NIMClient

Type parameters

Name Type
T extends keyof NIMClientEvents

Parameters

Name Type
event T
fn? (...args: ArgumentMap<NIMClientEvents>[Extract<T, keyof NIMClientEvents>]) => void
context? any
once? boolean

Returns

NIMClient

Inherited from

EventEmitter.off


removeAllListeners

removeAllListeners(event?): NIMClient

Remove all listeners, or those of the specified event.

Parameters

Name Type
event? keyof NIMClientEvents

Returns

NIMClient

Inherited from

EventEmitter.removeAllListeners


init

init(appKey, appDataDir, appInstallDir, config): boolean

NIM SDK初始化

Parameters

Name Type Description
appKey string 应用注册的APP KEY
appDataDir string 推荐用户目录放置在系统目录AppData\Local,默认只需要传入目录名,SDK会默认在系统目录下创建该级用户目录。如果要使用其他自定义路径,需传入绝对路径路径,并确保该目录有正确的读写权限。
appInstallDir string SDK动态库所在的目录全路径(如果传入为空,则按照默认规则搜索该动态库)
config SDKConfig 初始化参数

Returns

boolean

bool 返回值true: 成功, false: 失败


initEventHandlers

initEventHandlers(): void

注册全局回调

Returns

void


login

login(appKey, account, password, cb, jsonExtension): boolean

NIM客户端登录

Note

200:成功
302:账号或密码错误
403:禁止操作
408:请求超时
414:参数错误
415:网络连接出现错误
416:频率超限
422:账号被禁用

Parameters

Name Type Description
appKey string
account string 帐号
password string 密码
cb LoginCallback 登录流程的回调函数
jsonExtension string json扩展参数(v5.7.0 项目增加自定义参数字段)

Returns

boolean

bool 检查参数如果不符合要求则返回失败


logout

logout(logoutType, cb, jsonExtension): void

NIM客户端注销/退出

Note

200:成功
500:未知错误

Parameters

Name Type Description
logoutType NIMLogoutType Logout操作类型,其定义见nim_client_def.h
cb LogoutCallback 注销/退出的回调函数
jsonExtension string json扩展参数(备用,目前不需要)

Returns

void

void 无返回值


cleanup

cleanup(jsonExtension): void

NIM SDK清理

Parameters

Name Type Description
jsonExtension string json扩展参数(备用,目前不需要)

Returns

void

void 无返回值


getSDKConfig

getSDKConfig(): SDKConfig

获取SDK配置

Returns

SDKConfig

SDKConfig 返回值SDKConfig的引用 const类型,不可试图修改


getLoginState

getLoginState(jsonExtension): NIMLoginState

获取客户端登录状态

Parameters

Name Type Description
jsonExtension string json扩展参数(备用,目前不需要)

Returns

NIMLoginState

NIMLoginState 登录状态


relogin

relogin(jsonExtension): void

NIM客户端手动重连(注意 APP需要统一处理自动重连/手动重连的回调,因为如果处于某次自动重连的过程中调用手动重连接口,不起作用!)

Parameters

Name Type Description
jsonExtension string json扩展参数(备用,目前不需要)

Returns

void

void 无返回值


kickOtherClient

kickOtherClient(clients): void

将本帐号的其他端踢下线

Parameters

Name Type Description
clients string[] 设备标识

Returns

void

bool 检查参数如果不符合要求则返回失败, 接口调用成功后的结果通过注册RegKickOtherClientCb回调得到


setMultiportPushConfigAsync

setMultiportPushConfigAsync(switch_on, cb, jsonExtension): void

(全局回调)设置多端推送

Note

200:成功

Parameters

Name Type Description
switch_on boolean 开关
cb MultiportPushConfigCallback 回调函数
jsonExtension string json扩展参数(备用,目前不需要)

Returns

void

void


getMultiportPushConfigAsync

getMultiportPushConfigAsync(cb, jsonExtension): void

获得多端推送设置

Parameters

Name Type Description
cb MultiportPushConfigCallback 回调函数
jsonExtension string json扩展参数(备用,目前不需要)

Returns

void

void


getSDKVersion

getSDKVersion(): string

获取SDK版本号

Returns

string

string 版本号


getServerCurrentTime

getServerCurrentTime(cb, calcLocal): void

获取当前服务器时间

Note

由于网络上/下行的原因,返回的时间会存在一定误差,
当 calc_local == false 时,如果跟上次调用该方法的时间间隔小于1000ms,SDK会采用 calc_local == true
时的方案以减少服务端的压力,并会在回调中指明返回的时间是由本地计算的。 如果返回 code != 200,同样会返回一个本地计算结果

Parameters

Name Type Description
cb GetCurrentServerTimeCallback 操作结果的回调函数
calcLocal boolean -

Returns

void

void


getCurrentUserAccount

getCurrentUserAccount(): string

获取当前登录的用户账号(accid)

Note

没有登录时将返回空字符串

Returns

string

string 当前登录的用户账号(accid)

Properties

client

client: NIMClientAPI

Defined in

ts/nim/client.ts:34

Constructors

constructor

new NIMClient()

Overrides

EventEmitter<NIMClientEvents&gt;.constructor

Clone this wiki locally