-
• #2
Could you check on the Web Browser's debug console and see if it really is just complaining about trying to call a callback that doesn't exist?
It wouldn't surprise me, and it's an easy fix - the standard
Puck.write
functions cope with not having callbacks fine, but I have to admit I have always used the connection-based write with a callback, so may not have added a check for when it doesn't exist. -
• #3
Hi Gordon,
I found the issue in the https://www.puck-js.com/puck.js code I believe. I've made some comments below.
connection.write = function(data, callback) { // **** This is pushing callback as null **** if (data) txDataQueue.push({data:data,callback:callback}); // *********************** if (connection.isOpen && !connection.txInProgress) writeChunk(); function writeChunk() { var chunk; if (!txDataQueue.length) return; var txItem = txDataQueue[0]; if (txItem.data.length <= CHUNKSIZE) { chunk = txItem.data; txItem.data = undefined; } else { chunk = txItem.data.substr(0,CHUNKSIZE); txItem.data = txItem.data.substr(CHUNKSIZE); } connection.txInProgress = true; log("BT> Sending "+ JSON.stringify(chunk)); txCharacteristic.writeValue(str2ab(chunk)).then(function() { log("BT> Sent"); if (!txItem.data) { txDataQueue.shift(); // **** This is calling the null callback function and throwing an Error. **** txItem.callback(); // *************************** } connection.txInProgress = false; writeChunk(); }).catch(function(error) { log('BT> SEND ERROR: ' + error); txDataQueue = []; // **** The error is being caught and the connection is being closed. **** connection.close(); // ******************** }); } };
Like you said it's an easy fix to only call the callback if one is passed.
-
• #4
I've also noticed that the
connection
object doesn't have theeval
function? -
• #5
Just updated!
-
• #6
Great!
-
• #8
It's that Puck.connect is the more 'advanced' way to talk to the Pucks - I'd been assuming that you would want full control of the input and output if you used it.
As a result, it's a bit harder to give you full control of the IO and then to yank it back when
eval
needs to be executed and then return it afterwards. It's not that bad though.If you want to add some extra stuff to it, pull requests are welcome :)
Hi,
Been playing around with the Web Javascript API and have noticed that if you don't specify a callback on some functions the Puck will disconnect instantly. For example:
Here is what I want to do
Expect when I call the
resetLEDOnButtonClick
a while later the Puck has been disconnected.I've ended up having to pass empty callbacks everywhere just to stop it disconnecting. For example:
Is this expected or am I using the API wrong?