viewing javascript console.log or opening camera on ios simulator - javascript

I implemented blinkid-react-native in react native ios app. blinkid-react-native will give me the ability to scan id's and veirfy the data on them. When i run my code i get json with only the address showing.
Since I can't open the camera to scan an id from the ios simulator. i deployed the app to test flight. i need to debug and see the javascript console.logs. I'm unable to do that from test flight?
I'm not sure about how to debug the issue? Since i can't open the camera on the ios simulator to run BlinkId and go thrugh console.logs.
here is the json the i get
here is BlinkId code
export const scanId = async () => {
console.log('BlinkId*****************');
const licenseKey = Platform.select({
ios:
'**********',
android:
'**********',
});
BlinkIDReactNative.SuccessFrameGrabberRecognizer(mrtdRecognizer);
var blinkIdCombinedRecognizer = new BlinkIDReactNative.BlinkIdCombinedRecognizer();
blinkIdCombinedRecognizer.returnFullDocumentImage = true;
blinkIdCombinedRecognizer.returnFaceImage = true;
const scanningResults = await BlinkIDReactNative.BlinkID.scanWithCamera(
new BlinkIDReactNative.BlinkIdOverlaySettings(),
new BlinkIDReactNative.RecognizerCollection([
blinkIdCombinedRecognizer /*, mrtdSuccessFrameGrabber*/,
]),
licenseKey,
)
.then((result) => handleResult(result))
.catch((e) => e);
return scanningResults;
};
console.log('BlinkId+scanningResults*****************');
console.log(this.scanningResults);
console.log('BlinkId+result1*****************');
console.log(this.result);
const handleResult = (result) => {
function buildResult(result, key) {
if (result && result != -1) {
return key + ': ' + result + '\n';
}
return '';
}
console.log('BlinkId+result2*****************');
console.log(result);
function buildDateResult(result, key) {
if (result) {
return (
key +
': ' +
result.day +
'.' +
result.month +
'.' +
result.year +
'.' +
'\n'
);
}
return '';
}
var localState = {
showFrontImageDocument: false,
resultFrontImageDocument: '',
showBackImageDocument: false,
resultBackImageDocument: '',
resultImageFace: '',
results: '',
showSuccessFrame: false,
successFrame: '',
};
console.log('BlinkId+result3*****************');
console.log(result);
if (result instanceof BlinkIDReactNative.BlinkIdCombinedRecognizerResult) {
let blinkIdResult = result;
console.log('BlinkId+blinkIdResult*****************');
console.log(blinkIdResult);
let resultString =
buildResult(blinkIdResult.firstName, 'First name') +
buildResult(blinkIdResult.lastName, 'Last name') +
buildResult(blinkIdResult.fullName, 'Full name') +
buildResult(blinkIdResult.localizedName, 'Localized name') +
buildResult(
blinkIdResult.additionalNameInformation,
'Additional name info',
) +
buildResult(blinkIdResult.address, 'Address') +
buildResult(
blinkIdResult.additionalAddressInformation,
'Additional address info',
) +
buildResult(blinkIdResult.documentNumber, 'Document number') +
buildResult(
blinkIdResult.documentAdditionalNumber,
'Additional document number',
) +
buildResult(blinkIdResult.sex, 'Sex') +
buildResult(blinkIdResult.issuingAuthority, 'Issuing authority') +
buildResult(blinkIdResult.nationality, 'Nationality') +
buildDateResult(blinkIdResult.dateOfBirth, 'Date of birth') +
buildResult(blinkIdResult.age, 'Age') +
buildDateResult(blinkIdResult.dateOfIssue, 'Date of issue') +
buildDateResult(blinkIdResult.dateOfExpiry, 'Date of expiry') +
buildResult(
blinkIdResult.dateOfExpiryPermanent,
'Date of expiry permanent',
) +
buildResult(blinkIdResult.expired, 'Expired') +
buildResult(blinkIdResult.maritalStatus, 'Martial status') +
buildResult(blinkIdResult.personalIdNumber, 'Personal id number') +
buildResult(blinkIdResult.profession, 'Profession') +
buildResult(blinkIdResult.race, 'Race') +
buildResult(blinkIdResult.religion, 'Religion') +
buildResult(blinkIdResult.residentialStatus, 'Residential status') +
buildResult(blinkIdResult.processingStatus, 'Processing status') +
buildResult(blinkIdResult.recognitionMode, 'Recognition mode');
let licenceInfo = blinkIdResult.driverLicenseDetailedInfo;
if (licenceInfo) {
resultString +=
buildResult(licenceInfo.restrictions, 'Restrictions') +
buildResult(licenceInfo.endorsements, 'Endorsements') +
buildResult(licenceInfo.vehicleClass, 'Vehicle class') +
buildResult(licenceInfo.conditions, 'Conditions');
}
// there are other fields to extract
localState.results += resultString;
// Document image is returned as Base64 encoded JPEG
if (blinkIdResult.fullDocumentFrontImage) {
localState.showFrontImageDocument = true;
localState.resultFrontImageDocument =
'data:image/jpg;base64,' + blinkIdResult.fullDocumentFrontImage;
}
if (blinkIdResult.fullDocumentBackImage) {
localState.showBackImageDocument = true;
localState.resultBackImageDocument =
'data:image/jpg;base64,' + blinkIdResult.fullDocumentBackImage;
}
// Face image is returned as Base64 encoded JPEG
if (blinkIdResult.faceImage) {
localState.showImageFace = true;
localState.resultImageFace =
'data:image/jpg;base64,' + blinkIdResult.faceImage;
}
} else {
throw JSON.stringify(result);
}
console.log('BlinkId+localState*****************');
console.log(localState);
return localState;
};

