Skip to content
New issue

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

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

Already on GitHub? # to your account

Object doesn't support property or method 'packet' #489

Closed
sjbog opened this issue Aug 29, 2011 · 3 comments
Closed

Object doesn't support property or method 'packet' #489

sjbog opened this issue Aug 29, 2011 · 3 comments

Comments

@sjbog
Copy link

sjbog commented Aug 29, 2011

Got this error on chrome and IE (haven't test others):

Uncaught TypeError: Object [object DOMWindow] has no method 'packet'
SocketNamespace.emit 

socket.io.js:2098

IE:

SCRIPT438: Object doesn't support property or method 'packet' 
socket.io.js, line 2098 character 5

since yesterday, when updated to 0.7.11
same with 0.8.0

On server's console don't see any errors

@einaros
Copy link
Contributor

einaros commented Aug 29, 2011

Which version of IE? Which transports are you using? What does your client code look like?

@sjbog
Copy link
Author

sjbog commented Aug 29, 2011

Tried websockets and xhr-pooling:
Client side:

socket.on('connect', function connected() {
    console.log('Connected to remote host');
    setLinkState(1);
    toggleControlButtons();
    statsIntervalHandle = setInterval(socket.emit, 3000, "get_stats", {"value": "all"});
});

socket.on('stats', function() {
    var outputArr = Array.prototype.slice.call(arguments), len = outputArr.length;
    while(len--) {
        console.log('got stats', outputArr[len]);
        setStats(outputArr[len]);
    }
});

Server side:

socket.on("get_stats", function(data) {
        switch(data['value']) {
            case 'memory_usage':
                    socket.emit("stats", getMemoryUsage(true));
                break;
            case 'all':
            default:
                    socket.emit("stats", getMemoryUsage(true), {
                        "mysql_rows": DBrows.length,
                        "rules_in_memory": rules.length,
                        "stocks_in_memory": stockNames.length,
                        "open_prices": Object.keys(startPrices).length,
                        "current_prices": Object.keys(currentPrices).length
                    });
        }
    });

@sjbog sjbog closed this as completed Aug 29, 2011
@sjbog sjbog reopened this Aug 29, 2011
@sjbog
Copy link
Author

sjbog commented Aug 29, 2011

Looks like the issue is in setInterval (setTimeout will do the same) of my code:
when it invokes "socket.emit" context is window

Code executed by setTimeout() is run in a separate execution context to the function from which it was called. As a consequence, the this keyword for the called function will be set to the window (or global) object, it will not be the same as the this value for the function that called setTimeout.

When you pass a method to setInterval() (or any other function, for that matter), it will be invoked with a wrong this value.

https://developer.mozilla.org/en/DOM/window.setTimeout#The_'this'_problem

@sjbog sjbog closed this as completed Aug 29, 2011
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants