-
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
- init
- initEventHandlers
- 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
▸ 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
▸ listenerCount(event
): number
Return the number of listeners listening to a given event.
Name | Type |
---|---|
event |
keyof NIMClientEvents
|
number
EventEmitter.listenerCount
▸ 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
▸ 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
▸ 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
▸ 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
▸ 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
▸ 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
▸ removeAllListeners(event?
): NIMClient
Remove all listeners, or those of the specified event.
Name | Type |
---|---|
event? |
keyof NIMClientEvents
|
EventEmitter.removeAllListeners
▸ init(appKey
, appDataDir
, appInstallDir
, config
): boolean
NIM SDK初始化
Name | Type | Description |
---|---|---|
appKey |
string |
应用注册的APP KEY |
appDataDir |
string |
推荐用户目录放置在系统目录AppData\Local,默认只需要传入目录名,SDK会默认在系统目录下创建该级用户目录。如果要使用其他自定义路径,需传入绝对路径路径,并确保该目录有正确的读写权限。 |
appInstallDir |
string |
SDK动态库所在的目录全路径(如果传入为空,则按照默认规则搜索该动态库) |
config |
SDKConfig |
初始化参数 |
boolean
bool 返回值true: 成功, false: 失败
▸ initEventHandlers(): void
注册全局回调
void
▸ login(appKey
, account
, password
, cb
, jsonExtension
): boolean
NIM客户端登录
Note
200:成功 302:账号或密码错误 403:禁止操作 408:请求超时 414:参数错误 415:网络连接出现错误 416:频率超限 422:账号被禁用
Name | Type | Description |
---|---|---|
appKey |
string |
|
account |
string |
帐号 |
password |
string |
密码 |
cb |
LoginCallback |
登录流程的回调函数 |
jsonExtension |
string |
json扩展参数(v5.7.0 项目增加自定义参数字段) |
boolean
bool 检查参数如果不符合要求则返回失败
▸ logout(logoutType
, cb
, jsonExtension
): void
NIM客户端注销/退出
Note
200:成功 500:未知错误
Name | Type | Description |
---|---|---|
logoutType |
NIMLogoutType |
Logout操作类型,其定义见nim_client_def.h |
cb |
LogoutCallback |
注销/退出的回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void 无返回值
▸ cleanup(jsonExtension
): void
NIM SDK清理
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void 无返回值
▸ getSDKConfig(): SDKConfig
获取SDK配置
SDKConfig 返回值SDKConfig的引用 const类型,不可试图修改
▸ getLoginState(jsonExtension
): NIMLoginState
获取客户端登录状态
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
NIMLoginState 登录状态
▸ relogin(jsonExtension
): void
NIM客户端手动重连(注意 APP需要统一处理自动重连/手动重连的回调,因为如果处于某次自动重连的过程中调用手动重连接口,不起作用!)
Name | Type | Description |
---|---|---|
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void 无返回值
▸ kickOtherClient(clients
): void
将本帐号的其他端踢下线
Name | Type | Description |
---|---|---|
clients |
string [] |
设备标识 |
void
bool 检查参数如果不符合要求则返回失败, 接口调用成功后的结果通过注册RegKickOtherClientCb回调得到
▸ setMultiportPushConfigAsync(switch_on
, cb
, jsonExtension
): void
(全局回调)设置多端推送
Note
200:成功
Name | Type | Description |
---|---|---|
switch_on |
boolean |
开关 |
cb |
MultiportPushConfigCallback |
回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void
▸ getMultiportPushConfigAsync(cb
, jsonExtension
): void
获得多端推送设置
Name | Type | Description |
---|---|---|
cb |
MultiportPushConfigCallback |
回调函数 |
jsonExtension |
string |
json扩展参数(备用,目前不需要) |
void
void
▸ getSDKVersion(): string
获取SDK版本号
string
string 版本号
▸ getServerCurrentTime(cb
, calcLocal
): void
获取当前服务器时间
Note
由于网络上/下行的原因,返回的时间会存在一定误差, 当 calc_local == false 时,如果跟上次调用该方法的时间间隔小于1000ms,SDK会采用 calc_local == true 时的方案以减少服务端的压力,并会在回调中指明返回的时间是由本地计算的。 如果返回 code != 200,同样会返回一个本地计算结果
Name | Type | Description |
---|---|---|
cb |
GetCurrentServerTimeCallback |
操作结果的回调函数 |
calcLocal |
boolean |
- |
void
void
▸ getCurrentUserAccount(): string
获取当前登录的用户账号(accid)
Note
没有登录时将返回空字符串
string
string 当前登录的用户账号(accid)
• client: NIMClientAPI
• new NIMClient()
EventEmitter<NIMClientEvents>.constructor
- 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