# Chat message event

When a chat message is received, the MessageHandler methods are executed through the Channel object. Users can define their own EventHandler by inheriting from MessageHandler, and register the event handler with the Channel object using the channel.SetHandler(new MessageHandlerEx(this)) method.

# Getting Started

# Inherit MessageHandler class

First, create a new class that inherits from MessageHandler. In the example below, the class is named MessageHandlerEx.

public class MessageHandlerEx : MessageHandler
{


    private UnityVChat _unityVChat;

    public MessageHandlerEx(UnityVChat unityVChat)
    {
        _unityVChat = unityVChat;
    }

    public MessageHandlerEx()
    {

    }

    public override void OnNotifyMessage(JObject data)
    {
        UnityMainThreadDispatcher.Instance().Enqueue(() =>
        {
            _unityVChat.AddMessageToChat(data["nickName"] + " " + data["message"]);
        });
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

Below, descriptions of each event and example code used in the sample app are attached. You can define the necessary methods by overriding them in a new class.

# Message received event

This is a function that runs when a normal message is received.

  • example code
public override void OnNotifyMessage(JObject data)
{

    UnityMainThreadDispatcher.Instance().Enqueue(() =>
    {
        _unityVChat.AddMessageToChat(data["nickName"] + " " + data["message"]);
    });
}
1
2
3
4
5
6
7
8
  • parameter value

    value identifier Description
    data JObject Received message data

# User Join event

This function is executed when a user joins.

  • example code
public override void OnNotifyJoinUser(JObject data)
{
    UnityMainThreadDispatcher.Instance().Enqueue(() =>
    {
        _unityVChat.AddMessageToChat(data["nickName"] + " Join");
    });
}
1
2
3
4
5
6
7
  • parameter value

    value identifier Description
    data JObject Received message data

# User leave event

This function is executed when the logged in user leaves.

  • example code
public override void OnNotifyLeaveUser(JObject data)
{
    UnityMainThreadDispatcher.Instance().Enqueue(() =>
    {
        _unityVChat.AddMessageToChat(data["nickName"] + " Leave");
    });
}
1
2
3
4
5
6
7
  • parameter value

    value identifier Description
    data JObject Received message data
Copyright 2022. E7Works Inc. & JOYTUNE Corp. All Rights Reserved.