When I try to fetch the cached by checking the offline button in dev tools.Its getting no internet connection error and I tried with turning off my wifi its getting cached data.
Offline Button
Offline check in Chrome inspect tools fully simulates offline network state, so you do not have to turn off your modem, wifi or network adapter while using it.
Observing response source
You can go to Chrome inspect > Network panel and look at the size column to check the origin of a response. By just looking at there you will be able to tell a request is served from browser cache, service worker or from network.
The error
If you are getting error because of your sw.js while you are offline, it is not a problem. It simply means it could not get service worker from network and it does not have to get it while you are offline anyway. See this answer for a more detailed information about it.
I recommend you to install Lighthouse extension for chrome it makes the testing way easier and the reports are quite useful.
Are you checking the 'fetch' event for the cache files? And are you sure you have the files cached ?
self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
Related
I try to make a angular 8 PWA app. So far so good, The cache is working in offline mode both for static resources and APIs.
But I'd like to inform the user about the offline state and let them know that the information displayed (API) is not necessarily up to date.
I tried to find a guide or doc about querying the service worker from angular, but found nothing. What is the best way - if any - to know if the service worker uses cache?
Thx.
Browser generates events 'offline' and 'online' depending on the network connectivity, you could listen on this event to inform the user:
window.addEventListener('online', hideOfflineIndicator);
window.addEventListener('offline', showOfflineIndicator);
function showOfflineIndicator() {
// Your code to inform the user they are offline.
}
function hideOfflineIndicator() {
// Your code to inform the user they are back online.
}
This has good browser support
More information on these events can be found here
I am having problems with understanding how to approach this problem as I am really new to xamarin and android both.
My problem is the following: I need to develop an android app, which takes photos of things and uploads them to a rest server. The confusing part is that the users have really poor connection, so I need to check the internet connection constantly and try to upload the photos when the internet is there. This check needs to be done in the background so the user wont notice any lag.
When the user clicks on "save" the app should save the photo and metadata to a local database or file (json or sqlite) and upload them when the internet is there.
I have tried many different approaches but failed due to lack of understanding how android threading and services work. (Bound service, Foregroundservice, SQLite)
As I dont have much time to research and test all the posibilities, I am asking you guys: How can I do this ?
Thanks for your understanding.
There is one nuget plugin Xam.Plugin.Connectivity for check internet continuously, and you can manage your code in event of this plugin.
For background, you need to create one background thread and you can call it from ConnectivityChanged event.
CrossConnectivity.Current.ConnectivityChanged += (object sender, Plugin.Connectivity.Abstractions.ConnectivityChangedEventArgs e) =>
{
if(e.IsConnected){
//your code here for fetching data when internet connected.
//Create task for background process
Task.Run(() =>
{
//your code for background
}).ConfigureAwait(false);
}
}
Im unable to connect to my Node server using Socket.io. I have been following these two tutorials http://www.appcoda.com/socket-io-chat-app/ and http://socket.io/get-started/chat/ but I cant seem to figure out where i'm going wrong. My goal is to connect my Node server to an ios app in Xcode. Here is the server file:
//require HTTP module/create server
var app = require ('http').createServer();
//Port Number
app.listen(3000)
//Run Server
var io = require('socket.io')(app);{
console.log('Listening on *:3000');
};
//Connection
io.on('connection', function(socket){
console.log('a user connected');
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
When I run the server via terminal, i get Listening on *:3000 as the output
(According to the tutorial) I then import the Socket.io Source folder and create the SocketIOManager.swift file as well as edit my AppDelegate.swift file
According to both tutorials I'm suppose to read a user connected when I open the simulator and user disconnected when i close it. However i get nothing in terminal. And i'm not sure what this means because i'm not getting any errors in Xcode.
Also when I run the server and open a browser i get the following:
I'm not sure if the browser issue relates or not but im putting it out there. Im only trying trying to connect my server to the app. I am looking forward to the a user connected message because that will verify a connection. If there is another way to test for a connection kindly let me know. Frankly, if there is a more simplified way to connect my server to the app, that would be greatly appreciated. I am open to any additional questions and of course comments.
Thank you in advance!
EDIT
I have SocketIOManager.sharedInstance.establishConnection() in my viewcontroller as is but I still cannot establish a connection. Can anyone shed some light?
I'm working on embedding a soft phone into a web page that will go into Odoo (web based ERP system). It will allow inbound and outbound calls for employees.
The token expires every hour. So this means the user will have to refresh the page every hour. I could do an http refresh but if the user is on a call when it does the refresh it will knock them off the call.
How do we get around this so we can build a fully working dialer?
Twilio evangelist here.
I'd suggest using JavaScript to do an asynchronous HTTP request to get a new token from your server and then updating the instance of client with it.
Hope that helps.
Another Twilio evangelist here!
You can actually listen for the offline event on the Twilio.Device object. From the documentation:
.offline( handler(device) )
Register a handler function to be called when the offline event is
fired. This is triggered when the connection to Twilio drops or the
device's capability token is invalid/expired. In either of these
scenarios, the device cannot receive incoming connections or make
outgoing connections. If the token expires during an active connection
the offline event handler will be called, but the connection will not
be terminated. In this situation you will have to call
Twilio.Device.setup() with a valid token before attempting or
receiving the next connection.
So you want something like:
Twilio.Device.offline(function(device) {
fetchTokenFromServer(function(token) {
device.setup(token);
});
});
where fetchTokenFromServer makes the HTTP request that Devin suggested in his answer.
Let me know if this helps.
I just ran into this issue so hopefully my solution can help you and others.
I was using twilio.js v1.3 and tried implementing my offline callback like #philnash recommended, but kept getting the error device.setup is not a function. I then tried using Twilio.Device.setup(newToken) and was able to get the capability token refreshed but also ended up getting a new error: Cannot read property 'setToken' of undefined.
I ended up having to use twilio.js v1.4 to make the error go away. My working solution looks like this:
Twilio.Device.offline(function(device) {
$.ajax(urlToGetNewToken, type: 'get').done(function(newToken) {
Twilio.Device.setup(newToken)
})
})
How long does it take to change the status from connecting to open using twilio device connection?
Since I see inconsistencies in connection and the connection remains in connecting status for a few and does not transition to open state requiring action to manually close the connection and restart again.
Satej, Megan from Twilio here.
There are a number of possible reasons for these inconsistencies. Among them are microphone access, browser settings and versions, or access to your token (i.e. it's expired). But there are also updates coming to version 1.3 of the Twilio.js library that could help isolate these issues.
In the meantime, be sure to put some status callback error handlers in place and include explicit code to disconnect the device and .disconnectAll().
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
...
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
function hangup() {
Twilio.Device.disconnectAll();
}