Closed ghost closed 1 month ago
Hi, is it possible to retrieve the data globally (because i have many input from the pages) when a hardware scanner captured the barcode? I have tested the sample code from the documentation but it does not work.
Hi @JustonJ99
I need more details.
What does it mean ? The data is sent in an event handler
do u mean not work handling of barcode ?
I think I get the same error ("its not working with external reader")
My Code:
window.broadcaster.addEventListener( 'de.someExternalBroadcast.SCAN_DATA', true, function( e ) { console.log( e ); });
broadcaster.js:84 Uncaught TypeError: Cannot set property type of #<Event> which has only a getter at Broadcaster.fireEvent (broadcaster.js:84:30) at <anonymous>:1:20
Broadcasted data is: {data: "25C6AE3E", secondaryData: null, type: "#41", typeExt: "HiTag1/S"}
Hi @kmitdebus thanks for sharing infos, I'll investigate as soon as possible
I think I get the same error ("its not working with external reader")
My Code:
window.broadcaster.addEventListener( 'de.someExternalBroadcast.SCAN_DATA', true, function( e ) { console.log( e ); });
broadcaster.js:84 Uncaught TypeError: Cannot set property type of #<Event> which has only a getter at Broadcaster.fireEvent (broadcaster.js:84:30) at <anonymous>:1:20
Broadcasted data is: {data: "25C6AE3E", secondaryData: null, type: "#41", typeExt: "HiTag1/S"}
I get the same error too, i find the issue in js code:
Broadcaster.prototype.fireEvent = function (type, data) {
if (!this._channelExists(type))
return;
var event = document.createEvent('Event');
event.initEvent(type, false, false);
if (data) {
for (var i in data) {
if (data.hasOwnProperty(i)) {
event[i] = data[i];
//^^^ will error when key is "type", "type" in event object is readonly
}
}
}
this._channelFire(event);
};
to fix that, special handling key "type" to another
Hi @lgl017 thanks for valuable feedback
Now there is another issue .... what's the best way to handle such problem:
data.type
property in event.dataType
I prefer the n. 2 what do you think ?
I think I get the same error ("its not working with external reader") My Code:
window.broadcaster.addEventListener( 'de.someExternalBroadcast.SCAN_DATA', true, function( e ) { console.log( e ); });
broadcaster.js:84 Uncaught TypeError: Cannot set property type of #<Event> which has only a getter at Broadcaster.fireEvent (broadcaster.js:84:30) at <anonymous>:1:20
Broadcasted data is: {data: "25C6AE3E", secondaryData: null, type: "#41", typeExt: "HiTag1/S"}I get the same error too, i find the issue in js code:
Broadcaster.prototype.fireEvent = function (type, data) { if (!this._channelExists(type)) return; var event = document.createEvent('Event'); event.initEvent(type, false, false); if (data) { for (var i in data) { if (data.hasOwnProperty(i)) { event[i] = data[i]; //^^^ will error when key is "type", "type" in event object is readonly } } } this._channelFire(event); };
to fix that, special handling key "type" to another
I've updated the fireEvent
code
Broadcaster.prototype.fireEvent = function (type, data) {
if (!this._channelExists(type))
return;
var event = new Event(type, { bubbles: false, cancelable: false });
if (data) {
event['data$'] = data; // fix issue #67
// for backward compatibility
for (var i in data) {
if (data.hasOwnProperty(i) && event[i] === undefined) {
event[i] = data[i];
}
}
}
this._channelFire(event);
}
The solution is to store the given data
object in a new Event.data$
property. For backward compatibility the data
properties will be added to Event
object skipping the ones already present in Event
itself.
So in the case of type
clashing to retrieve type
value we have to access the data
property:
// in the listener
var listener = function( e ) {
console.log( "type: ", e.data$.type );
}
fix released in 5.2.0
Hi, is it possible to retrieve the data globally (because i have many input from the pages) when a hardware scanner captured the barcode? I have tested the sample code from the documentation but it does not work.