Skip to content

nim.client.NIMClient

Zvicii edited this page Feb 10, 2023 · 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

Defined in

node_modules/eventemitter3/index.d.ts:15


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

Defined in

node_modules/eventemitter3/index.d.ts:20


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

Defined in

node_modules/eventemitter3/index.d.ts:27


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

Defined in

node_modules/eventemitter3/index.d.ts:32


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

Defined in

node_modules/eventemitter3/index.d.ts:40


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

Defined in

node_modules/eventemitter3/index.d.ts:45


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

Defined in

node_modules/eventemitter3/index.d.ts:54


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

Defined in

node_modules/eventemitter3/index.d.ts:63


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

Defined in

node_modules/eventemitter3/index.d.ts:69


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

Defined in

node_modules/eventemitter3/index.d.ts:79


initEventHandlers

initEventHandlers(): void

注册全局回调

Returns

void

Defined in

ts/nim/client.ts:43


init

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

NIM SDK初始化

Parameters

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

Returns

boolean

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

Defined in

ts/nim/client.ts:54


login

login(appKey, account, password, cb, jsonExtension): Promise<[LoginRes]>

NIM客户端登录

Note

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

Parameters

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

Returns

Promise<[LoginRes]>

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

Defined in

ts/nim/client.ts:77


logout

logout(logoutType, cb, jsonExtension): Promise<[NIMResCode]>

NIM客户端注销/退出

Note

200:成功
500:未知错误

Parameters

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

Returns

Promise<[NIMResCode]>

void 无返回值

Defined in

ts/nim/client.ts:107


cleanup

cleanup(jsonExtension): void

NIM SDK清理

Parameters

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

Returns

void

void 无返回值

Defined in

ts/nim/client.ts:126


getSDKConfig

getSDKConfig(): SDKConfig

获取SDK配置

Returns

SDKConfig

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

Defined in

ts/nim/client.ts:133


getLoginState

getLoginState(jsonExtension): NIMLoginState

获取客户端登录状态

Parameters

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

Returns

NIMLoginState

NIMLoginState 登录状态

Defined in

ts/nim/client.ts:141


relogin

relogin(jsonExtension): void

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

Parameters

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

Returns

void

void 无返回值

Defined in

ts/nim/client.ts:149


kickOtherClient

kickOtherClient(clients): void

将本帐号的其他端踢下线

Parameters

Name Type Description
clients string[] 设备标识

Returns

void

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

Defined in

ts/nim/client.ts:157


setMultiportPushConfigAsync

setMultiportPushConfigAsync(switch_on, cb, jsonExtension): Promise<[NIMResCode, boolean]>

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

Note

200:成功

Parameters

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

Returns

Promise<[NIMResCode, boolean]>

void

Defined in

ts/nim/client.ts:171


getMultiportPushConfigAsync

getMultiportPushConfigAsync(cb, jsonExtension): Promise<[NIMResCode, boolean]>

获得多端推送设置

Parameters

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

Returns

Promise<[NIMResCode, boolean]>

void

Defined in

ts/nim/client.ts:191


getSDKVersion

getSDKVersion(): string

获取SDK版本号

Returns

string

string 版本号

Defined in

ts/nim/client.ts:205


getServerCurrentTime

getServerCurrentTime(cb, calcLocal): Promise<[number, boolean, number]>

获取当前服务器时间

Note

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

Parameters

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

Returns

Promise<[number, boolean, number]>

void

Defined in

ts/nim/client.ts:220


getCurrentUserAccount

getCurrentUserAccount(): string

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

Note

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

Returns

string

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

Defined in

ts/nim/client.ts:234

Properties

client

client: NIMClientAPI

Defined in

ts/nim/client.ts:36

Constructors

constructor

new NIMClient()

Overrides

EventEmitter<NIMClientEvents&gt;.constructor

Defined in

ts/nim/client.ts:37

Clone this wiki locally