Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Assets/Talo Game Services/Talo/Runtime/APIs/BaseAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected async Task<string> Call(

var allHeaders = continuity ? headers : BuildHeaders();

if (Talo.Settings.logRequests && Debug.isDebugBuild)
{
Debug.Log($"<-- {method} {uri}{(continuity ? " [CONTINUITY]" : "")} {content}");
}

if (Talo.Settings.offlineMode)
{
return HandleOfflineRequest(uri, method, content, allHeaders);
Expand All @@ -91,6 +96,11 @@ protected async Task<string> Call(
await Task.Yield();
}

if (Talo.Settings.logResponses && Debug.isDebugBuild)
{
Debug.Log($"--> {method} {uri} [{www.responseCode}] {www.downloadHandler.text}");
}

if (www.result == UnityWebRequest.Result.Success)
{
return www.downloadHandler.text;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using UnityEngine;

namespace TaloGameServices
{
[System.Serializable]
[Serializable]
public class SocketResponse
{
private class SocketMessage<T>
Expand All @@ -13,20 +14,28 @@ private class SocketMessage<T>

public string message;

public SocketResponse(string message)
public SocketResponse(string message)
{
this.message = message;
}

public string GetResponseType()
{
var message = JsonUtility.FromJson<SocketMessage<object>>(this.message);
return message.res;
var json = JsonUtility.FromJson<SocketMessage<object>>(message);
return json.res;
}

public T GetData<T>()
{
return JsonUtility.FromJson<SocketMessage<T>>(message).data;
}

public object GetJsonData()
{
var json = message.Substring(1, message.Length - 2) // remove the curly braces
.Replace("\"res\":\"" + GetResponseType() + "\",", "") // remove the response type
.Replace("\"data\":", ""); // remove the data key, only keep the value
return json;
}
}
}
4 changes: 4 additions & 0 deletions Assets/Talo Game Services/Talo/Runtime/TaloSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ public class TaloSettings : ScriptableObject
public bool offlineMode = false;
[Tooltip("Whether to automatically connect to the Talo socket when the game starts")]
public bool autoConnectSocket = true;
[Tooltip("Enable request logs in Debug builds")]
public bool logRequests = true;
[Tooltip("Enable response logs in Debug builds")]
public bool logResponses = true;
}
}
13 changes: 12 additions & 1 deletion Assets/Talo Game Services/Talo/Runtime/TaloSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ private void HandleMessage(WebSocketConnection connection, WebSocketMessage wsm)
var res = response.GetResponseType();
OnMessageReceived?.Invoke(response);

if (Talo.Settings.logResponses && Debug.isDebugBuild)
{
Debug.Log($"--> WSS {res} {response.GetJsonData()}");
}

switch (res)
{
case "v1.connected":
Expand Down Expand Up @@ -83,7 +88,13 @@ public void CloseConnection()

public void Send<T>(SocketRequest<T> request)
{
socket.AddOutgoingMessage(JsonUtility.ToJson(request));
var data = JsonUtility.ToJson(request);

if (Talo.Settings.logRequests && Debug.isDebugBuild)
{
Debug.Log($"<-- WSS {request.req} {data}");
}
socket.AddOutgoingMessage(data);
}

private void IdentifyPlayer()
Expand Down