Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface NIMChatroomGetInstanceOptions

Hierarchy

  • NIMChatroomGetInstanceOptions

Index

Properties

account: string

Account ID, unique within the app.

Anonymous mode

  • For the first login in anonymous mode, no account is required. To prevent the creation of a new chat room instance, the previously obtained account should be used.
  • Anonymous login, isAnonymous must be set to true
  • Anonymous login, the nickname is required. For non-anonymous logins, the nickname is optional. It is recommended to use the avatar

Associated function

appKey: string

The AppKey of you application.

chatroomAddresses: string[]

Persistent connection address for the chat room. It is recommended to get the address of the chat room using the server API.

chatroomAvatar?: string

The avatar displayed after joining the chat room, if it is not configured and the user profile is hosted in NOS, then use the avatar in the user profile.

chatroomCustom?: string

Extension field, the member information obtained in getChatroomMembers

  • It is recommended to use JSON format. For data other than JSON format, the web client will receive the data but will be ignored by other clients.

Associated function

chatroomEnterCustom?: string

Extension field. In the onmsgs callback, if attach.type === 'memberEnter', attach.custom is the chatroomEnterCustom set during login

  • It is recommended to use JSON format. For data other than JSON format, the web client will receive the data but will be ignored by other clients.

Associated function

Example

// User A logs in
Chatroom.getInstance({
"account": "A",
"chatroomEnterCustom": "{'enterCustom': 'enterCustom'}"
})

// Logged-in User B gets notified by onmsgs
Chatroom.getInstance({
"account": "B",
"onmsgs": function(msg) {
if (msg.type === 'notification' && msg.attach.type === 'memberEnter') {
// {'enterCustom': 'enterCustom'}
console.log(msg.attach.custom)
}
}
})
chatroomId: string

Chat room ID

Associated function

chatroomNick?: string

The nickname displayed after joining the chat room, if it is not configured and the user profile is hosted in NOS, then use the nickname in the user profile. If it is an anonymous login, this parameter is required

customClientType?: string

Custom client type, set an integer greater than 0

Note: The default client types are only Web, PC, AOS, and iOS. If you want to distinguish more types, such as WeChat Mini Program and other environments, they can use this field to map the values.

customTag?: string

Client custom tag. Up to 32 characters

Note: This field is often used during login. Get notified when the account is logged in on other devices. You can configure a custom setting.

debug?: boolean

Specify whether to print the debugging log.. The default value is false.

deprecated

logLevel log level is recommended

distance?: number

Distance of the subscribed message

isAnonymous: boolean

Whether to log in in anonymous mode The default value is false

loc_x?: number

Coordinate X, optional, only for location messages

loc_y?: number

Coordinate Y, optional, only for location messages

loc_z?: number

Coordinate z, optional, only for location messages

logLevel?: "debug" | "log" | "info" | "warn" | "error" | "off"

Log level, the default is off and no log is output.

  • off: do not output any logs
  • debug: output debug, info, warn and error level logs
  • info: output info, warn, and error level logs
  • warn: output warn and error level logs
  • error: output error level logs
loginAuthType?: number

Authentication method for logging in to a chat room (default value: 0):

  • 0: Authentication using static tokens. The static token remains unchanged and is permanently valid by default, unless you refresh token using the server API.
  • 1: Authentication using dynamic tokens. Dynamic tokens can be configured with a validity period and are time-sensitive. This authentication method can effectively increase the security and reduce the risk of password leakage. For information about how to generate dynamic tokens, see: dynamic token
  • 2: Authentication using third-party webhooks. The CommsEase server does not perform IM login authentication, and the authentication must be performed by a designated third-party server (your app server).
note

For information about how to get tokens and related login methods, see initialization and sign in.

loginExt?: string

Extension field for login

Note: the extension is synced with the app server, and will not be synchronized to other devices.

needReconnect?: boolean

Whether to enable automatic reconnection. default value: true

Notes

  • The connection is closed due to network, heartbeat timeout and other reasons, and the SDK provides automatic reconnection
  • The interval for reconnection is accumulated from 1.6 to 8s, and each reconnection will trigger the onwillreconnect event
nosScene?: string

NOS file storage global setting, default value: chatroom

nosSurvivalTime?: number

The NOS storage global setting, the validity duration of storage. The default value Infinity must not be less than one day in seconds

notifyTargetTags?: string

