Easy Code For Vivox
  • Introduction
    • Official Links
    • Getting Started
      • Wheres The Code
      • Setup EasyCode in My Project
    • Setup Demo Scenes
      • Vivox Developer Portal
      • Unity Gaming Services (UGS) Dashboard
    • Things To Consider
    • FAQ
  • Development Info
    • Design Decisions
    • Release Notes
      • v2.0
      • v1.3
      • v1.2
      • v1.1
      • Template
    • Not Supported
  • Easy Code For Vivox
    • How do I setup EasyCode?
      • Setup Your Credentials
    • How do I do this in EasyCode?
      • Login / Logout
        • Login Properties
        • SetTransmissionMode
        • Login Events
      • Join / Leave Channel
        • Audio Channel
          • Audio Channel Events
        • Text Channel
          • Text Channel Events
        • Channel Events
      • Send Messages
        • Message Events
      • Mute / Unmute
        • Mute / Unmute Events
      • Subscribe to User Events
      • Volume / Audio Settings
        • Audio Device Events
      • Text To Speech ( TTS )
        • TTS Events
    • Vivox Access Tokens
      • Unity Cloud Code
    • Supported Vivox Events
      • Callback Methods
    • Folder Structure / Info
      • / Demo Scenes /
      • / Documentation /
      • / Examples /
      • / Plugins /
      • / Resources /
      • / Scripts /
      • / Settings /
    • Common Errors
  • API Info
    • EasySession.cs
    • EasyManager.cs
      • Main Methods
      • Vivox Event Callbacks
    • Easy3DPositional.cs
    • EasyVivoxUtilities.cs
    • EasySettings.cs
    • Extension Methods
      • EasySIPExtensions.cs
      • GameObjectExtensions.cs
      • TTSMessageExtensions.cs
      • UIExtensions.cs
      • VivoxExtensions.cs
      • EasyDebug.cs
    • EasyEvents.cs
  • Dependency Injection
    • Zenject vs Extenject
    • Install Dependencies
    • Inject Classes
  • Dynamic Events
    • Dynamic Events
    • Tests
    • Gotchas
    • Dynamic Async Events
      • Dont Do
    • Event Examples
  • Related Info
    • How do I do this in Vivox?
      • Conference Chat
    • Pre-Processor Directives
    • How to set iOS Info.plist for Unity?
    • Unity Gaming Services
  • The Future
    • Roadmap
    • Todo / Notes / Changelog
Powered by GitBook
On this page
  • Inherit from EasyManager.cs
  • Inject EasyEvents
  • Dynamic Events
  • How to Subscribe to Message Events in EasyCode

Was this helpful?

  1. Easy Code For Vivox
  2. How do I do this in EasyCode?
  3. Send Messages

Message Events

Inherit from EasyManager.cs

using EasyCodeForVivox;

public class VivoxManager : EasyManager
{

}

Inject EasyEvents

using EasyCodeForVivox.Events;
using UnityEngine;
using Zenject;

public class VivoxEvents : MonoBehaviour
{
    EasyEvents _events;

    [Inject]
    private void Initialize(EasyEvents events)
    {
        _events = events;
    }
}

Dynamic Events

Make sure Dynamic Events are enabled

How to Subscribe to Message Events in EasyCode

EasyManager

Keeping the base methods are not necessary. They are simply Debug.Logs(). Feel free to delete them

// Message Event Callbacks

protected override void OnChannelMessageRecieved(IChannelTextMessage textMessage)
{
    base.OnChannelMessageRecieved(textMessage);
}

protected override void OnDirectMessageRecieved(IDirectedTextMessage directedTextMessage)
{
    base.OnDirectMessageRecieved(directedTextMessage);
}

protected override void OnDirectMessageFailed(IFailedDirectedTextMessage failedMessage)
{
    base.OnDirectMessageFailed(failedMessage);
}

EasyEvents

public void SubscribeToMessageEvents()
{
    _events.ChannelMessageRecieved += OnChannelMessageRecieved;

    _events.DirectMessageRecieved += OnDirectMessageRecieved;
    _events.DirectMessageFailed += OnDirectMessageFailed;
}

