Chrome App - Cannot read property 'connect' of undefined - serial-port

I'm working on a Raspberry pi 3, I have a webpage that sends text data to a Chrome App, and everything works fine up to here.
After that the Chrome App should send that data to the serial port and here appears the error:
Error in event handler for runtime.onMessageExternal: TypeError: Cannot read property 'connect' of undefined
The problem could be that this is not a Chrome App, it's an Extension and it can't use this API cause only Chrome Apps have access to the hardware, but I followed this guide to make my first Chrome App (https://developer.chrome.com/apps/first_app), so maybe there's something i didn't understand or a step that i missed.
Here's my code, thanks in advance for the help!
manifest.json
{
"name": "Send serial data",
"description": "App to send serial data.",
"version": "1.0",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": { "16": "img-16.png", "128": "img-128.png" },
"externally_connectable" : {
"matches": ["*://localhost/*"]
}
}
background.js
var msg ;
function openSend(data) {
var onConnect ;
onConnect = function(connectionInfo) {
_this.connectionId = connectionInfo.connectionId;
}
chrome.serial.connect("/dev/ttyAMA0", {bitrate: 115200}, onConnect);
chrome.serial.send(connectionId, convertStringToArrayBuffer(data), function(sendInfo) {
if(sendInfo.error) $.modal('<div id="title">Unable to send data: ' + sendInfo.error + '</div>')
});
}
chrome.runtime.onMessageExternal.addListener((message, sender, sendResponse) => {
console.log(message.data);
msg = message.data ;
openSend(msg);
});

Solved, i just forgot to put this line of code in my manifest.json:
"permissions":["serial"],

Related

Firebase Dynamic Links doesn't navigate to deep link on iOS

Using Firebase Dynamic Links in a Managed Workflow Expo app directs to the correct deep link in the app on Android, but on iOS only opens the app in either whatever page was last open or the homepage.
app.config.js
ios: {
associatedDomains: [
'applinks:*.myapp.web.app',
'applinks:myapp.web.app',
'applinks:*.myapp.page.link',
'applinks:myapp.page.link',
],
},
AppNavigation.js
const linking = {
prefixes: [
prefix,
'https://myapp.web.app',
'https://*.myapp.web.app',
],
The apple-app-site-association file stored on myapp.web.app
{
"applinks": {
"apps": [],
"details": [
{
"appID": "1234567890.com.my.app",
"paths": [ "*" ]
}
]
}
}
The Dynamic Link is generated using REST API with the following payload:
const payload = {
dynamicLinkInfo: {
domainUriPrefix: 'https://myapp.page.link',
link: `https://myapp.web.app/${deepLink}`,
androidInfo: {
androidPackageName: com.my.app,
},
iosInfo: {
iosBundleId: com.my.app,
iosAppStoreId: 1234567890,
},
The generated Dynamic Link opens the app and directs to the ${deepLink} on Android as expected, but not on iOS. This was tested in an app built with EAS built.
Ended up solving this myself. Dynamic Links get resolved (converted from short link to full link) automatically on Android, but on iOS this has to be done manually with dynamicLinks().resolveLink(url);
After resolving, the link gets picked up by React Native Navigation and works like a normal deep link.
Full code for Dynamic Links:
const linking = {
prefixes: [
'https://myapp.page.link',
'https://myapp.web.app',
],
async getInitialURL() {
// If the app was opened with a Firebase Dynamic Link
const dynamicLink = await dynamicLinks().getInitialLink();
if (dynamicLink) {
const { url } = dynamicLink;
const resolvedLink = await dynamicLinks().resolveLink(url);
return resolvedLink.url;
}
// If the app was opened with any other link (sometimes the Dynamic Link also ends up here, so it needs to be resolved
const initialUrl = await Linking.getInitialURL();
if (initialUrl) {
const resolvedLink = await dynamicLinks().resolveLink(initialUrl);
return (resolvedLink) ? resolvedLink.url : initialUrl;
}
},
subscribe(listener) {
const handleDynamicLink = (dynamicLink) => {
listener(dynamicLink.url);
};
// Listen to incoming links from deep linking
const unsubscribeToDynamicLinks = dynamicLinks().onLink(handleDynamicLink);
return () => {
// Clean up the event listeners
unsubscribeToDynamicLinks();
};
},
};
In my case I also had to install all 3 of the following libraries:
"#react-native-firebase/analytics": "16.4.3",
"#react-native-firebase/app": "16.4.3",
"#react-native-firebase/dynamic-links": "16.4.3",

Firestore Call is freezing my app temporarily - Xcode/iOS/Firestore

I am making a call in my SwiftUI app which will add a document to my Cloud Firestore database. The issue is this is taking around 5 seconds to complete and rendering the app useless for those 5 seconds. I think this could also be down to the cloud functions running when the document is added however I am not sure.
I have tried, rather unsuccessfully so far I might add, to look at using other threads however this is to no avail. Can anyone provide some advice?
This is how I am calling the function:
Button(action: {
DispatchQueue.main.async{
addCard(time: "", text: "\(userSettings.username) Recorded")
}
}){
Text("Another One")
}
This is the actual function that is running.
func addCard(_ card: Card) {
do {
_ = try store.collection(path).addDocument(from: card)
} catch {
fatalError("Unable to add card: \(error.localizedDescription).")
}
}
As I think it could also be my Cloud Functions causing an issue, here it is too:
exports.logActivities = functions.firestore.document('/{collection}/{id}')
.onCreate((snap, context) => {
return admin.messaging().send({
"notification": {
"title": 'New Record',
"body": snap.data()['text'] + ' a new "Tell Em Lad"'
},
"apns": {
"payload": {
"aps": {
"sound": 'notiSound.wav'
}
}
},
"topic": 'client'
});
})
Any help would be greatly appreciated!

Dialogflow simulator not responding

I am testing a simple conversation from my dialogflow simulator using a fulfillment hosted in firebase functions.
And I am receiving the fulfillment response when triggered
But my simulator is showing this. Saying no response is received.
Please help
The complete RAW fulfillment response
{
"responseId": "99b660de-e2ca-4d8c-ace5-ef724fe5ee72",
"queryResult": {
"queryText": "male",
"parameters": {
"gender": "male"
},
"allRequiredParamsPresent": true,
"webhookPayload": {
"google": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Amazing"
}
}
]
},
"expectUserResponse": true,
"userStorage": "{\"data\":{}}"
}
},
"outputContexts": [
{
"name": "projects/assurance-purple/agent/sessions/bf891cbe-8642-eb61-ed7b-d6796adfab60/contexts/_actions_on_google",
"lifespanCount": 99,
"parameters": {
"data": "{}",
"gender.original": "male",
"gender": "male"
}
}
],
"intent": {
"name": "projects/assurance-purple/agent/intents/96b523a0-7a3a-4135-bdfc-d9d8ad16b661",
"displayName": "getGender"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 45
},
"languageCode": "en"
},
"webhookStatus": {
"message": "Webhook execution successful"
}
}
My actions on google Testing debug tab
`
{
"response": "We're sorry, but something went wrong. Please try again.",
"expectUserResponse": false,
"conversationToken": "",
"audioResponse": "",
"visualResponse": {
"visualElementsList": [
{
"displayText": {
"content": "Sorry, this action is not available in simulation"
}
}
],
"suggestionsList": [],
"agentLogoUrl": ""
},
"clientError": 4,
"is3pResponse": false
}
`
You don't show the entire response (copying and pasting it as text in your question would have been better), but it looks like you're sending a response back for an Action, but trying to test it in Dialogflow's conversation tool.
The Actions on Google response is slightly different than the response that Dialogflow expects to handle the additional features that the Assistant supports. Because of this, you need to use the Actions on Google simulator when testing your agent.
The Dialogflow test is looking for some specific fields to show the response that are not included with the actions-on-google library, and it will not show anything that is in a Google RichResponse object.
To summarize:
If you are working with an Action, use the Actions on Google simulator.
If you are working with other Dialogflow integrations, you can use the test tool on the right in Dialogflow.
Update
The error you're indicating from the AoG Simulator suggests that you're trying to just issue a statement in the conversation and not starting the Action, or that the Action has quit. Make sure you're talking to the action by starting it with "talk to my test app" or whatever the name of your Action is.

