Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/copleykj/socialize-server-presence
A Meteor package to keep track of your running app instances and help you clean up the mess when they fail.
https://github.com/copleykj/socialize-server-presence
meteor meteor-package meteorjs presence servers sponsor
Last synced: 3 months ago
JSON representation
A Meteor package to keep track of your running app instances and help you clean up the mess when they fail.
- Host: GitHub
- URL: https://github.com/copleykj/socialize-server-presence
- Owner: copleykj
- License: mit
- Created: 2015-06-14T04:52:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-06T15:25:46.000Z (about 1 year ago)
- Last Synced: 2023-12-06T16:43:47.794Z (about 1 year ago)
- Topics: meteor, meteor-package, meteorjs, presence, servers, sponsor
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 3
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# Server Presence
This packages keeps track of servers running your application and provides a way to run cleanup tasks when they die
- [Supporting The Project](#supporting-the-project)
- [Installation](#installation)
- [API](#api)## Supporting The Project
Finding the time to maintain FOSS projects can be quite difficult. I am myself responsible for over 30 personal projects across 2 platforms, as well as Multiple others maintained by the [Meteor Community Packages](https://github.com/meteor-community-packages) organization. Therfore, if you appreciate my work, I ask that you either sponsor my work through GitHub, or donate via Paypal or Patreon. Every dollar helps give cause for spending my free time fielding issues, feature requests, pull requests and releasing updates. Info can be found in the "Sponsor this project" section of the [GitHub Repo](https://github.com/copleykj/socialize-server-presence)
## Installation
```shell
meteor add socialize:server-presence
```## API
**`ServerPresence.serverId();`** - Get the current Id of the server.
```javascript
Meteor.publish(null, function(){
if(this.userId && this._session){
var id = UserSessions.insert({serverId:ServerPresence.serverId(), userId:this.userId, sessionId:this._session.id});this.onStop(function(){
UserSessions.remove(id);
});
}
}, {is_auto:true});
```**`ServerPresence.registerCleanupFunction(function)`** - registers a function to clean up data related to a particular server. If the server died cleanly the function will be passed the ID of the server and you should take action to clean up data just for this particular server. If the server died without cleaning up after itself and was the only server instance running the cleanup function will be called without a serverId parameter and depending on your app you may want to do a global cleanup.
```javascript
ServerPresence.onCleanup(function(serverId){
if(serverId){
UserSessions.remove({serverId:serverId});
}else{
UserSessions.remove({});
}
});
```