-
Notifications
You must be signed in to change notification settings - Fork 363
Open
Description
Hi,
I would like to use the websocket API, to send a request to a websocket server to request a data.
I tried to adapt the getXhtr example, but it does not seems to work well: I receive the data but Blockly is blocked forever.
Here is my code:
var wrapper = function sensor(command, callback) {
Code.socket.addEventListener("message", (e) => {
callback(e.data);
});
Code.socket.send('{ "command" : "READ" , "params": ["' + command + '"]}');
};
interpreter.setProperty(globalObject, 'sensor',
interpreter.createAsyncFunction(wrapper));
The eventListener seems to be called, but the sensor function does not return in the interpreter (adding a console.log before callback print the right value).
Also, always adding a new eventlistener seems to not be very clean.
Does someone have tried websocket? How can I do?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels