Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chugunov/socketio_emitter
socketio_emitter allows you to communicate with socket.io servers easily from Elixir processes.
https://github.com/chugunov/socketio_emitter
elixir emitter msgpack redix socket-io socket-io-client
Last synced: 2 months ago
JSON representation
socketio_emitter allows you to communicate with socket.io servers easily from Elixir processes.
- Host: GitHub
- URL: https://github.com/chugunov/socketio_emitter
- Owner: chugunov
- License: mit
- Created: 2017-07-03T15:15:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-01-12T14:48:51.000Z (about 3 years ago)
- Last Synced: 2024-03-14T21:05:25.119Z (10 months ago)
- Topics: elixir, emitter, msgpack, redix, socket-io, socket-io-client
- Language: Elixir
- Homepage:
- Size: 24.4 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socketio_emitter
[![Build Status](https://api.travis-ci.org/chugunov/socketio_emitter.svg?branch=master)](https://travis-ci.org/chugunov/socketio_emitter)
[![Hex.pm](https://img.shields.io/hexpm/v/socketio_emitter.svg)](https://hex.pm/packages/socketio_emitter)`socketio_emitter` allows you to communicate with socket.io servers easily from Elixir processes. Inspired by [socket.io-emitter](https://github.com/socketio/socket.io-emitter)
## Installation
The package can be installed
by adding `socketio_emitter` to your list of dependencies in `mix.exs`:```elixir
def deps do
[{:socketio_emitter, "~> 0.1.2"}]
end
```## How to use
Register `socketio_emitter` supervisor at your supervisor tree:
```elixir
defmodule ExampleApp do
use Applicationdef start(_type, _args) do
import Supervisor.Specchildren = [
# Add this line to your supervisor tree
supervisor(SocketIOEmitter, []),
]opts = [strategy: :one_for_one, name: ExampleApp.Supervisor]
Supervisor.start_link(children, opts)
end
end
```Then call `SocketIOEmitter.emit/2`:
```elixir
msg = %{:text => "hello"}# sending to all clients
{:ok, _consumers_count} = SocketIOEmitter.emit ["broadcast", msg]# sending to all clients in 'game' room
{:ok, _consumers_count} = SocketIOEmitter.emit ["new-game", msg],
rooms: ["game"]
# sending to individual socketid (private message)
{:ok, _consumers_count} = SocketIOEmitter.emit ["private", msg],
rooms: [socket_id]
# sending to all clients in 'admin' namespace
{:ok, _consumers_count} = SocketIOEmitter.emit ["namespace", msg],
nsp: "/admin"
# sending to all clients in 'admin' namespace and in 'notifications' room
{:ok, _consumers_count} = SocketIOEmitter.emit ["namespace", msg],
nsp: "/admin",
rooms: ["notifications"]
```## Configuration
You can configure `socketio_emitter` from your `config.exs`.
See the [redix documentation](https://hexdocs.pm/redix/Redix.html#start_link/2) for the possible values of `redix_config`.```elixir
use Mix.Configconfig :socketio_emitter, :redix_pool,
redix_config: [
# default value: localhost
host: "example.com",
# default value: 6379
port: 5000,
],
# 5 Redix processes will be available (default value: 1)
pool_size: 5
```
Or passing by parameters directly to supervisor, in this way values from config will be **overridden**:```elixir
redix_pool = [redix_config: [
host: "localhost",
port: 6379
], pool_size: 3]children = [
# Add this line to your supervisor tree
supervisor(SocketIOEmitter, [redix_pool], [name: :socket_emitter])
]
```## TODO
- tests
- documentation## License
MIT