Skip to main content

Websocket client for Phoenix Elixir

Project description

phxsocket

Synchronous phoenix websocket client using callbacks

Phoenix channels

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.1.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

phxsocket-0.0.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file phxsocket-0.0.1.tar.gz.

File metadata

  • Download URL: phxsocket-0.0.1.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for phxsocket-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b355fe205ef67054caa135449453a44c7b4f333c4bb621213388930e648a54cf
MD5 4a252bba8d11ea36056725a1d011be26
BLAKE2b-256 b4f342f53518f65689ce8452a55643eb47fa5a30db494b1abb5bd414488d1fac

See more details on using hashes here.

File details

Details for the file phxsocket-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: phxsocket-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for phxsocket-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f78e73ff972271b24eb39d4bec74b1670f01457a75c87d092cb70a0a30de3645
MD5 8267c5a27a6beca5efa238e2c8b1ed09
BLAKE2b-256 7be90a8336ef87ef7e21f8feaf6feeaac8709b0b1e86f0346bf6de47dab8af6e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page