Related

Reactjs Show Real-Time Data from Database in Popup Window

I have a GUI that shows live data of little icons moving around based on the data from my postgresql database. When I click on one of the icons, a popup window shows with the data from the database. However, it only shows data on the time the icon was clicked and I want the data displayed to update as the database updates. I could really use some help.
The Popup Window Event
addClickEvent(id, source, publish) {
this.map.on('click', id, function (e) {
let description = ''
let trackId = e.features[0].properties.id
let trackSource = e.features[0].properties.track_source
let trackIdWithSource = trackId + '_' + source
//HELPFUL TIP: This will need to be updated when you bring over an update to base with the previous version
for (const [key, value] of Object.entries(e.features[0].properties)) {
if (isLowerCase(key)) {
}
else { description += key + ': ' + value + '\n' }
}
let trackWindow = document.getElementById("a" + trackIdWithSource);
if (!trackWindow) {
let trackDescription = document.createElement('div')
trackDescription.id = "a" + trackIdWithSource
trackDescription.innerHTML = description;
trackDescription.style.whiteSpace = "pre-wrap"
document.getElementById('root').appendChild(trackDescription)
new WindowModal({ size: { x: 'max-content', y: 200 }, pos: { x: 300, y: 25 }, title: trackIdWithSource + " Info: ", elementSelector: '#a' + trackIdWithSource })
}
trackWindow = document.getElementById("a" + trackIdWithSource);
//let trackContent = trackWindow.getElementsByClassName("WindowModal-content")
if (publish) {
if (!document.getElementById('publish_' + trackIdWithSource)) {
let publishButton = document.createElement('button')
publishButton.innerHTML = "Publish"
publishButton.id = "publish_" + trackIdWithSource
publishButton.onclick = function () {
let url = process.env.REACT_APP_PROTOCOL + '://' + process.env.REACT_APP_PUBLISH_API_HOST + ':' + process.env.REACT_APP_PUBLISH_API_PORT + '/track/' + trackId + '&' + trackSource + '/publish'
fetch(url, { method: 'post' })
.then(function (data) {
return console.log(data.status);
})
}
publishButton.className = "button"
trackWindow.insertBefore(publishButton, trackWindow.children[1])
}
}
});
const popup = new maplibregl.Popup({
closeButton: false,
closeOnClick: false
});
this.map.on("mouseenter", id, function (e) {
const coordinates = e.features[0].geometry.coordinates.slice();
let description = e.features[0].properties.id;
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
popup.setLngLat(coordinates)
.setHTML(description)
.addTo(this);
});
this.map.on('mouseleave', id, () => {
this.map.getCanvas().style.cursor = '';
popup.remove();
});
}

How to make variables optional while concatenation of string?

I am manipulating string to display in UI, Data is being dynamically with below code sometime i don't get header and details so how to make IHeader and IResponse optional for the string concatenation below.
if i dont have IHeader it will break at IHeader.id and throw exception i want to display whatever data is available to render.
main.js
const data = [{
id: "header",
name: "IHeader"
}, {
id: "param",
name: "IParams"
}, {
id: "details",
name: "IResponse"
}]
function buildText(data) {
var IParams;
var IResponse;
var IHeader;
for (var item of data) {
if (item.id === "param") {
IParams = item;
} else if (item.id === "header") {
IHeader = item;
} else if (item.id === "details") {
IResponse = item;
}
}
var text = '';
text += app + '.setConfig({\n' + "env:" + getEnv() + '\n});' + '\n\n';
text += 'let param:' + IParams.name + ' ' + '=' + '' + JSON.stringify(request, null, 4) + ';\n\n';
text += ref + '(' + 'param,(result:' + ' ' + '{' + '\n' + IHeader.id + ':' + IHeader.name + '\n' + IResponse.id + ':' + IResponse.name + '\n' + '})' + ' ' +
' => {\n console.log(result); \n});';
}
1 - You can try to create an object with empty values. That'll prevent the exception.
emptyObject = {id: ""} // more empty keys, if there is
IParam = (item.id === "param") ? item : emptyObject
2 - Or ignore that concatenation of the variable if undefined or null.
if (Iparam) {
// concatenation ..
}

