Skip to content

Commit

Permalink
Merge pull request #131 from meteorrn/dev
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
jankapunkt committed Sep 12, 2023
2 parents cb96f79 + 067c3f9 commit a6dec62
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 13 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@ node_modules
.vscode
.idea
.DS_Store

7 changes: 4 additions & 3 deletions companion-packages/meteorrn-local/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ const Local = {

LiveCol.find({}).observe({
added: async (doc) => {
LocalCol._collection.upsert(doc);
LocalCol.insert(doc);
storeLocalCol();
},
changed: async (doc) => {
LocalCol._collection.upsert(doc);
changed: async (changes, oldDoc) => {
delete changes._id;
LocalCol.update(oldDoc._id, { $set: changes });
storeLocalCol();
},
});
Expand Down
2 changes: 1 addition & 1 deletion companion-packages/meteorrn-local/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteorrn/local",
"version": "1.0.2",
"version": "1.0.3",
"description": "Store data locally",
"main": "index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Connect to the Meteor Server
- autoReconnect **boolean** [true] whether to try to reconnect to the server when the socket connection closes, unless the closing was initiated by a call to the disconnect method.
- reconnectInterval **number** [10000] the interval in ms between reconnection attempts.
- AsyncStorage **object** your preferred AsyncStorage. Defaults to `'@react-native-async-storage/async-storage'` as a peer dependency.
- reachabilityUrl **string** ["https://clients3.google.com/generate_204"] server to check internet reachability, used by NetInfo. If not provided, NetInfos default url will be used, which currently is `'https://clients3.google.com/generate_204'`

### `Meteor.disconnect()`

Expand Down
3 changes: 2 additions & 1 deletion lib/ddp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events';
import EventEmitter from 'eventemitter3';
import Queue from './queue';
import Socket from './socket';
import { uniqueId } from './utils';
Expand Down Expand Up @@ -115,6 +115,7 @@ export default class DDP extends EventEmitter {
this.socket.on('message:in', (message) => {
if (message.msg === 'connected') {
this.status = 'connected';
this._lastSessionId = message.session;
this.messageQueue.process();
this.emit('connected');
} else if (message.msg === 'ping') {
Expand Down
2 changes: 1 addition & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EventEmitter } from 'events';
import EventEmitter from 'eventemitter3';
import EJSON from 'ejson';
import './mongo-id'; // Register mongo object ids */

Expand Down
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteorrn/core",
"version": "2.5.1",
"version": "2.6.0",
"description": "Full Meteor Client for React Native",
"main": "src/index.js",
"repository": {
Expand Down Expand Up @@ -28,7 +28,8 @@
"homepage": "https://github.com/TheRealNate/meteor-react-native#readme",
"dependencies": {
"@meteorrn/minimongo": "1.0.1",
"ejson": "2.2.3"
"ejson": "2.2.3",
"eventemitter3": "^5.0.1"
},
"devDependencies": {
"@babel/core": "7.19.6",
Expand Down
16 changes: 16 additions & 0 deletions src/Meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,16 @@ const Meteor = {

try {
const NetInfo = require('@react-native-community/netinfo').default;

if (options.reachabilityUrl) {
NetInfo.configure({
reachabilityUrl: options.reachabilityUrl,
useNativeReachability: true,
});
}

// Reconnect if we lose internet

NetInfo.addEventListener(
({ type, isConnected, isInternetReachable, isWifiEnabled }) => {
if (isConnected && Data.ddp.autoReconnect) {
Expand Down Expand Up @@ -160,6 +169,13 @@ const Meteor = {
console.info('Disconnected from DDP server.');
}

// Mark subscriptions as ready=false
for (var i in Data.subscriptions) {
const sub = Data.subscriptions[i];
sub.ready = false;
sub.readyDeps.changed();
}

if (!Data.ddp.autoReconnect) return;

if (!lastDisconnect || new Date() - lastDisconnect > 3000) {
Expand Down
2 changes: 2 additions & 0 deletions src/user/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ const User = {
}
this._loadInitialUser();
}, time + 100);
} else if (err?.error === 403) {
User.logout();
} else {
User._handleLoginCallback(err, result);
}
Expand Down

0 comments on commit a6dec62

Please sign in to comment.