Chrome WebSocket - onopen is not a function
Date : March 29 2020, 07:55 AM
Hope this helps The function is not correctly assigned to the onopen event. Do it like this instead: var ws = new WebSocket('ws://localhost:8002/', 'a')
ws.onopen = function() {
console.log("ok")
};
|
Object method call inside WebSocket's 'onopen()' function gives 'Function is undefined'
Date : March 29 2020, 07:55 AM
seems to work fine You are trying to access this inside the asynchronous call which will not be present when socket will be open. And this cause this.some() to be undefined. Below code should work: var ChatClient = function() {
var _self = this; // Save outer context
this.me = null; // This user
this.others = []; // Other users
this.socket = null;
this.handshake = function() {
this.socket = new WebSocket("ws://" + "localhost" + ":8000");
// Error occurred
this.socket.onerror = function(error) {
console.log('Socket error: ' + error);
};
// Opened
this.socket.onopen = function() {
console.log('Socket opened');
_self.some(); //It should work
};
// Message received
this.socket.onmessage = function(message) {
console.log('Socket message: ' + message.data);
};
// Closed
this.socket.onclose = function(message) {
console.log('Socket message: ' + message.data);
};
};
this.someOther = function() {
alert('name');
}
var some = function() {
this.someOther();
}
}
var _self = this;
|
When having both onEdit and onOpen registered triggers, only onOpen works
Date : March 29 2020, 07:55 AM
it should still fix some issue I found the cause of my issue and would like to share it here for anybody looking for an answer. It turned out to be an authorization issue. My scripts were used in couple of different projects, but each one of them had the same name. Adding to that some test spreadsheets I made to test some solutions, each of them again using script projects with the same name eventually led to my account authorizing ~ 15 scripts of the same name to use my google account. This made google confused and resulted in these scripts working only one at a time. I fixed this by removing all registered triggers and removing the authorization for them from my google account. I then created separate projects, each named differently, and pasted my functions in them. Now all my functions work properly, regardless of whether they are used withing the same script file or not.
|
How can I make sure a Websocket does not open before attaching an onopen handler?
Date : March 29 2020, 07:55 AM
it helps some times JavaScript implementation in browsers is asynchronous and single threaded. Of course, it can use multiple worker threads inside (for example, for input/output operations or timers), but your application code is executing on one thread with event loop. When you connect to the server through WebSocket: var socket = new WebSocket('ws://localhost:8080');
|
function onOpen() is not running
Date : March 29 2020, 07:55 AM
|