Javascript If variable value type

I have the following function which populates elements options.
player.onTracksChanged_ = function(event) {
// Update the track lists.
var lists = {
video: document.getElementById('videoTracks'),
audio: document.getElementById('audiotrackButton'),
text: document.getElementById('captionButton')
};
var formatters = {
video: function(track) {
return track.width + 'x' + track.height + ', ' +
track.bandwidth + ' bits/s';
},
audio: function(track) {
return 'language: ' + track.language + ', ' +
track.bandwidth + ' bits/s';
},
text: function(track) {
return 'language: ' + track.language + ' ' +
'(' + track.kind + ')';
}
};
// Clear the old track lists.
Object.keys(lists).forEach(function(type) {
var list = lists[type];
while (list.firstChild) {
list.removeChild(list.firstChild);
}
});
// Populate with the new tracks.
var tracks = player.getTracks();
tracks.sort(function(t1, t2) {
// Sort by language, then by bandwidth.
if (t1.language) {
var ret = t1.language.localeCompare(t2.language);
if (ret) return ret;
}
return t1.bandwidth - t2.bandwidth;
});
tracks.forEach(function(track) {
var list = lists[track.type];
var option = document.createElement('option');
option.textContent = formatters[track.type](track);
option.track = track;
option.value = track.id;
option.selected = track.active;
list.appendChild(option);
});
};
What I am trying to achieve is an if statement based on this which determines if the number of each 'type' of 'track' is greater than or equal to 2, this is what I've got:-
var mediaTracks = player.getTracks();
if (mediaTracks.length >= 2) {
console.log('there are more than 2 tracks');
} else {
console.log('there are less than 2 tracks');
};
When in fact I need to do something more like this:-
var mediaTracksVideo = player.getTracks(video)
var mediaTracksAudio = player.getTracks(audio)
Then do something like:-
if (mediaTracksAudio >= 2) {...
But when I try player.getTracks(audio); the console logs 'audio is not defined'.
Any idea why?
With player.getTracks(audio) you're using the variable audio, which is undefined. You probably want to use player.getTracks('audio'), where 'audio' is a string.

beaglebone black not receiving serial bonescript

Beaglebone black - not receiving data on serial. I have connected Tx and Rx pins of the serial ports 1 and 2 directly (tx - rx). I'm kind of new to beaglebone. I used this code to send data on the serial to another device, it worked properly for transmission, but not for Rx.
I haven't found the file ttyO1, just ttyO2.
var b = require('bonescript');
var rxport = '/dev/ttyO1';
var txport = '/dev/ttyO2';
var options = { baudrate: 115200, parity: 'even', parser:
b.serialParsers.readline('\n') };
var teststring = "This is the string I'm sending out as a test";
b.serialOpen(rxport, options, onRxSerial);
function onRxSerial(x) {
console.log('rx.eventrx= ' + x.event);
if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
if(x.event == 'open') {
//readReapeatedly();
b.serialOpen(txport, options, onTxSerial);
}
if(x.event == 'data') {
console.log("I am receiving on rxport");
console.log('rx (' + x.data.length +
') = ' + x.data.toString('ascii'));
}
}
function onTxSerial(x) {
console.log('tx.event = ' + x.event);
if(x.err) throw('***FAIL*** ' + JSON.stringify(x));
if(x.event == 'open') {
writeRepeatedly();
}
if(x.event == 'data') {
console.log('tx (' + x.data.length +
') = ' + x.data.toString('ascii'));
console.log(x.data);
}
}
function printJSON(x) {
console.log(JSON.stringify(x));
}
function writeRepeatedly() {
console.log("write to serial");
b.serialWrite(txport, teststring, onSerialWrite);
console.log("I have sent data");
}
function onSerialWrite(x) {
console.log("Iam in the onSerialWrite function");
if(x.err) console.log('onSerialWrite err = ' + x.err);
if(x.event == 'callback') {setTimeout(writeRepeatedly, 5000);
console.log("HERE");
}
}

checking if busboy finish event has already occured or not

I have a form in which I am expected to do some file processing which takes some time, so I want that finish event executes only after the processing is complete, right now
node is processing the file and while it is processing the file and executes commands node if finds finish event it fires it. so, how do i make sure that the finish event is fired only after processing of all files.
busboy.on('file', function(fieldname, file, filename,transferEncoding,mimeType) {
var fName = uuid.v4();
var fileext = filename.substr(filename.lastIndexOf('.') + 1);
var filepath = path.normalize(__dirname + '/../../');
var fstream = fs.createWriteStream(filepath+'/server/uploads/'+fName+'.'+fileext);
var uploadFileCompletion = file.pipe(fstream);
uploadFileCompletion.on('finish',function(){
console.log('uploaded now');
var cmd = 'libreoffice --headless --convert-to pdf --outdir '+ filepath + 'server/uploads ' + filepath + 'server/uploads/' + fName + '.' + fileext;
exec(cmd, function(error,stdout,stderr){
sys.puts(stdout);
var encryptCmd = 'java -jar server/uploads/pdfbox-app-1.8.6.jar Encrypt -canAssemble false -canExtractContent false -canExtractForAccessibility false ' +
'-canModify false -canModifyAnnotations false -canPrint false -canPrintDegraded false server/uploads/' + fName + '.' + 'pdf'
+ ' ' + 'server/uploads/' +fName + '.' + 'pdf';
exec(encryptCmd, function(error,stdout,stderr){
fs.unlink(filepath+'server/uploads/'+fName + '.' + fileext, function(){
console.log("removed " +filepath+'server/uploads/'+fName + '.' + fileext);
actualFileName.push(filename);
storedFileName.push(fName+'.'+'pdf');
});
});
});
});
});
busboy.on('field', function(fieldname, val, valTruncated,keyTruncated) {
noteData = JSON.parse(val);
});
busboy.on('finish',function(){
noteData.uploader = req.user.username;
noteData.actualFileName = actualFileName;
noteData.storedFileName = storedFileName;
noteData.noteId = uuid.v4();
Campusnotes.create(noteData,function(err,note){
if(err){
res.status(400);
return res.send({reason:err.toString()});
}
console.log('finish');
res.status(200);
res.end();
})
});
now the console log for this is as follows -
finish
uploaded now
convert /home/unknown/public_html/campustop/server/uploads/8465f9a9-d6b7-4d53-8cb5-a8dbf3aed6a5.odt -> /home/unknown/public_html/campustop/server/uploads/8465f9a9-d6b7-4d53-8cb5-a8dbf3aed6a5.pdf using writer_pdf_Export
removed /home/unknown/public_html/campustop/server/uploads/8465f9a9-d6b7-4d53-8cb5-a8dbf3aed6a5.odt
indicating that the finish event is getting fired again and again
You could try something like:
var files = 0;
busboy.on('file', function(fieldname, file, filename,transferEncoding,mimeType) {
++files;
var fName = uuid.v4();
var fileext = filename.substr(filename.lastIndexOf('.') + 1);
var filepath = path.normalize(__dirname + '/../../');
var fstream = fs.createWriteStream(filepath+'/server/uploads/'+fName+'.'+fileext);
file.pipe(fstream).on('finish',function() {
console.log('uploaded now');
var cmd = 'libreoffice --headless --convert-to pdf --outdir '+ filepath + 'server/uploads ' + filepath + 'server/uploads/' + fName + '.' + fileext;
exec(cmd, function(error,stdout,stderr) {
console.log(stdout);
var encryptCmd = 'java -jar server/uploads/pdfbox-app-1.8.6.jar Encrypt -canAssemble false -canExtractContent false -canExtractForAccessibility false ' +
'-canModify false -canModifyAnnotations false -canPrint false -canPrintDegraded false server/uploads/' + fName + '.' + 'pdf'
+ ' ' + 'server/uploads/' +fName + '.' + 'pdf';
exec(encryptCmd, function(error,stdout,stderr) {
fs.unlink(filepath+'server/uploads/'+fName + '.' + fileext, function() {
console.log("removed " +filepath+'server/uploads/'+fName + '.' + fileext);
actualFileName.push(filename);
storedFileName.push(fName+'.'+'pdf');
});
});
--files;
onFinish();
});
});
});
busboy.on('field', function(fieldname, val, valTruncated,keyTruncated) {
noteData = JSON.parse(val);
});
busboy.on('finish', onFinish);
function onFinish() {
if (!busboy.writable && files === 0) {
noteData.uploader = req.user.username;
noteData.actualFileName = actualFileName;
noteData.storedFileName = storedFileName;
noteData.noteId = uuid.v4();
Campusnotes.create(noteData,function(err,note){
if (err){
res.status(400);
return res.send({reason:err.toString()});
}
console.log('finish');
res.status(200);
res.end();
});
}
}
On an unrelated note, you should probably do some sanitizing/checking of the filename, someone could be malicious and use something like '../../../../../../../../../etc/passwd' (I'm not sure if createWriteStream() resolves/normalizes the path given to it or not).

Categories

Resources