Websocket client for Phoenix Elixir
Project description
phxsocket
Synchronous phoenix websocket client using callbacks
Requirements
websocket_client
Usage
Import the package
import phxsocket
Create socket client
socket = phxsocket.Client("wss://target.url/websocket", {"options": "something"})
Connect and join a channel
def on_open(socket):
channel = socket.channel("room:roomname", {"more options": "something else"})
join_success, resp = self.channel.join()
def reconnect():
socket.connect()
socket.on_open = on_open
socket.on_error = lambda socket, message: (print(message), reconnect())
socket.connect()
Subscribe to events
def do_something(payload):
thing = payload["thing"]
channel.on("eventname", do_something)
Push data to a channel
channel.push("eventname", {"some": "data"})
Push data and wait for a response
message = channel.push("eventname", {"some": "data"}, reply=True)
response = message.wait_for_response() # blocking
Push data and react to the response with a callback
def respond(payload):
print(payload)
channel.push("eventname", {"some": "data"}, respond)
Leave a channel
channel.leave()
Disconnect
socket.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
phxsocket-0.0.2.tar.gz
(3.7 kB
view hashes)
Built Distribution
phxsocket-0.0.2-py3-none-any.whl
(16.5 kB
view hashes)
Close
Hashes for phxsocket-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fea7fc54c2f729bf33fb98f39363267ae8f239eeabd9ca0efa52a216bd3a96c1 |
|
MD5 | dcecc9c6c7c42c0fa61e680eec9403d0 |
|
BLAKE2b-256 | 08b553db04911a9afaa681c9182fa4c9d3f42a73e3828f5dd1d7cba42c34afa7 |