Tag expression. Indicates which tagged users should the notifications for login and logout be broadcast to.

If unspecified, the server will automatically generate a tag expression according to NIMChatroomGetInstanceOptions.tags.

The generation rule is to combine all the tags in the and keyword. Only users who have all the tags can receive the notifications for joining and leaving the chat room.

Associated function

quickReconnect?: boolean

Whether to enable quick automatic reconnection. default value: false. If the value is set to true, NIM SDK will monitor the browser's offline and online events to detect network disconnection and recovery, and will implement corresponding disconnection and reconnection strategies.

notice

This field is only valid when needReconnect is true.

reconnectionAttempts?: number

The maximum number of times the SDK tries to reconnect. If the attempts exceed the maximum number, the SDK will stop reconnecting.

note

When the maximum number of reconnection attempts is reached, the reconnection process will end, and finally the ondisconnect callback will be triggered, indicating a complete disconnection.

secure: boolean

Whether to use the secure mode

In secure mode, a connection will be established with the server using HTTPS protocol, and in non-secure mode, a connection will be established with the server using HTTP protocol, the default value is true.

socketConcurrent?: number

The number of concurrent socket connections.

Supported since v9.12.0 The maximum number of Socket concurrent connections. Valid values: an integer between 1 and 3. The default value is 1, no concurrent connections are supported. If you need more Socket connections, you can set this parameter.

tags?: string[]
  • The parameter tags is used to identify which tags the persistent connection of this login belongs to. It is a JSON array. The same persistent connection can support up to 10 tags. Each tag can have a maximum of 32 characters, such as: ["abc", "def"]
token: string

The login credentials of the account, use the token for verification when initializing the connection or reconnecting. No token is required for anonymous logins

Methods

  • Whether to perform additional processing on the log, such as log storage, log reporting, etc., this function will intercept the parameters of the console log for use Whether perform additional processing on the log, such as log storage, log reporting, etc.

    This function will intercept the parameters of the SDK log for use.

    Associated function

    Example

    const logs = []

    setInterval(() => {
    if (logs.length > 0) {
    //Every 2 minutes, upload the logs to your app server
    //...

    //Clear logs
    logs = []
    }
    }, 120000)

    Chatroom.getInstance({
    logFunc: {
    log: function (data) {
    logs.push(`log: ${data}`)
    },
    warn: function (data) {
    logs.push(`warn: ${data}`)
    },
    info: function (data) {
    logs.push(`info: ${data}`)
    },
    debug: function (data) {
    logs.push(`debug: ${data}`)
    },
    error: function (data) {
    logs.push(`error: ${data}`)
    }
    }
    })

    Parameters

    Returns void

  • onTagsUpdate(currentTags: string[]): void
  • onconnect(data: { connectionId: string; country?: string; customTag?: string; ip: string; lastLoginDeviceId: string; port: string }): void
  • Callback invoked when the SDK gets connected with the CommsEase server. Users can prompt the network status of the application in the interface using onwillreconnect, onconnect, ondisconnect and other callbacks

    Associated function

    Example

    Chatroom.getInstance({
    onconnect: function () {
    showToast('connected')
    }
    })

    Parameters

    • data: { connectionId: string; country?: string; customTag?: string; ip: string; lastLoginDeviceId: string; port: string }
      • connectionId: string

        Connection ID of the current login

      • Optional country?: string

        Country

      • Optional customTag?: string

        Client custom tag, multi-device synchronous field when logging in, up to 32 characters

      • ip: string

        IP address

      • lastLoginDeviceId: string

        Device ID of the last login

      • port: string

        port

    Returns void

  • Hook function-receiving a message in the chat room

    Parameters

    Returns void

  • onwillreconnect(data: { duration: number; retryCount: number }): void
  • The callback invoked when the SDK are connecting to the CommsEase server. Users can prompt the network status of the application in the interface using onwillreconnect, onconnect, ondisconnect and other callback functions

    notice

    If this callback is triggered, the SDK has disconnected from the CommsEase server. NIM make the system must prompt the user on the interface that the app becomes disconnected, and the app is reconnecting..

    Example

    Chatroom.getInstance({
    onwillreconnect: function () {
    showToast('The network is unstable, connecting')
    }
    })

    Parameters

    • data: { duration: number; retryCount: number }
      • duration: number

        The interval for retries

      • retryCount: number

        Number of retries

    Returns void