Using DDP in a Chrome extension

In the Chrome extension I am building, I would like to connect to a Meteor server from the extensions popup window, for user registration, login and
I've found a brief explanation from Meteor Spotting from 2014 that indicates that it is possible to do this using ddp.js, but the project it describes appears to have disappeared.
The current version of ddp.js uses import statements, which Chrome objects to. My understanding is that these scripts are designed for Node.js. How should I edit these scripts so that they can be used in a Chrome extension as described in the Meteor Spotting article?
Alternatively, is there any example of a bare-bones Chrome extension which connects with a bare-bones Meteor server via DPP, that I can use for inspiration?
I have found my own solution. Here is a bare-bones implementation of a call to a Meteor server from a Chrome extension:
manifest.json
{
"manifest_version": 2
, "name": "DDP Test"
, "version": "0.1"
, "background": {
"scripts": [
"jquery-3.1.0.js"
, "meteor-ddp.js"
, "meteor.js"
, "background.js"
]
}
}
jquery-3.1.0.js can be found here
eddfirs meteor-ddp.js can be found here
meteor.js (adapted from Meteor Spotting)
var Meteor
;(function meteor(){
"use strict"
var endpoint = "ws://localhost:3000/websocket"
// Use your own endpoint ^^^
Meteor = {
call : function(){
var args = [].slice.call(arguments)
var methodName = args.shift()
var callback = args.pop()
var ddp = new MeteorDdp(endpoint)
if (!(callback instanceof Function)) {
args.push(callback)
callback = function (error, data) {
console.log("Result of "+methodName+" call:", error, data)
}
}
ddp.connect().done(MeteorCall)
function MeteorCall() {
console.log('Connected!');
var $deferred = ddp.call(methodName, args)
$deferred.done(function (result) {
callback(null, result)
})
$deferred.fail(function (error) {
callback(error)
})
}
}
};
})()
background.js
;(function background(){
"use strict"
Meteor.call("test", 1, "two", { three: [4]})
Meteor.call("test", "using", "a", "custom", callback)
function callback(error, result) {
console.log("Custom callback error:", error, ", Result:", result)
}
})()
Output in the server console when the extension is loaded:
I20160917-19:35:19.352(-4)? test 1 two { three: [ 4 ] }
I20160917-19:35:19.377(-4)? test using a custom
Output in the Inspector for the background view:
Connected!
meteor.js:18 Result of test call: null test method activated with arguments {"0":1,"1":"two","2":{"three":[4]}}
meteor.js:25 Connected!
background.js:8 Custom callback error: null , Result: test method activated with arguments {"0":"using","1":"a","2":"custom"}

Can I send a blank alert message for APNS/GCM?

APNS Ex:
{
"content":
{
"aps":
{
"alert" : "",
"badge" : 37,
"sound" : "bingbong.aiff"
},
},
}
GCM Ex:
{
"content":
{
"registration_ids":
[
"abc...xyz",
"012...789",
"~!#...*_+"
],
"time_to_live":100,
"data":
{
"message":""
}
},
}
You can send a blank message. The question is what purpuse that blank message would serve.
In APNS, you can simply ommit the alert property from the payload, and no alert will be displayed (only the badge will be updated and the sound played).
In GCM, there is no special purpose to the message property. You can include whatever properties you wish inside the data dictionary, and it's up to you to decide what to do with those properties in your app.

Resources