How to disable offline persistence with react-redux-firebase - javascript

I have a web application with React, Redux that connects to the Firebase's Realtime Database. Implementation uses react-redux-firebase library and it works.
Out of the box, if the app goes temporarily offline, changes to store are saved locally and are then executed once online again. The feature is called "offline persistence" by Firebase. I want to turn this off - if the application is offline, no actions should work and later, when internet is reconnected, no changes should be pushed to server.
How can I do this? I can't find it in react-redux-firebase's documentation or configuration. Neither switching from Realtime Database to Firestore changes this. As a side problem, the app writes errors to the console while offline. Everything works, but once again, I don't know how to turn these logs off.
WebSocketConnection.ts:183 WebSocket connection to 'wss...' failed: Error in connection establishment: net::ERR_INTERNET_DISCONNECTED
WebSocketConnection.open # WebSocketConnection.ts:183
(anonymous) # Connection.ts:145
BrowserPollConnection.ts:745 GET https://... net::ERR_INTERNET_DISCONNECTED

You can detect whether the Firebase client is connected to the server by listening for the .info/connected node. When this is the case, you can prevent your code from sending any write operations to the database.
For an example of this, see the Firebase documentation on detecting connection state.

Related

IBM Websphere - Websockets (wss) - Connection to a websocket server in other profile

Good afternoon,
I come to request support here to try to understand a behavior that I have noticed in my application and that I cannot explain the reason why it happens.
Settings
I'm using Webshepere, version 9.0.0.11, in which a spring mvc application is running over HTTPS in a profile. This application performs the definition of values ​​in session (HttpSession), so that later, through the JSP, it is possible to obtain this data to be displayed in the browser.
On the client side, through js, a connection is made via WebSocket. The WebSocket server is located in another WebShepere profile.
Unexpected behavior
Whenever the websocket connection is successfully performed, all session data is deleted. Only the data that was recorded after successful connection is kept.
Additional data
If the WebSocket Server is installed in the same profile, the reported behavior no longer occurs, and the application works as expected.
if the application uses HTTP, the behaviour isn't presente.
on wildfly server, even with HTTPS, the behaviour is as expected, that means that session data isn`t deleted.
Default configuration
Application Address: https://myappurl:9444/
webSocket Server address: wss://myappurl:9450/websocket
After tests carried out, it was found that as the connection to the websocket was made to another port on the same domain, an override of the cookies was being carried out, thus eliminating the session data.
The solution went through, in the webshere's profile where the websoket server is located, changing the parameterization of the cookie name in the session management, from the default (JSESSIONID) to (JSESSIONIDA).
Path: Application servers > server1 > Web container > Session management > Cookies

How to establish a SSH MySQL database connection for a Electron App?

I'm making a app with the Electron Framework, within this the user needs to register an account to be able to use this app.
This worked great when making this for my localhost database, but creating connection with the MySQL server that is running on a dedicated server seems not working for me, and also insecure since people can unpack the .asar file and see the database credentials..
So, I've heard about 'SSH Connection' but can't figure out how to set this up, and get this up and running for my Electron app.
I am using XAMPP to create a MySQL/Apache server and I use HeidiSQL to enter the MySQL server.
For your info, I've never used Electron before and this is my first time using it. I've also never used a SSH connection before (at least, not that I'm aware of.) so a guide for newbies would be nice.

Does Firebase JavaScript API catch-up with server when re-connected

I have a question about Firebase's offline capabilities for JavaScript. Specifically, I am wondering if one were to lose connection while filling out a form on a web application (powered by firebase, obviously), and then try to send that form, would it perform a write operation to the local database, and then catch up with the server when connection is re-established, or would that data be lost? If this is a yes, I am assuming that it does not matter if the user exits out of the page, as long as the form as sent.
I know that it offers tremendous disk persistence for its iOS and Android SDKs, however I am just trying to get a better handle on how this can help in JavaScript. I am aware of the onDisconnectclass, and that it should mainly be used to manage the presence of a users as well - Just has this on mind for a while!
Thanks !
Firebase supports two types of offline mode:
in case of intermittent loss of connectivity, the client will keep serving events from the local data and any writes will be queued. When the connection is restored, all writes are sent to the server and any stale data is resynchronized. We often call this "tunnel mode".
The mobile native (iOS and Android) clients can be configured through their API to store all data on the local disk. In case of prolonged loss of connectivity, these clients will then queue writes on disk too. The client will also be able to serve data from this disk cache, when the app is restarted. This one we often call "airplane mode".
Tunnel mode is available in all Firebase SDKs. Airplane mode is only available in Firebase's native mobile SDKs for Android and iOS.

How to make an offline AngularJS/Cordova app?

I have a AngularJS app (embedded in a Cordova app).
To get and set data, it uses a REST API (that runs on a Django backend server).
I need that the app keeps working for several features even if the network is down.
For example, I'm expecting this kind of behaviour:
Online Mode
A client does something in the app
a POST request (to create data) is sent to the API
The client gets a "Thank you for doing xxx"
Fallback offline mode
A client buys something on the app
The client gets a "xxx can't be done right now, but it will be done as soon as possible"
Nothing can be sent to the server since we're offline. So how to do? Is there a way to put the API requests in a queue that will be executed when we're back to online mode?
How would you technically design this? It seems there is lots of differents technologies for offline mode, and it's a little bit confusing to me. Any guidance would be welcome.
Thanks a lot.
I would like to use such app, that would make me feel stupid. But there is
You can check network status with this plugin.
https://github.com/apache/cordova-plugin-network-information/blob/master/doc/index.md
Each request will need a switch between sending HTTP POST and saving POST data to local storage.
Then you would just create callbacks for following events:
document.addEventListener("offline", onOffline, false);
function onOffline() {
// Turn on saving to local storage
}
document.addEventListener("online", onOnline, false);
function onOnline() {
// Read local storage, send all requests
}
I'm not sure what the pressure in the comments are not to do this. We have this functionality in an app we are developing.
Basically we package up the iOS app as a Cordova wrapped web container and also run a local proxy server as part of the app. It passes all data through it to the web service. If the requests fail, it returns an identifier to the app so you can determine that the connection to the server is down, and the app then saves the requests to localStorage. That way the UI can adapt to being in "offline mode." you can later push data from the app through the proxy once the connection to the server is restored. The app connects directly to the proxy rather than to a webservice.
As far as I'm aware, there's not an easy library to solve this situation though, and you have to be aware of how the requests will affect the online application (can things go out of sync in your system, if the user runs requests that are cached until later?)
It is definitely something that can be done, though.

Socket.io - Preventing multiple connections from a client

I just got started in node.js and created a server where browser clients can connect to it.
Problem: When there is an error in the nodejs server and it crashes and restarts, the connected clients will usually reconnect automatically, but I notice that many clients usually make multiple reconnections back to the server!
How can I prevent that from happening, either serverside or clientside?
I suggest implementing it server-side. Apperantly, there is no implementation of it in socket.io (Source Code), so you can use key-value caches like Redis and map every connection in the Redis and check if user is already connected.

Categories