fix(cordova): force DDP transport for time sync on Cordova/Capacitor#61
Conversation
|
Thank you for your contribution @BastienRodz |
|
Hello @harryadel ! |
|
On a side note, you mentioned Capacitor. I was interested how you managed to do it in your app. Any links/resources on that would be appreciated. Thanks! |
Add two Mocha tests under a 'transport selection' describe block:
- forces DDP on Meteor.isCordova=true — asserts Meteor.callAsync('_timeSync')
is used and globalThis.fetch to the sync URL is not. Reproduces the
scenario that motivated the fix (Cordova client with useDDP still false).
- uses HTTP on a plain browser — guards the else fetch(...) branch of
updateOffset() against accidental deletion, proving the fix does not
regress the web.browser path.
Both tests install spies on Meteor.callAsync and globalThis.fetch, drive
a TimeSync.resync(), and poll with simplePoll rather than a fixed timeout
to stay reliable under CI load.
|
Glad you asked - there is unfortunately no plug-and-play way to do this today, it's mostly glue around Meteor's existing
The short version of what we do in our app:
That's essentially it. It's ugly, but it lets us ship web, iOS and Android from a single Meteor codebase. Also worth knowing: on iOS the WebView reports |
|
@BastienRodz Universe works in weird way! Today I was working on migrating from Cordova to Capacitor. And now you're opening up a PR and I'm asking you about it lol. 🤣 Yes, I relied on https://forums.meteor.com/t/migrating-from-cordova-to-capacitor/63874 like you mentioned and it worked for the most part. Except for tiny error. I guess your setup is a lot more nuanced. It's important for @nachocodoner to take note of this. |
|
|
The previous fetch spy installed itself on globalThis.fetch, but timesync-client.js imports fetch from meteor/fetch as a module binding at load time. Replacing globalThis.fetch had no effect, so the browser regression test could never observe an HTTP sync and timed out. Switch to PerformanceObserver on 'resource' entries, which captures any fetch() to /_timesync regardless of how the caller references it.
|
Sorry, I was not paying enough attention. All fixed 👍 |
2e2cd43
into
Meteor-Community-Packages:feature/meteor3
Problem
On Cordova and Capacitor apps, the HTTP fetch to
/_timesynccan fail with CORS or URL resolution errors. This is a known class of issues (see #44, #52) that affects any Meteor 3 app running inside a mobile webview.The
web.cordovaarchitecture is used by both legacy Cordova apps and modern Capacitor setups (viaMETEOR_FORCE_INCLUDE_ARCHS="web.cordova"), soMeteor.isCordovaistruein both cases.Fix
Force DDP transport when
Meteor.isCordovaistrue:This is safe because:
forceDDP/useDDP)setSyncUrl()already special-cases Cordova (L51), acknowledging that HTTP routing behaves differently on mobile — this change alignsupdateOffset()with that same assumptionweb.browserclientsContext