Navigation

    Colyseus
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Users
    1. Home
    2. Imallic
    I

    Imallic

    @Imallic

    Chat Follow Unfollow
    2
    Reputation
    8
    Posts
    1030
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    • Profile
    • More
      • Continue chat with Imallic
      • Flag Profile
      • Following
      • Followers
      • Topics
      • Posts
      • Best
      • Groups
    Imallic Follow

    Posts made by Imallic

    RE: Colyseus.js Websocket is not defined

    I know this topic is 3 months old, but I have found a workaround so if anyone searches for this they will have an answer.

    The reason your unit test is not working is that WebSocket is not globally installed when you run it in say Jest for example.

    A quick work around would be to define it globally.

    // npm install ws
    
    const globalAny: any = global; // This way we don't get an error in TypeScript saying WebSocket is not a defined property on global
    globalAny.WebSocket = require('ws');
    

    Also, it appears as though the colyseus.js client makes use of the window.local storage object. A quick polyfill you could do would look something like this

    globalAny.window = {
        localStorage: {
            getItem: () => {},
            setItem: () => {}
        },
    

    };

    posted in Questions & Help •
    RE: Getting error when leaving room on OnDestroy (Unity)

    @endel, I have created the pull request: https://github.com/gamestdio/colyseus-unity3d/pull/40

    posted in Questions & Help •
    RE: Getting error when leaving room on OnDestroy (Unity)

    @endel , does this change seem appropriate? If so, I could make a pull request for this change.

    posted in Questions & Help •
    Getting error when leaving room on OnDestroy (Unity)

    When the game object gets destroyed that holds the game room, I call room.Leave()

        public void OnDestroy()
        {
            if (isRoomJoined)
            {
                this.Leave();
            }
        }
    

    This throws an error whenever I do this though.

    WebsocketSharp Error! An exception has occured while OnClose.

    Is the issue that I'm leaving while the gameObject is being destroyed?

    Edit:

    Also, it appears that this doesn't have any actual affect on any other rooms and everything appears to be functioning normally. But it scares me for it to have this error popping up.

    Update:

    When I try to just leave the room without destroying the game object, I still see the issue

    So it looks like the error is coming from this cast of WebSocket to Room.
    But I'm still not quite sure how to fix the issue.

    0_1529542860133_Screen Shot 2018-06-20 at 5.59.57 PM.png

    If I change this line in Room.cs it makes it work:
    0_1529543210037_Screen Shot 2018-06-20 at 6.06.39 PM.png

    posted in Questions & Help •
    RE: Not getting updated state in Unity client

    But things like updating player movement wouldn't need to be that reliable. I understand that things like interpolation could be used but it's still going to make something like an FPS too glitchy.

    posted in Questions & Help •
    RE: Not getting updated state in Unity client

    This may be off topic, but does colyseus support UDP? with state changes?

    posted in Questions & Help •
    RE: Not getting updated state in Unity client

    That solved the issue. You are correct, I was taking a React approach to it.
    Thanks for saving me again @endel!

    posted in Questions & Help •
    Not getting updated state in Unity client

    I'm only getting the first state and it's not being updated beyond that.
    Is there something obvious that I'm not seeing that is causing the issue?

    Here is my room code:

    import BaseRoom from "./BaseRoom";
    import {Client} from "colyseus";
    
    export class State {
        ticks: number;
        constructor() {
            this.ticks = 0;
        }
    }
    
    export default class ChatRoom extends BaseRoom<State> {
        onDispose(): void | Promise<any> {
            return undefined;
        }
    
        onInit(options: any): void {
            console.log('ChatRoom created');
            this.setState(new State());
            setInterval(() => {
                this.setState({ticks: this.state.ticks + 1});
                console.log('Updated state', this.state);
            }, 1000);
        }
    
        onJoin(client: Client, options?: any, auth?: any): void | Promise<any> {
            return undefined;
        }
    
        onLeave(client: Client): void | Promise<any> {
            return undefined;
        }
    
        onMessage(client: Client, data: any): void {
            console.log('ChatRoom received message', data);
        }
    }
    

    And on the Unity Side:

        Client client = new Colyseus.Client("ws://localhost:6900");
        client.OnError += Client_OnError;
        yield return StartCoroutine(client.Connect());
        Room room = client.Join("chat", new Dictionary<string, object>() {
            {"accessToken",accessToken},
            {"username", username}
        });
        room.OnReadyToConnect += (sender, e) => {
            Debug.Log("Ready to join room");
            StartCoroutine(room.Connect());
        };
    
        room.OnError += Room_OnError;
    
        room.OnStateChange += OnStateChange;
        room.Listen("message", this.OnMessage);
        room.Listen("ticks", this.OnTick);
        room.OnJoin += Room_OnJoin;
        room.OnMessage += Room_OnMessage;
    
        int i = 0;
    
        while (true)
        {
            client.Recv();
    
            i++;
    
            if (i % 50 == 0)
            {
                room.Send("some_command");
            }
    
            yield return 0;
        }
    posted in Questions & Help •