In-app Chat
  • iOS : Objective-C
  • Android
  • Web
  • Flutter
  • React Native
  • Unity3D
  • Windows
  • macOS
  • Introduction
    • Overview
    • Basic concepts
  • Sample app
  • Getting started
  • Client SDKs
    • SDK downloads
    • Release notes
    • Upgrade guide
  • Guides
    • Authentication
    • Manage users
    • Room
    • Group
    • Messaging
    • Call invitation (signaling)
    • Manage sessions
  • Offline push notifications
  • Error codes
  • Client APIs
  • Server APIs
  • Documentation
  • In-app Chat
  • Server APIs
  • Third party callback
  • Login and logout callback

Login and logout callback

Last updated:2024-03-14 18:33

Overview

You can use this callback to listen for user login and logout and implement the business logic, for example, counting online users.

  • User login: A TCP connection is established.
  • User logout or network disconnection: A TCP connection is disconnected.
  • App heartbeat timeout: An app is killed or crashes.

Callback description

  • Request method: POST/JSON.

    <div class="mk-hint">

    The callback data needs to be decoded by UrlDecode.

  • Request URL: Contact ZEGOCLOUD technical support to configure the callback URL.

  • Protocol: HTTPS/HTTP. HTTPS is recommended.

Callback parameters

Parameter Type Description
appid
String
The unique ID of an app.
event
String
The callback event. The return value is user_action.
timestamp
Integer
The Unix timestamp of the callback server. Unit: seconds.
nonce
String
A random number.
signature
String
The verification string. For more information, see Authenticating server-to-server callbacks.
user_id
String
The user ID.
user_name
STRING
The username.
os
String
The description of the operating system, which is synchronized upon user login. Valid values:
  • PC
  • IOS_PHONE
  • ANDROID
  • MAC
  • LINUX
  • WEB
  • MINIPROGRAM (mini program)
  • ANDROID_TV
action
Integer
Status. Valid values:
  • 0: online, which indicates that the user app successfully connects to the ZIM server by calling the login operation.
  • 1: logout, which indicates that the user app successfully disconnects from the ZIM server by calling the logout operation.
  • 2: offline.
session_id
String
The unique ID of a session. If a user is online on multiple terminals, multiple sessions exist and are identified by ID.
login_time
Integer
The Unix timestamp of login. Unit: seconds.
relogin
String
The identifier of re-login. Valid values:
  • 0: first login.
  • 1: re-login.
logout_time
Integer
The Unix timestamp of logout. Unit: seconds.
logout_reason
String
The reason for logout.
offline_time
Integer
The Unix timestamp of going offline. Unit: seconds.
We recommend that you convert some parameters into integers for logic processing, including `appid` and `nonce`.

Sample code

  • POST/JSON
{
    "appid": "1",
    "event": "user_action",
    "timestamp": 1679553625,
    "nonce": "350176",
    "signature": "signature",
    "user_id": "123456",
    "user_name": "user_name",
    "os": "PC ",
    "action": 1,
    "session_id": "930821637828251648",
    "login_time": 1679553625,
    "relogin": "1",
    "logout_time": 1679553625,
    "logout_reason": "logout_reason"
}

Return codes

If an HTTP status code 2XX (for example, 200) is returned, the callback succeeded. Otherwise, the callback failed.

Callback retry policy

If the ZEGOCLOUD server does not receive a response, it will retry with intervals of 2s, 4s, 8s, 16s, and 32s respectively. If the retry still fails after an interval of 32s, it will no longer retry.

Page Directory