Event Subscription

Update time: 2021/09/25 14:35:08

Event subscription means subscribing to events published by another user, so that the subscriber can be notified of any event published by that user. There are two types of events: system predefined event and custom event, of which the former falls within the range of 1-99999, and the latter must have a value larger than 99999. For custom events, users can specify different event types and events to define different meanings as needed; for system predefined events, the system reserves the event value from 1 to 9999. If users want to send a system predefined event , the value of which must be greater than 9999.

Currently, system predefined events are limited to online status events, event type is 1, event values include: 1-User logs in, 2-User logs out, 3-User disconnects from server. When the user logs in, logs out, and exits abnormally, the server will send a corresponding online status event value to notify the subscriber.Subscribing or un-subscribing events with one client will take effect on other clients at the same time Therefore, it is required to unsubscribe events with caution in a manner that prevents any effect on other terminals.

Receive event

Register in advance the callback function for receive event, so that it can receive the subscribed event after logging in. Two callback functions need to be registered: One for receiving subscribed events, the other for bulk receiving subscribed events.

  • API prototype
csharp/// <summary>
* (Global callback) Uniformly register the callback function for receiving subscription event
/// </summary>
/// <param name="cb"></param>
public static void RegPushEventCb(PushEventDelegate cb)

/// <summary>
* (Global callback) Uniformly register the callback function for receiving subscription events in bulk
/// </summary>
/// <param name="cb"></param>
public static void RegBatchPushEventCb(BatchPushEventDelegaet cb)

Publish event

Users can publish system predefined events or custom events according to their own needs. To publish an event, the user needs to specify its type, event value, message id, validity period, broadcast type, synchronization type, and choose whether to attach custom extended properties to the event as required. Among themEvent validity period: 60s to 7 days, in seconds, validity period refers to the time period during which the corresponding event can be received after login; broadcast type specifies whether to notify offline subscribers; synchronization type specifies whether to synchronize the event to other terminals used; and extended properties can contain any string created as needed.

  • API prototype
csharp/// <summary>
/// Publish an event
/// </summary>
/// <param name="info">Event information</param>
/// <param name="cb"></param>
/// <param name="data"></param>
/// <returns></returns>
public static bool Publish(NIMEventInfo info, PublishEventDelegate cb,object data = null)

Subscribe event

To receive an event published by a user, you must first subscribe to one of his/her events. When subscribing to events, you need to specify the event type, validity period of subscription, and whether to synchronize the latest events immediately after subscription. Among themSubscription validity period: 60s to 30 days, in seconds. Upon expiration of validity period, re-subscription is required to continue receiving the event..

  • API prototype
csharp/// <summary>
/// Subscription event
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="period">Period of validity of subscription, unit: s, range: 60s - 30d</param>
/// <param name="syncType">It determines to synchronize the latest event immediately after subscription. See NIMEventSubscribeSyncType definition.</param>
/// <param name="idList"User list></param>
/// <param name="cb"></param>
/// <returns></returns>
public static bool Subscribe(int eventType,long period, NIMEventSubscribeSyncEventType syncType,List<string> idList,SubscribeEventDelegate cb)

Unsubscribe event

You can unsubscribe an event that you no longer want to know about, and you won't be notified of the event after that. You can unsubscribe events published by a specified friend or all subscribed events.

  • API prototype
csharp/// <summary>
/// Unsubscribe designated event by account
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="idList">List of users</param>
/// <param name="cb"></param>
/// <returns></returns>
public static bool UnSubscribe(int eventType,List<string> idList, UnSubscribeEventDelegate cb)

 /// <summary>
/// Unsubscribe designated event.
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="cb"></param>
/// <returns></returns>
public static bool BatchUnSubscribe(int eventType, BatchUnscribeEventDelegate cb)

Query subscription relationship

  • API prototype

You can query the event subscription information of a specified friend or a specified event type.

csharp/// <summary>
/// Query subscriptions of designated event by account
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="idList">List of users</param>
/// <param name="cb"></param>
/// <returns></returns>
public static bool QuerySubscribe(int eventType,List<string> idList, QuerySubscribeDelegate cb)

/// <summary>
/// Query all subscriptions of designated event
/// </summary>
/// <param name="eventType">Event type</param>
/// <param name="cb"></param>
/// <returns></returns>
public static bool BatchQuerySubscribe(int eventType, QuerySubscribeDelegate cb)
Was this page helpful?
Yes
No
  • Receive event
  • Publish event
  • Subscribe event
  • Unsubscribe event
  • Query subscription relationship