copleykj / socialize-user-presence Goto Github PK
View Code? Open in Web Editor NEWSimple, scalable package to help your app keep track of your users online status.
License: MIT License
Simple, scalable package to help your app keep track of your users online status.
License: MIT License
Hi,
What is the most sensible way to track user-presence per route?
Thanks,
Hello Kelly, I was reading the server API and I wonder in which cases idle status can be enabled?
I saw that exists a method Meteor.user().setStatusIdle()
, however, I have doubt if also exists a default timeout to detect inactivity of the user and enable idle status automatically.
it happens that I have a monitoring application and I am getting a weird behavior, since devices (users) are disconnected after the 3rd or 5th day. In some cases, they're reconnected automatically (this is good) but in other cases they remain offline.
In the monitoring view I am only using two status: online and offline, if online property is true then the icon is green, otherwise is red. So, I am suspecting if "idle" is active in those cases, that is the possible reason they keep in red, so that's why my question.
On the other hand, I wonder if you have had a similar situation of this:
I am getting a weird behavior, since devices (users) are disconnected after the 3rd or 5th day.
Notes:
Server:
Client:
Front-end of web admin is using Vue since they are real users who operate the system.
When the package is imported to meteor project, the "Hot Code Push" of Meteor (from server side code) seems not to be working because the changes are not reflected. In the console only shows Meteor server restarted but when I invoke again a meteor method it executes the old code. To see the changes I have to disconnect and connect the ddp client or reload the browser.
I verified this behavior in different apps and even, I create a basic meteor project and I only added 2 packages: socialize:user-presence and mdg:validated-method. and the issue is still present.
You can reproduce this issue following the next steps:
import { ValidatedMethod } from 'meteor/mdg:validated-method';
new ValidatedMethod({
name: 'testMethod',
validate: null,
run() {
console.log('entry 4');//Change the number to test
return { hello: 'world 4' };//Change the number to test
}
});
meteor
You can use this mini project to verify it:
You can use Meteorman to test meteor methods.
Hi,
onUserOffline not fires up. I've just added it like this on server:
UserPresence.onUserOnline(function(userId){
Meteor.users.update({_id:userId}, {$set:{'profile.status':"online"}})
});
UserPresence.onUserOffline(function(userId){
console.log(userId);
Meteor.users.update({_id:userId}, {$set:{'profile.status':"offline"}})
});
onUserOnline - work fine.
But on Offline - nothing happens. Console.log not works too.
Any suggestions?
Thank you.
Hi Kelly, this work with React too or only React-Native?
thank you!
Perhaps I'm overlooking something, but it seems that this query should be { serverId: serverId }
instead, yes?
Thanks!
This package has a lot of dependencies.
aldeed:collection2 added, version 2.3.3
matb33:collection-hooks added, version 0.7.15
meteorhacks:unblock added, version 1.1.0
socialize:base-model added, version 0.2.3
socialize:server-presence added, version 0.1.2
socialize:server-time added, version 0.1.2
socialize:user-model added, version 0.1.4
socialize:user-presence added, version 0.2.1
tmeasday:publish-with-relations added, version 0.2.0
Most of them are from socialize:user-model which depends on socialize-base-model. Can user-model be removed or made optional? Is common/user-extensions.js the only place it's used?
Issue here
In
UserPresence.onSessionConnected(function(connection){
var userId = connection.userId;
});
run on the server, userId is always undefined. Any idea why?
Thanks!
Hi @copleykj , I'm trying to migrate from mizzao:user-status to this package due to a issue in the another package, however, I can't run my meteor app because appears this error:
W20201111-17:45:48.661(-6)? (STDERR) /Users/diavrank/.meteor/packages/meteor-tool/.1.11.1.95af9c.g0b4t++os.osx.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
W20201111-17:45:48.683(-6)? (STDERR) throw(ex);
W20201111-17:45:48.683(-6)? (STDERR) ^
W20201111-17:45:48.683(-6)? (STDERR)
W20201111-17:45:48.683(-6)? (STDERR) TypeError: Cannot read property 'RegEx' of undefined
W20201111-17:45:48.683(-6)? (STDERR) at module (packages/socialize:linkable-model/common/linkable-model.js:50:28)
W20201111-17:45:48.683(-6)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20201111-17:45:48.684(-6)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
W20201111-17:45:48.684(-6)? (STDERR) at Module.moduleLink [as link] (/Users/diavrank/.meteor/packages/modules/.0.15.0.tjvg00.6lcb++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/reify/lib/runtime/index.js:52:22)
W20201111-17:45:48.684(-6)? (STDERR) at module (packages/socialize:linkable-model/common/common.js:1:8)
W20201111-17:45:48.684(-6)? (STDERR) at fileEvaluate (packages/modules-runtime.js:336:7)
W20201111-17:45:48.684(-6)? (STDERR) at Module.require (packages/modules-runtime.js:238:14)
W20201111-17:45:48.684(-6)? (STDERR) at require (packages/modules-runtime.js:258:21)
W20201111-17:45:48.684(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/packages/socialize_linkable-model.js:149:15
W20201111-17:45:48.684(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/packages/socialize_linkable-model.js:154:3
W20201111-17:45:48.685(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/boot.js:401:38
W20201111-17:45:48.685(-6)? (STDERR) at Array.forEach (<anonymous>)
W20201111-17:45:48.685(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/boot.js:226:21
W20201111-17:45:48.685(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/boot.js:464:7
W20201111-17:45:48.685(-6)? (STDERR) at Function.run (/Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/profile.js:280:14)
W20201111-17:45:48.685(-6)? (STDERR) at /Users/diavrank/Documents/monitoreo-sismos/.meteor/local/build/programs/server/boot.js:463:13
My code is the following:
import { Meteor } from 'meteor/meteor';
import { User } from 'meteor/socialize:user-model';
import { UserPresence } from 'meteor/socialize:user-presence';
import Utilities from '../../startup/server/Utilities';
import SimpleSchema from 'simpl-schema';
// Schema for the fields where we will store the status data
const StatusSchema = new SimpleSchema({
status: Object,
'status.online': { type: Boolean },
'status.idle': { type: Boolean, optional: true },
'status.lastLogin': Object
});
// Add the schema to the existing schema currently attached to the User model
User.attachSchema(StatusSchema);
// If `sessionIds` is undefined this signifies we need a fresh start.
// When a full cleanup is necessary we will unset the status field to show all users as offline
UserPresence.onCleanup(function onCleanup(sessionIds) {
if (!sessionIds) {
console.log('cleanup sessionIds executed');
Meteor.users.update({}, { $set: { 'status.online': false }, $unset: { 'status.idle': true } }, { multi: true });
}
});
// When a user comes online we set their status to online and set the lastOnline field to the current time
UserPresence.onUserOnline(function onUserOnline(userId, connection) {
console.log('connection: ', connection);
Meteor.users.update(userId, { $set: { 'status.online': true, 'lastLogin.date': Utilities.currentLocalDate() } });
});
// When a user goes idle we'll set their status to indicate this
UserPresence.onUserIdle(function onUserIdle(userId) {
Meteor.users.update(userId, { $set: { 'status.idle': false } });
});
// When a user goes offline we'll unset their status field to indicate offline status
UserPresence.onUserOffline(function onUserOffline(userId) {
Meteor.users.update(userId, { $set: { 'status.online': false }, $unset: { 'status.idle': true } });
});
I already added the necessary packages and it doesn't work :( .
Meteor packages:
Yarn dependency:
(I also tried it with npm but neither work)
Do you know what could be the problem?
How to use it in the application?
I can not update the status of the user.
What about switching to this more maintained package for user presence? https://github.com/mizzao/meteor-user-status/
Client: Error: invoking Method 'updateSessionStatus': Internal server error [500]
Server: ReferenceError: determineStatus is not defined
when we call Meteor.user().setStatusOnline();
because determineStatus is not globally defined.
I'm trying to use onSessionConnected method on server side, but there is no userId field in connection object.
Connection object:
{
id: 'fc3LM2KyNs2GTvNo7',
close: [Function: close],
onClose: [Function: onClose],
clientAddress: '127.0.0.1',
httpHeaders: {
'x-forwarded-for': '127.0.0.1',
'x-forwarded-proto': 'ws',
host: 'localhost:3000',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50'
}
}
How can I get userId for connection?
Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.