WebSockets on the websockets library (extra pyfect-dev[websockets];
Effect's NodeSocket.layerWebSocketConstructorWS; the server side,
NodeSocketServer.makeWebSocket, is pyfect.socket.server.make_web_socket).
WsWebSocket is a WebSocketLike over a websockets connection run
on the socket loop thread; its events are dispatched there. layer_web_socket_constructor
provides WebSocketConstructor with it, and layer_web_socket a client
Socket::
socket = make_web_socket("ws://127.0.0.1:8080").pipe(
provide(layer_web_socket_constructor)
)Re-exports#
Values#
| Attribute | Type | Description |
|---|---|---|
layer_web_socket_constructor | Layer[WebSocketConstructor] |
|
Classes#
Functions#
web_socket_constructor#
web_socket_constructor(*, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> WebSocketConstructorServiceWsWebSocket.connect with max_message_size (100 MiB by default, as ws's
maxPayload, what pyfect's servers take; None: no limit).
| Parameter | Type | Description |
|---|---|---|
max_message_size | int | None = DEFAULT_MAX_MESSAGE_SIZE |
Returns WebSocketConstructorService
def web_socket_constructor(
*, max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE
) -> WebSocketConstructorService:
"""``WsWebSocket.connect`` with ``max_message_size`` (100 MiB by default, as ``ws``'s
``maxPayload``, what pyfect's servers take; ``None``: no limit)."""
def construct(url: str, options: WebSocketClientOptions) -> WebSocketLike:
return WsWebSocket.connect(url, options, max_message_size=max_message_size)
return constructlayer_web_socket_constructor_with#
layer_web_socket_constructor_with(*, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> Layer[WebSocketConstructor]WebSocketConstructor on the websockets client, taking messages
up to max_message_size bytes.
| Parameter | Type | Description |
|---|---|---|
max_message_size | int | None = DEFAULT_MAX_MESSAGE_SIZE |
Returns Layer[WebSocketConstructor]
def layer_web_socket_constructor_with(
*, max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE
) -> Layer[WebSocketConstructor]:
"""``WebSocketConstructor`` on the ``websockets`` client, taking messages
up to ``max_message_size`` bytes."""
return layer_succeed(
WebSocketConstructor, web_socket_constructor(max_message_size=max_message_size)
)layer_web_socket#
layer_web_socket(url, *, open_timeout=None, protocols=None, headers=None, high_water_mark=None, max_message_size=DEFAULT_MAX_MESSAGE_SIZE) -> Layer[Socket]Socket as a WebSocket client on the websockets library; a
message longer than max_message_size bytes closes it with 1009.
| Parameter | Type | Description |
|---|---|---|
url | str | Effect[str] | |
open_timeout | DurationInput | None = None | |
protocols | str | Sequence[str] | None = None | |
headers | Mapping[str, str] | None = None | |
high_water_mark | int | None = None | |
max_message_size | int | None = DEFAULT_MAX_MESSAGE_SIZE |
Returns Layer[Socket]
def layer_web_socket(
url: str | Effect[str],
*,
open_timeout: DurationInput | None = None,
protocols: str | Sequence[str] | None = None,
headers: Mapping[str, str] | None = None,
high_water_mark: int | None = None,
max_message_size: int | None = DEFAULT_MAX_MESSAGE_SIZE,
) -> Layer[Socket]:
"""``Socket`` as a WebSocket client on the ``websockets`` library; a
message longer than ``max_message_size`` bytes closes it with 1009."""
client = layer_web_socket_with(
url,
open_timeout=open_timeout,
protocols=protocols,
headers=headers,
high_water_mark=high_water_mark,
)
constructor = layer_web_socket_constructor_with(max_message_size=max_message_size)
return client.pipe(layer_provide(constructor))make_server#
make_server(port=0, host=None, **serve_options) -> Effect[SocketServerService, SocketServerError, Scope]pyfect.socket.server.make_web_socket.
| Parameter | Type | Description |
|---|---|---|
port | int = 0 | |
host | str | None = None | |
serve_options | Any = {} |
Returns Effect[SocketServerService, SocketServerError, Scope]
@deprecated("Use pyfect.socket.server.make_web_socket; ws.make_server is removed in 0.7.0")
def make_server(
port: int = 0, host: str | None = None, **serve_options: Any
) -> Effect[SocketServerService, SocketServerError, Scope]:
"""``pyfect.socket.server.make_web_socket``."""
from pyfect.socket._ws_server import make_web_socket
return make_web_socket(port, host, **serve_options)layer_server#
layer_server(port=0, host=None, **serve_options) -> Layer[SocketServer, SocketServerError]pyfect.socket.server.layer_web_socket.
| Parameter | Type | Description |
|---|---|---|
port | int = 0 | |
host | str | None = None | |
serve_options | Any = {} |
Returns Layer[SocketServer, SocketServerError]
@deprecated("Use pyfect.socket.server.layer_web_socket; ws.layer_server is removed in 0.7.0")
def layer_server(
port: int = 0, host: str | None = None, **serve_options: Any
) -> Layer[SocketServer, SocketServerError]:
"""``pyfect.socket.server.layer_web_socket``."""
from pyfect.socket._ws_server import make_web_socket
return layer_effect(SocketServer, make_web_socket(port, host, **serve_options))