Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnAny fires but not On("eventName", response=>{foo();}); any idea? #278

Closed
ghost opened this issue Mar 31, 2022 · 2 comments
Closed

OnAny fires but not On("eventName", response=>{foo();}); any idea? #278

ghost opened this issue Mar 31, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Mar 31, 2022

Problem

The OnAny function works normally. The string value received through this function can be compared normally. However, it doesn't recognize eventName that I handed over through "On("eventName", response=> {foo();});".

OS / Platform

Windows / Unity 19.4.34f1, target .net 4.xx

Code

    void Awake()
    {
        client = new ClientInfo("null", userName);
        clientSocket = new SocketIO(serverIP);
    }

    async void Start()
    {
        //For Event Debug
        clientSocket.OnAny((eventName, data) =>
        {
            Debug.Log($"OnAny/{eventName}:{data}");
        });// It works
        
        clientSocket.On("[user] join", response =>
        {
            userList.Add(JsonConvert.DeserializeObject<ClientInfo>(response.GetValue<string>()));
            Debug.Log($"client Socket current Id : {clientSocket.Id}");
        });//not works

        clientSocket.On("[user] leave", response =>
        {
            string userSocketId = GetUserIdFromData(response.GetValue<string>());
            userList.RemoveWhere(info => info.id == userSocketId);
            Debug.Log($"Delete {userSocketId} from userList");
        });//not works

        clientSocket.On("connection", response =>
        {
            Debug.Log("connection");
        });// not works

        Connect();
    }
    async void Connect()
    {
        if (clientSocket == null)
            return;

        clientSocket.OnConnected += async (sender, e) =>
        {
            Debug.Log($"Emit Client name {client.name}");
            await clientSocket.EmitAsync("[user] join", client.name);
        };**//it works**

        Debug.Log($"Connect Async");
        await clientSocket.ConnectAsync();
    }

Etc

Unity console log
image

@doghappy
Copy link
Owner

doghappy commented Apr 14, 2022

maybe an exception was thrown, have you tried to move Log to the first line?

        clientSocket.On("[user] join", response =>
        {
            Debug.Log($"client Socket current Id : {clientSocket.Id}");
            userList.Add(JsonConvert.DeserializeObject<ClientInfo>(response.GetValue<string>()));
        });//not works

maybe you can clean your code like this?

        clientSocket.On("[user] join", response =>
        {
            Debug.Log($"client Socket current Id : {clientSocket.Id}");
            userList.Add(response.GetValue<ClientInfo>());
        });

@ghost
Copy link
Author

ghost commented Apr 26, 2022

@doghappy Thanks to your reply
For some reason, I confirmed that it works normally after the SocketIO .net update.
When error occurred I use the OnAny like this haha

            Debug.Log($"OnAny/{eventName}:{data}");
            
            if(eventName == "[user] enter")
            {
                Debug.Log("User Enter");

Thanks @doghappy :) have a good day

@ghost ghost closed this as completed Apr 26, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant