Skip to content

Commit

Permalink
Merge pull request #147 from meteorrn/fix/connection-events
Browse files Browse the repository at this point in the history
Fix/connection events
  • Loading branch information
jankapunkt authored Feb 14, 2024
2 parents c77f0b6 + 8c26120 commit e0fad19
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 42 deletions.
2 changes: 1 addition & 1 deletion companion-packages/meteorrn-local/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"peerDependencies": {
"@meteorrn/core":">=2.0.7 || ^2.8.0-rc.1"
"@meteorrn/core":">=2.0.7 || ^2.8.1-rc.0"
}
}
2 changes: 1 addition & 1 deletion companion-packages/meteorrn-ndev-mfa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"peerDependencies": {
"@meteorrn/core":">=2.0.7"
"@meteorrn/core":">=2.0.7 || ^2.8.1-rc.0"
}
}
26 changes: 24 additions & 2 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteorrn/core",
"version": "2.8.0-rc.1",
"version": "2.8.1-rc.0",
"description": "Full Meteor Client for React Native",
"main": "src/index.js",
"repository": {
Expand Down Expand Up @@ -28,6 +28,7 @@
},
"homepage": "https://github.com/TheRealNate/meteor-react-native#readme",
"dependencies": {
"@meteorrn/core": "^2.8.1-rc.0",
"@meteorrn/minimongo": "1.0.1",
"ejson": "2.2.3",
"eventemitter3": "^5.0.1"
Expand Down
66 changes: 33 additions & 33 deletions src/Meteor.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,14 @@ const Meteor = {
Data._endpoint = endpoint;
Data._options = options;

this.ddp = Data.ddp = new DDP({
const ddp = new DDP({
endpoint: endpoint,
SocketConstructor: WebSocket,
...options,
});

if (options.NetInfo !== null) {
try {
const NetInfo = getNetInfo(options.NetInfo);

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) {
Data.ddp.connect();
}
}
);
} catch (e) {
console.warn(
'Warning: NetInfo not installed, so DDP will not automatically reconnect'
);
Data.ddp.connect();
}
} else {
Data.ddp.connect();
}
Data.ddp = ddp;
this.ddp = ddp;

Data.ddp.on('connected', () => {
// Clear the collections of any stale data in case this is a reconnect
Expand Down Expand Up @@ -326,9 +299,36 @@ const Meteor = {
}
}
});
Data.ddp.on('error', (message) => {
console.warn(message);
});

if (options.NetInfo !== null) {
try {
const NetInfo = getNetInfo(options.NetInfo);

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) {
Data.ddp.connect();
}
}
);
} catch (e) {
console.warn(
'Warning: NetInfo not installed, so DDP will not automatically reconnect'
);
Data.ddp.connect();
}
} else {
Data.ddp.connect();
}
},
subscribe(name) {
let params = Array.prototype.slice.call(arguments, 1);
Expand Down
8 changes: 5 additions & 3 deletions src/Tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ function _debugFunc() {
// on some browser we come across, like it was on IE 7).
//
// Lazy evaluation because `Meteor` does not exist right away.(??)
return typeof Meteor !== 'undefined'
? Meteor._debug
: typeof console !== 'undefined' && console.error
if (typeof Meteor !== 'undefined') {
return Meteor._debug;
}

return typeof console !== 'undefined' && console.error
? function () {
console.error.apply(console, arguments);
}
Expand Down
10 changes: 9 additions & 1 deletion src/user/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,15 @@ const User = {
_isTokenLogin: false,
_isCallingLogin: false,
_loginWithToken(value) {
Data._tokenIdSaved = value;
if (!value) {
Meteor.isVerbose &&
console.info(
'User._loginWithToken::: parameter value is null, will not save as token.'
);
} else {
Data._tokenIdSaved = value;
}

if (value !== null) {
this._isTokenLogin = true;
Meteor.isVerbose && console.info('User._loginWithToken::: token:', value);
Expand Down

0 comments on commit e0fad19

Please sign in to comment.