public void UnsubscribeToMessageEvents()
{
    _events.ChannelMessageRecieved -= OnChannelMessageRecieved;

    _events.DirectMessageRecieved -= OnDirectMessageRecieved;
    _events.DirectMessageFailed -= OnDirectMessageFailed;
}



protected virtual void OnChannelMessageRecieved(IChannelTextMessage textMessage)
{
    Debug.Log($"From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.Message}");
}

// This feature is expiramental and may be removed later
protected virtual void OnEventMessageRecieved(IChannelTextMessage textMessage)
{
    Debug.Log($"Event Message From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.ApplicationStanzaNamespace} : {textMessage.ApplicationStanzaBody} : {textMessage.Message}");
}

protected virtual void OnDirectMessageRecieved(IDirectedTextMessage directedTextMessage)
{
    Debug.Log($"Recived Message From : {directedTextMessage.Sender.DisplayName} : {directedTextMessage.ReceivedTime} : {directedTextMessage.Message}");
}

protected virtual void OnDirectMessageFailed(IFailedDirectedTextMessage failedMessage)
{
    Debug.Log($"Failed To Send Message From : {failedMessage.Sender}");
}

Dynamic Events

[ChannelMessageEvent(ChannelMessageStatus.ChannelMessageRecieved)]
private void OnChannelMessageRecieved(IChannelTextMessage textMessage)
{
    Debug.Log($"From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.Message}");
}

// This feature is expiremental and may be removed later
[ChannelMessageEvent(ChannelMessageStatus.EventMessageRecieved)]
private void OnEventMessageRecieved(IChannelTextMessage textMessage)
{
    Debug.Log($"Event Message From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.ApplicationStanzaNamespace} : {textMessage.ApplicationStanzaBody} : {textMessage.Message}");
}

[DirectMessageEvent(DirectMessageStatus.DirectMessageRecieved)]
private void OnDirectMessageRecieved(IDirectedTextMessage directedTextMessage)
{
    Debug.Log($"Recived Message From : {directedTextMessage.Sender.DisplayName} : {directedTextMessage.ReceivedTime} : {directedTextMessage.Message}");
}

[DirectMessageEvent(DirectMessageStatus.DirectMessageFailed)]
private void OnDirectMessageFailed(IFailedDirectedTextMessage failedMessage)
{
    Debug.Log($"Failed To Send Message From : {failedMessage.Sender}");
}

Dynamic Async Events

Remember to use async void or async Task or else the event may run synchronously

[ChannelMessageEventAsync(ChannelMessageStatus.ChannelMessageRecieved)]
private async void OnChannelMessageRecievedAsync(IChannelTextMessage textMessage)
{
    Debug.Log($"From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.Message}");
    await SavePlayerData();
}

// This feature is expiremental and may be removed later
[ChannelMessageEventAsync(ChannelMessageStatus.EventMessageRecieved)]
private async void OnEventMessageRecievedAsync(IChannelTextMessage textMessage)
{
    Debug.Log($"Event Message From {textMessage.Sender.DisplayName} : {textMessage.ReceivedTime} : {textMessage.ApplicationStanzaNamespace} : {textMessage.ApplicationStanzaBody} : {textMessage.Message}");
    await SavePlayerData();
}

[DirectMessageEventAsync(DirectMessageStatus.DirectMessageRecieved)]
private async void OnDirectMessageRecievedAsync(IDirectedTextMessage directedTextMessage)
{
    Debug.Log($"Recived Message From : {directedTextMessage.Sender.DisplayName} : {directedTextMessage.ReceivedTime} : {directedTextMessage.Message}");
    await SavePlayerData();
}

[DirectMessageEventAsync(DirectMessageStatus.DirectMessageFailed)]
private async void OnDirectMessageFailedAsync(IFailedDirectedTextMessage failedMessage)
{
    Debug.Log($"Failed To Send Message From : {failedMessage.Sender}");
    await SavePlayerData();
}
PreviousSend MessagesNextMute / Unmute

Last updated 2 years ago

Was this helpful?

Make sure the parameter in your method matches the event type. See what parameter is required for each . Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=

Make sure the parameter in your method matches the event type. See what parameter is required for each . Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=

More information on the methods called in any async method can be found here. . They are direct copies from Unity's docs. These are just examples and don't mimic real world use cases

Unity Gaming Services Examples
Message Event here
Message Event here