block some fetch requests by the service worker - service

I'm using SW in my PWA,
I have a fetch event, so every single request is intercepted by the SW,
i want to block in some "if cases", but it seems that the fetch event must return "event.respondWith()" synchronously.
I tried calling: event.preventDefault()
but it didnt work..

Related

Why isn't my firebase listener firing when the app is offline and initialized offline

I've setup a listener on my database that is only failing to respond in a weird offline scenario.
On setup I'm adding a listener to a database that should fire anytime there's an update...
let mySpots = self.databaseRefSpots.child("users").child(globalMasterUser.userUID).child("type").observe(.value, with: { snapshot in
//code that should be executed when there's an update.
Once the user takes some action that should get saved, it's saved to the firebase database using...
annotationdb.child("type").setValue("Feature")
annotationdb.child("properties").setValue(propDict)
annotationdb.child("geometry").setValue(["type":"Point"])
annotationdb.child("geometry").child("coordinates").setValue(coordinates)
This code works whenever the user is online, and when a user starts the app online and goes offline.
But, if the listener is created when the app is initialized in an offline state, it looks like the listener is setup successfully, but after my setValue's are called, the listener isn't called. If I turn the data connection on, at that point my listeners are called with the values I set with setValue.
Any idea why the listeners aren't firing in this offline state?
I've tried stepping through the firebase code to see if the listener is getting hit and it's not. I've tried creating separate listeners to catch this scenario and they wont fire either.

Is there a smart possibility to get API results without sending requests every second? [VueJS | Vuetify]

So I made a website to show which services on my server are running and which are offline.
The site is an Vuetify App running in a docker container. My services are monitored via UptimeRobot.
Currently I use:
created: function () {
this.interval = setInterval(() => this.getStatuses(), 1000);
},
To trigger my API request function every second to update the status of my services.
But is there some smarter possibility to only update on change and not request every second to see if something happened?
Like I send one request to get the status and then receive a message when something changed? I hope you can understand, whats my problem. It's hard to decribe.
Yes you can by firing an event. for example:
in your app.js
window.Fire = new Vue();
For example here you create a user then you want to update table after creating a new user, Follow these steps:
createUser(){
// FireUpdate is your fire name, you can give it any name you want!
// Call this after you post something to specific route.
Fire.$emit('FireUpadte');
}
Then you will load new users using this approach:
created(){
// Load new Users after created.
Fire.$on('FireUpadte', () => { this.createUser(); });
}
For more information check this video: https://www.youtube.com/watch?v=DHuTkJzH2jI&list=PLB4AdipoHpxaHDLIaMdtro1eXnQtl_UvE&index=20
What you're looking for are websockets. You establish a websocket connection and it stays open, allowing the server to notify the web app when something changes.
You can run your own socket.io server on a Node.js backend or use a service like Pusher.com (very cheap, free tier is pretty big).
I highly recommend going the Pusher.com route, they also have great tutorials ; )
https://pusher.com

Twilio always returns callstatus as 'completed' in statuscallback

I am making a call using Twilio using the following code
$call = $client->account->calls->create ($twilioPhoneNumber,
$customerPhoneNumber, // The number of the phone receiving call
$url,
$options); // The URL Twilio will request when the call is answered
In the options, I have the following parameters:
$options = array('StatusCallback'=>'twilioStatusCallback.php',
'IfMachine'=>'Hangup', 'FallbackUrl'=>'fallBack.php','Timeout'=>'15');
If the call is answered, and the Twilio menu goes through correctly, there is no problem.
But if the call is not answered or busy, Twilio still returns the call status as 'completed' to twilioStatusCallback.php
How can I get a correct busy or no-answer status instead?
Thanks.
Megan from Twilio here.
When you're making calls, the completed event is fired when the call is completed, regardless of the status.
You can create custom actions while tracking call status based upon the transitions between call state.

in-addr.arpa. responses not triggering callbacks in ServiceListener

I am trying to setup some ServiceListeners, in particular two:
zeroConf.addServiceListener("100.1.168.192.in-addr.arpa.", myListener);
zeroConf.addServiceListener("_workstation._tcp.local.", myListener);
Whenever I do this, I get callbacks for myListener on serviceResolved() and serviceAdded() for all services that match "_workstation._tcp.local." However, I get no callbacks for "100.1.168.192.in-addr.arpa." ... despite the fact that jmDns sends out the queries, and a response comes back! I've attached a tcpdump of the request packets that jmdns sends out, and the response that comes back for it. However, the callbacks are not called so I never see the response in my application.
Does anyone know why this might be happening?
http://users.ece.cmu.edu/~gnychis/jmdns_nocallback.pcap
After some debugging of the actual event type that comes in, the event type resolves to "_tcp.in-addr.arpa." Adding this to my service listeners triggers the call back.

How to kill a GWT RPC which has not yet completed

My code is for sending Emails to multiple users.User will click on send button,and rpc will be called. Now if user clicks on Cancel button .Ongoing rpc should be cancelled. . Can anyone help ?
I googled a lot, they have introduced the concept of Request Builder. But I am not getting any perfect idea.
Make your async method return a Request instead of void so you can call cancel() on it.
For the same reason, asynchronous methods do not have return types; they generally return void. Should you wish to have more control over the state of a pending request, return Request instead.
— Source: https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication#DevGuideCreatingServices
FYI, you can also use RequestBuilder as the return type, you'll then have to call the send() method by yourself (after possibly customizing the request, e.g. adding headers) to actually make the request to the server.
And of course, if you need to tell the server to abort the processing, you'll have to make another RPC call.
The request is asynch, so the client side can do anything it wants.
All you need to do is add a flag to indicate that the request should be cancelled, and then change the onSuccess method to check the flag and do nothing if it is set.
You should clear the requestCancelled flag each time you make a request - or else after the first request is cancelled, you won't be able to make another one...
e.g.
boolean requestCancelled = false;
void onSuccess(...)
{
if (!requestCancelled) {
// actual response handing code
}
}
If you really want to cancel the request on the server side, it is a lot more complicated. You could do this by sending a second request - one where the fuinctionality is to cancel a request.
To make this work, the "cancel request" has to set a field somewhere the "email request" can read. The "email request" needs to check if the "cancel field" has been set.
// server side Impl
void cancelRequest()
{
// You need to implement this class and ensure it really is a singleton
// and thread safe.
RequestStatusSingleton.setCancelled(true);
}
void serverSideEmailFunc()
{
while(modeEmailAddrs && ! RequestStatusSingleton.getCancelled()) {
// get next address and send email
}
}
Obviously this is a lot of work. Have you considered:
Not having a cancel button on your GUI?
Getting the server to process emails a few at a time (i.e. client sends multiple requests until server tells the client all emails are done).
I totally understand your user. No one wants to wait for 15 seconds.
There is no standard way to "kill" the request, because there is no way to know where your server/datastore is in implementing it. Unless you deal with a process that can be put in a single transaction that can be rolled back, you will have to implement your own logic. For example, if you asked the server to save an entity, you will have to tell the server to save this entity again, but this time without the changes.
Also, think again about your use case. Why a user wants to kill the request? May be he simply wants to go to another place in the app. Then there is no need to kill the request: when the response arrives, check if the user is still in the same place patiently waiting. If not, do not execute onSuccess().