-
Notifications
You must be signed in to change notification settings - Fork 2
nim.client.NIMClient
nim/client.NIMClient
-
EventEmitter
<NIMClientEvents
>↳
NIMClient
- eventNames
- listeners
- listenerCount
- emit
- on
- addListener
- once
- removeListener
- off
- removeAllListeners
- initEventHandlers
- init
- login
- logout
- cleanup
- getSDKConfig
- getLoginState
- relogin
- kickOtherClient
- setMultiportPushConfigAsync
- getMultiportPushConfigAsync
- getSDKVersion
- getServerCurrentTime
- getCurrentUserAccount
▸ eventNames(): keyof NIMClientEvents
[]
Return an array listing the events for which the emitter has registered listeners.
keyof NIMClientEvents
[]
EventEmitter.eventNames
node_modules/eventemitter3/index.d.ts:15
▸ listeners<T
>(event
): (...args
: ArgumentMap
<NIMClientEvents
>[Extract
<T
, keyof NIMClientEvents
>]) => void
[]
Return the listeners registered for a given event.
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
(...args
: ArgumentMap
<NIMClientEvents
>[Extract
<T
, keyof NIMClientEvents
>]) => void
[]
EventEmitter.listeners
node_modules/eventemitter3/index.d.ts:20
▸ listenerCount(event
): number
Return the number of listeners listening to a given event.
Name | Type |
---|---|
event |
keyof NIMClientEvents
|
number
EventEmitter.listenerCount
node_modules/eventemitter3/index.d.ts:27
▸ emit<T
>(event
, ...args
): boolean
Calls each of the listeners registered for a given event.
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
...args |
ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >] |
boolean
EventEmitter.emit
node_modules/eventemitter3/index.d.ts:32
▸ on<T
>(event
, fn
, context?
): NIMClient
Add a listener for a given event.
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
fn |
(...args : ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >]) => void
|
context? |
any |
EventEmitter.on
node_modules/eventemitter3/index.d.ts:40
▸ addListener<T
>(event
, fn
, context?
): NIMClient
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
fn |
(...args : ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >]) => void
|
context? |
any |
EventEmitter.addListener
node_modules/eventemitter3/index.d.ts:45
▸ once<T
>(event
, fn
, context?
): NIMClient
Add a one-time listener for a given event.
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
fn |
(...args : ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >]) => void
|
context? |
any |
EventEmitter.once
node_modules/eventemitter3/index.d.ts:54
▸ removeListener<T
>(event
, fn?
, context?
, once?
): NIMClient
Remove the listeners of a given event.
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
fn? |
(...args : ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >]) => void
|
context? |
any |
once? |
boolean |
EventEmitter.removeListener
node_modules/eventemitter3/index.d.ts:63
▸ off<T
>(event
, fn?
, context?
, once?
): NIMClient
Name | Type |
---|---|
T |
extends keyof NIMClientEvents
|
Name | Type |
---|---|
event |
T |
fn? |
(...args : ArgumentMap <NIMClientEvents >[Extract <T , keyof NIMClientEvents >]) => void
|
context? |
any |
once? |
boolean |
EventEmitter.off
node_modules/eventemitter3/index.d.ts:69
▸ removeAllListeners(event?
): NIMClient
Remove all listeners, or those of the specified event.
Name | Type |
---|---|
event? |
keyof NIMClientEvents
|
EventEmitter.removeAllListeners
node_modules/eventemitter3/index.d.ts:79
▸ initEventHandlers(): void
注册全局回调
void
ts/nim/client.ts:43
▸ init(appKey
, appDataDir
, appInstallDir
, config
): boolean
NIM SDK初始化
Name | Type | Description |
---|---|---|
appKey |
string |
应用注册的APP KEY |
appDataDir |
string |
推荐用户目录放置在系统目录AppData\Local,默认只需要传入目录名,SDK会默认在系统目录下创建该级用户目录。如果要使用其他自定义路径,需传入绝对路径路径,并确保该目录有正确的读写权限。 |
appInstallDir |
string |
Deprecated |
config |
SDKConfig |
初始化参数 |
boolean
bool 返回值true: 成功, false: 失败
ts/nim/client.ts:54
▸ login(appKey
, account
, password
, cb
, jsonExtension
): Promise
<[LoginRes
]>
NIM客户端登录
Note
200:成功 302:账号或密码错误 403:禁止操作 408:请求超时 414:参数错误 415:网络连接出现错误 416:频率超限 422:账号被禁用
Name | Type | Description |
---|---|---|
appKey |
string |
|
account |
string |
帐号 |
password |
string |
密码 |
cb |
null | LoginCallback
|
登录流程的回调函数 |
jsonExtension |
string |
json扩展参数(v5.7.0 项目增加自定义参数字段) |
Promise
<[LoginRes
]>
bool 检查参数如果不符合要求则返回失败
ts/nim/client.ts:77
▸ logout(logoutType
, cb
, jsonExtension
): Promise
<[NIMResCode
]>
NIM客户端注销/退出
Note
200:成功 500:未知错误
Name | Type | Description |
---|---|---|
logoutType |
NIMLogoutType |
Logout操作类型,其定义见nim_client_def.h |
cb |
null | LogoutCallback
|
注销/退出的回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
Promise
<[NIMResCode
]>
void 无返回值
ts/nim/client.ts:107
▸ cleanup(jsonExtension
): void
NIM SDK清理
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void 无返回值
ts/nim/client.ts:126
▸ getSDKConfig(): SDKConfig
获取SDK配置
SDKConfig 返回值SDKConfig的引用 const类型,不可试图修改
ts/nim/client.ts:133
▸ getLoginState(jsonExtension
): NIMLoginState
获取客户端登录状态
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
NIMLoginState 登录状态
ts/nim/client.ts:141
▸ relogin(jsonExtension
): void
NIM客户端手动重连(注意 APP需要统一处理自动重连/手动重连的回调,因为如果处于某次自动重连的过程中调用手动重连接口,不起作用!)
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void 无返回值
ts/nim/client.ts:149
▸ kickOtherClient(clients
): void
将本帐号的其他端踢下线
Name | Type | Description |
---|---|---|
clients |
string [] |
设备标识 |
void
bool 检查参数如果不符合要求则返回失败, 接口调用成功后的结果通过注册RegKickOtherClientCb回调得到
ts/nim/client.ts:157
▸ setMultiportPushConfigAsync(switch_on
, cb
, jsonExtension
): Promise
<[NIMResCode
, boolean
]>
(全局回调)设置多端推送
Note
200:成功
Name | Type | Description |
---|---|---|
switch_on |
boolean |
开关 |
cb |
null | MultiportPushConfigCallback
|
回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
Promise
<[NIMResCode
, boolean
]>
void
ts/nim/client.ts:171
▸ getMultiportPushConfigAsync(cb
, jsonExtension
): Promise
<[NIMResCode
, boolean
]>
获得多端推送设置
Name | Type | Description |
---|---|---|
cb |
null | MultiportPushConfigCallback
|
回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
Promise
<[NIMResCode
, boolean
]>
void
ts/nim/client.ts:191
▸ getSDKVersion(): string
获取SDK版本号
string
string 版本号
ts/nim/client.ts:205
▸ getServerCurrentTime(cb
, calcLocal
): Promise
<[number
, boolean
, number
]>
获取当前服务器时间
Note
由于网络上/下行的原因,返回的时间会存在一定误差, 当 calc_local == false 时,如果跟上次调用该方法的时间间隔小于1000ms,SDK会采用 calc_local == true 时的方案以减少服务端的压力,并会在回调中指明返回的时间是由本地计算的。 如果返回 code != 200,同样会返回一个本地计算结果
Name | Type | Description |
---|---|---|
cb |
null | GetCurrentServerTimeCallback
|
操作结果的回调函数 |
calcLocal |
boolean |
- |
Promise
<[number
, boolean
, number
]>
void
ts/nim/client.ts:220
▸ getCurrentUserAccount(): string
获取当前登录的用户账号(accid)
Note
没有登录时将返回空字符串
string
string 当前登录的用户账号(accid)
ts/nim/client.ts:234
• client: NIMClientAPI
ts/nim/client.ts:36
• new NIMClient()
EventEmitter<NIMClientEvents>.constructor
ts/nim/client.ts:37
- chatroom/chatroom
- chatroom_def/chatroom_def
- nim/client
- nim/data_sync
- nim/friend
- nim/global
- nim/msglog
- nim/nos
- nim/online_session
- nim/pass_through_proxy
- nim/plugin
- nim/session
- nim/subscribe_event
- nim/super_team
- nim/sysmsg
- nim/talk
- nim/talkex
- nim/team
- nim/tool
- nim/user
- nim_def/client_def
- nim_def/data_sync_def
- nim_def/doc_trans_def
- nim_def/friend_def
- nim_def/global_def
- nim_def/msglog_def
- nim_def/nos_def
- nim_def/online_session_def
- nim_def/pass_through_proxy_def
- nim_def/plugin_def
- nim_def/session_def
- nim_def/subscribe_event_def
- nim_def/super_team_def
- nim_def/sysmsg_def
- nim_def/talk_def
- nim_def/talkex_def
- nim_def/team_def
- nim_def/tool_def
- nim_def/user_def
- node-nim
- qchat/attachment
- qchat/channel
- qchat/channel_category
- qchat/instance
- qchat/message
- qchat/role
- qchat/server
- qchat/system_notification
- qchat_def/attachment_def
- qchat_def/channel_def
- qchat_def/instance_def
- qchat_def/message_def
- qchat_def/public_def
- qchat_def/role_def
- qchat_def/server_def
- qchat_def/system_notification_def