Example #1
0
    socket.on('message', function(data) {

        var decoded = Encoder.decode(data);

        //We must wait for this message to be recieved before loading modules
        if (decoded.verb == 'sendDetails') {

            game.config = decoded.msg;
            game.redraw = true;
            repo.load();
            loaded = true;

        } else if (!loaded || flag) {

            //while waiting for the sendDetails message, some other messages may not be routed, so cache them
            //we also cache if the flag has been set to true, as it means something else is being routed.
            cache.push(decoded);
            return;

        } else while (cache.length > 0) {
            router.route(cache.pop(), new Server(socket)); //Route the cached messages
        }

        //route one message at a time.
        //This should, strictly speaking, never happen as JS isn't multithreaded
        //but somehow, and we do not know how, Firefox has concurrency problems.
        //it is possible that socket.io is using web workers and calling these functions asynchronously.

        flag = true;
        router.route(decoded, new Server(socket));
        flag = false;
    });
Example #2
0
 this.send = function(res, verb, message) {
     skt.emit('message', Encoder.encode(res, verb, message));
 };