PouchDB - Live sync got stuck, sometimes? - javascript

Introduction
We are using PouchDB 7.2.1 to synchronize a mobile PWA with a CouchDB to build up a Shared Context. In order to achieve this we use the bidirectional sync method from PouchDB. In the following code snippet you can see our parameters.
PouchDB.sync(
POUCH_DB,
`${internalUrl}/couchdb/${POUCH_DB}`,
{
auth: {
username: username,
password: password
},
live: true,
retry: true
};
The communication path can be described as:
PWA <---> Nginx (Reverse Proxy) <---> CouchDB (as a Docker-Container)
Description of the problem
PouchDB works well on PCs, iOS and some Android devices. From time to time, the long pool request on an Android device is frozen or does not disconnect, and PouchDB stopped the bidirectional synchronization. The client does not receive no updates anymore. The following snippet shows of the last request, we have recieved at our reverse proxy (nginx).
IP-Address - USER [17/Jan/2023:18:16:07 +0100] "GET /couchdb/dbname/_changes?style=all_docs&feed=longpoll&heartbeat=10000&since=...&limit=1
We have already checked:
Session-Timeout
Device is offline or not
Logs on all PouchDb events
Using no reverse proxy
Hopefully, someone have a possible solution for this problem.

Thanks to LyteFM. His comment helped us to isolate the problem.
We had a CouchDB Version prior 3.3.0. An upgrade to CouchDB to 3.3.1 solved our problem.

Related

How to disable offline persistence with react-redux-firebase

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.

ERR_CERT_COMMON_NAME_INVALID from jQuery Using Reverse Proxy

I am having an issue with 'ERR_CERT_COMMON_NAME_INVALID' when making a request from a website.
First of all, am really a bit of a novice when it comes to setting up and using certs... so this is probably something stupid that I have ether done or not done!
I have a ssl certificate www.my-dummy-url.abc and api.my-dummy-url.abc (obviously my-dummy-url is for example only). Where api.my-dummy-url.abc is the certificate Subject Alternative Name and www.my-dummy-url.abc is the certificate Subject.
The Apache Web sever, is hosted at www.my-dummy-url.abc, whilst a reverse proxy points 'api.my-dummy-url.abc to a Raspberry Pi running a little node.js API endpoint (/weather).
I have set node.js up to use express: https.createServer(ssl_options, ..., where ssl_options is my cert.pem and key.pem. CORS is enabled (app.use(cors());) and 'Access-Control-Allow-Origin', '*' is present in the response.
The Website (apart from the API call) renders fine at https://www.my-dummy-url.abc (Chrome).
The API, (https://api.my-dummy-url.abc/weather) if requested within the address bar of a Chrome browser or through Postman receives the correct JSON response.
However, from my website as a jQuery $.get function I get the following error:
GET https://api.my-dummy-url.abc/weather net::ERR_CERT_COMMON_NAME_INVALID
Any ideas, helpers, pointer or solutions will be gratefully received...
As an addition, if I use Edge rather then Chrome, it works...!
Kind Regards,
Harold Clements
This issue was that Chrome was caching the certificate somehow. After shutting down and coming back to it the next day, it was working fine.

Client-side, how to trust self-signed certificates from an IoT device?

I have an Expo app that works alongside an IoT device.
To connect to that device, the user goes on the device's wifi and sends it info about their wifi so that the device itself can connect to the wifi.
So far, that network call from device to app has been done using fetch to send a post to the IP address of the device, on a specific port. For example http://192.168.1.1:1234/
The team handling the device production has recently added SSL to this call, and now the network call should be made to https://192.168.1.1:1234/. They asked me to "Create a custom "TrustManager" and trust the self-signed certificate I have created."
The problem is that I can't find any information as to how I should trust the self-signed certificate using React Native. I can't even find a way to disable SSL certificate check just for testing purposes (which I can do with Postman for example and the network call works). I'm not even sure which direction to look into as most if not all info I found was specific to node and not client side.
As most of my expertise is in app building, I'm not that knowledgeable in regards to SSL certificates and I'm aware that maybe my comprehension of the problem is wrong and that I may be approaching it from the wrong side.
EDIT : This can't be done via Expo yet, but feel free to upvote the issue here
I haven't worked with IOT devices as such on React native, but I faced a similar problem when the APIs made didn't have the SSL certification done properly. I solved it by bypassing the SSL certification by using rn-fetch-blob (https://github.com/joltup/rn-fetch-blob).
You can try calling the API using rn-fetch-blob like this
RNFetchBlob.config({ trusty: true })
.fetch(
'POST',
'https://yourAPI',
{
'Content-Type': 'application/json',
},
dataObj
)
.then(res => console.log(res));

Firestore web Could not reach firestore backend

This is the error message : #firebase/firestore: Firestore (4.12.1): Could not reach Firestore backend
I am building a web app and it was working fine today and after a couple of login / logouts , I started receiving this error message. I have initialized the firestore config again and the problem persists. same error message was being thrown with firestore 4.11.0 version.
For future viewers, this error occurs when the Firebase SDK is unable to reach the Cloud Firestore service for a variety of reasons. We've since moved from Beta to General Availability for the service and SDKs and made several improvements since this was first asked.
A prime reason for this error is network connectivity where we cannot get a response from the service in a reasonable timeframe and then revert to offline mode (if enabled).
Another possible reason in Javascript libraries/frameworks are messing with functionality we rely upon in a now compatible way.
If you continue to encounter this issue and don't believe it's network connectivity relate, post a question on our discussion group or as a Github issue against the relevant client library.

architecture to Facebook-chat from a webpage, (XMPP? Strophe? Punjab?)

I would like to implement FB-chat inside a webpage. I looked around in Facebook API, i found out that chat is allowed only using XMPP. First I tried to connect to FB-chat using Pidgin and it worked fine. My conclusion was that FB-chat server is acting as the XMPP server. Is this true?
I read about XMPP, it seems that an open TCP connection should be established between the client and the server to exchange the XML stanzas which is not possible from a website (over JavaScript and without plugins) since only http requests/responses can be exchanges, no TCP connection there. This means that there should be some kind of a proxy in between, and as for authentication, FB API suggests to use the X-FACEBOOK-PLATFORM SASL (not the DIGEST MD5, since there is a proxy). I didn't find a clear tutorial or steps how to do so, help here is appreciated.
A bit more research about XMPP client from the web or browser, I saw that I am supposed to use a library called Strophe (based on BOSH protocol) and in other answers some kind of connection manager called Punjab. I read about this BOSH protocol, it seems to be the solution but in some places I found out that it is not allowed in FB (I am not sure how correct is this info though). I tried to setup these but i was totally confused how to begin and what I am really supposed to do.
For the strophe, I didn't find a real tutorial how to implement it, and in what i found, they suggest to first setup a jabber server like ejabberd (I didnt get the need for that).
My question is:
Can somebody suggest an architecture that I should implement to achieve my goal?
So will there be: webpage ->(HTTP) -> Strophe -> (TCP) -> FB-chat OR will it have an XMPP server in between and why?
I would appreciate any answer to any of my questions. Please suggest some links to how to implement all these stuff. I am totally new to all this which made me lost for more than a week now.
If somebody already did this, please help.
Thanks a lot.
Sabah
Informations about facebook chat server :
Protocol: XMPP or Jabber
Username: mathvdh
Domain: chat.facebook.com
Jabber ID: mathvdh#chat.facebook.com
Password: <your Facebook password>
Port: 5222
Server: chat.facebook.com
Use SSL/TLS: no
Allow plaintext authentication: no
I think strophe and punjab should be a working combination for fb chat, see here : XMPP library for facebook chat
And I think the schema would be more like :
client webpage/js/strophe <-> yourserver/punjab <-> facebook xmpp chat server
I'm trying to solve this problem too. So far I have decided on a set up of:
Jappix mini (uses JSJAC.js library) <-> node-xmpp-bosh on node.js on my server <-> Facebook server.
Jappix mini was hard to find but it seems by far the best open source chat bar so worth mentioning here.
I don't have it all set up yet but will update here if I make progress. The main issue will be how to make JSJAC use Facebook API Key authentication. I can't find any info or examples for that, but I found this plugin for strophe library which maybe can be adapted:
https://github.com/rubenjgarciab/turedsocial/blob/master/strophe-plugins/src/facebook.js
Finally, you cannot include your facebook secret key in javascript (because it's a secret!) so you need to use Facebook REST API auth.promoteSession server-side to produce a session-secret key which can be used in the javascript to sign the X-FACEBOOK-PLATFORM auth request.
Hope that helps, I'll add more if/when I get it working.
Sabah,
As mentioned in the previous answers the Punjab <-> strophe.js works. I have forked the facebook strophe client here: https://github.com/javierfigueroa/turedsocial and I added an example.
Hope this helps.

Categories