Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mainshayne233/lobby
In memory lobby for handling members and their state
https://github.com/mainshayne233/lobby
Last synced: 8 days ago
JSON representation
In memory lobby for handling members and their state
- Host: GitHub
- URL: https://github.com/mainshayne233/lobby
- Owner: MainShayne233
- Created: 2017-07-06T05:28:09.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-07-16T23:54:17.000Z (over 7 years ago)
- Last Synced: 2024-10-30T12:09:42.502Z (20 days ago)
- Language: Elixir
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lobby
In memory lobby that handles members and their states.
[![Build Status](https://travis-ci.org/MainShayne233/lobby.svg?branch=master)](https://travis-ci.org/MainShayne233/lobby)
[![Coverage Status](https://coveralls.io/repos/github/MainShayne233/lobby/badge.svg?branch=master)](https://coveralls.io/github/MainShayne233/lobby?branch=master)
[![Code Climate](https://codeclimate.com/github/MainShayne233/lobby/badges/gpa.svg)](https://codeclimate.com/github/MainShayne233/lobby)
[![Hex Version](http://img.shields.io/hexpm/v/lobby.svg?style=flat)](https://hex.pm/packages/lobby)## Install
In your `mix.exs` file, add `{:lobby, "~> 0.0.1"}` to the `deps`, like so:
```elixir
defp deps do
[
{:lobby, "~> 0.0.1"},
]
end
```
Then run `mix deps.get`## Use
Example of creating a lobby and handling members
```elixir# creating a named lobby
{:ok, _lobby} = Lobby.start_link(:my_lobby)# creating a new member of the lobby
{:ok, {member_id, member}} = Lobby.new_member(:my_lobby)# updating a lobby member
Lobby.update_member(:my_lobby, member_id, %{some_cool: "state"})# retrieving a lobby member
Lobby.get_member(:my_lobby, member_id)
#=>
{:ok, %{some_cool: "state"}}# retrieving entire lobby
Lobby.lobby(:my_lobby)
#=>
{:ok, %{
0 => %{some_cool: "state"},
}}# removing a lobby member
Lobby.remove_member(:my_lobby, member_id)Lobby.get_member(:my_lobby, member_id)
#=>
{:error, "No member for id"}
```## Use with Supervisor
Since `Lobby` is a GenServer, you can use it with Supervisor, and can be easily added to any already existing Supervisor module.
```elixir
defmodule YourApp do
use Applicationdef start(_type, _args) do
import Supervisor.Specchildren = [
supervisor(Lobby, [:my_lobby_name]),
]opts = [strategy: :one_for_one, name: YourApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
```Then you can just refer to your lobby by `:my_lobby_name` throughout your application.
## Roadmap
- Finalize implementation for how members are stored and fetched
- Currently stored in a map, where the member_id points to the member's state
- Maybe a more proper enum would be better?
- Add `!` versions of synchronous functions
- Add different unique key options (currently just an integer, maybe JWT?)
- Track member count for easy access to the total member count
- Add ability to persist state to disk as a background task## Contributing
I am extremely happy to receive pull requests for any bug fixes, new features, enhancements, etc. If you want to make a change, and you're not sure how to proceed, feel free to leave an issue on this repo explaining that and I'll totally work with you on making the change.