Coder Social home page Coder Social logo

chugunov / socketio_emitter Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 1.0 25 KB

socketio_emitter allows you to communicate with socket.io servers easily from Elixir processes.

License: MIT License

Elixir 100.00%
elixir socket-io socket-io-client msgpack redix emitter

socketio_emitter's Introduction

socketio_emitter

Build Status Hex.pm

socketio_emitter allows you to communicate with socket.io servers easily from Elixir processes. Inspired by socket.io-emitter

Installation

The package can be installed by adding socketio_emitter to your list of dependencies in mix.exs:

def deps do
  [{:socketio_emitter, "~> 0.1.2"}]
end

How to use

Register socketio_emitter supervisor at your supervisor tree:

defmodule ExampleApp do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec

    children = [
      # 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:

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 for the possible values of redix_config.

use Mix.Config

config :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:

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

socketio_emitter's People

Contributors

chugunov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

adrian7123

socketio_emitter's Issues

why does it depend on redix?

I don't understand why this package relies on redix to emit messages.
I'm trying to connect to a third party socket.io server and they don't have any information on redis support.

Can I still use this to connect with their socket.io server?
The socket.io server url I'm trying to connect is https://ws-api.iextrading.com/1.0/tops (here's a example),
if this package can do it, how should I configure?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.