PlayEveryWare / eos_plugin_for_unity

Repository for PlayEveryWare's EOS Plugin for Unity, bringing the functionality of Epic Online Services to the Unity Game Engine.
https://eospluginforunity.playeveryware.com
288 stars 56 forks source link

`EOSManager.Instance.GetEOSRTCInterface().GetDataInterface().SendData()` always returns `NotFound` #758

Closed FREEZX closed 3 months ago

FREEZX commented 3 months ago

Describe the bug I'm trying to send a message to other participants in the same RTC Room of the lobby i'm in, I'm using the EOSLobbyManager included in the samples.

To Reproduce First I'm joining a lobby. Then, I'm calling my SendRTCMessage function given here with some random text message. Here's my function that I'm trying to get to work:

    public void SendRTCMessage(string message) {
        var sendDataOptions = new SendDataOptions(){
            Data = Encoding.Unicode.GetBytes(message),
            LocalUserId = EOSManager.Instance.GetProductUserId(),
            RoomName = LobbyManager.GetCurrentLobby().RTCRoomName
        };
        var rtcIface = EOSManager.Instance.GetEOSRTCInterface();
        Debug.Log($"RTC sending message to room name {LobbyManager.GetCurrentLobby().RTCRoomName}: {message}");
        Result res = rtcIface.GetDataInterface().SendData(ref sendDataOptions);
        Debug.Log(res);
    }

Expected behavior Res should be Success

Screenshots res is actually NotFound

Desktop (please complete the following information):

FREEZX commented 3 months ago

Enabling verbose logging also gives me this related error when I'm trying to send the data LogEOSRTC(Error): LibRTCCore: LibRtc::FDataChannelManager::PushData. Unknown conference or no outgoing data channel Even though I can see the same roomName I'm using in logs just above that, when joining the lobby and there are any updates to users in the lobby.

WispyMouse commented 3 months ago

Ahoy @FREEZX ! Let's try and figure out what's going on here.

I spun up the C samples from the EOS SDK, and found that our sample is missing two specific things.

The first is that the data channel for the RTC Room won't work unless you turn on a certain flag. The easiest way to manage that from the samples is to set the customLocalRTCOptions. You can find that struct at the top of the Manager class, and it's currently null. Since it's null, it won't pass in the custom options, so set its value here, or create your own LocalRTCOptions struct as you go to create or join a lobby.

public LocalRTCOptions? customLocalRTCOptions = new LocalRTCOptions() { Flags = (uint)JoinRoomFlags.EnableDatachannel };

When CreateLobby or JoinLobby run, they can pass in LocalRTCOptions to the createLobbyOptions. With this flag set, you'll be able to send data correctly.

The other missing piece is receiving that data. This'll require a few things. Inside SubscribeToRTCEvents, you'll need to subscribe to the AddNotifyDataReceived function of the RTCDataInterface. That could look like this;

Epic.OnlineServices.RTCData.AddNotifyDataReceivedOptions dataReceivedOptions = new Epic.OnlineServices.RTCData.AddNotifyDataReceivedOptions() { LocalUserId = EOSManager.Instance.GetProductUserId(), RoomName = CurrentLobby.RTCRoomName };

CurrentLobby.RTCRoomDataReceived = new NotifyEventHandle(EOSManager.Instance.GetEOSRTCInterface().GetDataInterface().AddNotifyDataReceived(ref dataReceivedOptions, null, OnRTCDataReceived), (ulong handle) =>
{
    EOSManager.Instance.GetEOSRTCInterface().GetDataInterface().RemoveNotifyDataReceived(handle);
});

You'll need to create a new notification handle for this. Go to the Lobby class inside the EOSLobbyManager, and add one.

/** Notification for RTC Data being received through the RTCInterface.SendData */
public NotifyEventHandle RTCRoomDataReceived;

The above code will clean up the handle when we're going to unsubscribe, but we still have to call that. Go to UnsubscribeFromRTCEvents and add a line of code to dispose it.

CurrentLobby.RTCRoomDataReceived.Dispose();

Finally, add the callback method that will actually handle the data being sent.

private void OnRTCDataReceived(ref Epic.OnlineServices.RTCData.DataReceivedCallbackInfo data)
{
    // Add your data handling methods here
}

You should be good to go from there! Apologies for the confusion, our team will consider how to supplement our samples to demonstrate how to implement this.

FREEZX commented 3 months ago

Many thanks for the quick response! I'll be trying these out first thing in the morning. This RTC Data interface looks perfect for implementing lobby chat, so it would be a good addition to the samples.

FREEZX commented 3 months ago

Just gave this a shot, but I still get the same result...

WispyMouse commented 3 months ago

Oh darn! Just to make sure, are you passing in LocalRTCOptions with the Flags = (uint)JoinRoomFlags.EnableDatachannel set when creating or joining the lobby? The fastest route for me to reproduce your error was creating a room without that, and even without the supporting structure for receiving and processing the data.

Otherwise, are you certain the RTCRoomName is being populated with a value?

FREEZX commented 3 months ago

Oh dang, it was my fault again :( While trying to figure out why it wasn't working previously i messed with the room name and just extracted the number after the +. We have liftoff, data is working! Sorry for wasting your time on this :(

WispyMouse commented 3 months ago

Helping people out is my job! I'm happy to have been able to assist, and in doing so I've learned more about the SDK and the kinds of problems users can have. Hope you have great luck in the future, @FREEZX , and let us know if you have any more problems!

FREEZX commented 3 months ago

Thanks for the support!