pondsocket 0.0.1__tar.gz → 0.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pondsocket-0.0.1 → pondsocket-0.0.2}/PKG-INFO +2 -2
- {pondsocket-0.0.1 → pondsocket-0.0.2}/pyproject.toml +2 -2
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/channel.py +136 -3
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/pubsub.py +7 -2
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_pubsub.py +4 -4
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_smoke.py +1 -1
- {pondsocket-0.0.1 → pondsocket-0.0.2}/.gitignore +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/README.md +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/__init__.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/__init__.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/connection_context.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/event_context.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/join_context.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/leave_context.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/contexts/outgoing_context.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/distributed/__init__.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/distributed/redis_pubsub.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/endpoint.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/errors.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/hooks.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/in_memory_transport.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/lobby.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/middleware.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/parser.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/presence.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/pubsub_local.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/py.typed +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/server.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/sse_transport.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/store.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/transport.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/types.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/src/pondsocket/wire.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_channel.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_distributed_local.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_errors.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_hooks_integration.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_hooks_unit.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_in_memory_transport.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_integration.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_middleware.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_parser.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_presence.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_redis_pubsub.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_sse_transport.py +0 -0
- {pondsocket-0.0.1 → pondsocket-0.0.2}/tests/test_pondsocket_store.py +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pondsocket
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: PondSocket - channel-based real-time framework with bring-your-own-server design.
|
|
5
5
|
Author: eleven-am
|
|
6
6
|
License: GPL-3.0-or-later
|
|
7
7
|
Requires-Python: >=3.11
|
|
8
|
-
Requires-Dist: pondsocket-common<0.1.0,>=0.0.
|
|
8
|
+
Requires-Dist: pondsocket-common<0.1.0,>=0.0.2
|
|
9
9
|
Provides-Extra: redis
|
|
10
10
|
Requires-Dist: redis>=5; extra == 'redis'
|
|
11
11
|
Description-Content-Type: text/markdown
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pondsocket"
|
|
3
|
-
version = "0.0.
|
|
3
|
+
version = "0.0.2"
|
|
4
4
|
description = "PondSocket - channel-based real-time framework with bring-your-own-server design."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = { text = "GPL-3.0-or-later" }
|
|
8
8
|
authors = [{ name = "eleven-am" }]
|
|
9
9
|
dependencies = [
|
|
10
|
-
"pondsocket-common>=0.0.
|
|
10
|
+
"pondsocket-common>=0.0.2,<0.1.0",
|
|
11
11
|
]
|
|
12
12
|
|
|
13
13
|
[project.optional-dependencies]
|
|
@@ -26,6 +26,7 @@ from .types import (
|
|
|
26
26
|
AllExceptSender,
|
|
27
27
|
AllUsers,
|
|
28
28
|
Event,
|
|
29
|
+
InternalActions,
|
|
29
30
|
LeaveReason,
|
|
30
31
|
MessageEvent,
|
|
31
32
|
Options,
|
|
@@ -34,7 +35,6 @@ from .types import (
|
|
|
34
35
|
ToUsers,
|
|
35
36
|
User,
|
|
36
37
|
)
|
|
37
|
-
from .wire import event_to_pubsub_bytes, pubsub_bytes_to_event
|
|
38
38
|
|
|
39
39
|
LeaveHandler: TypeAlias = Callable[[LeaveContext], Awaitable[None]]
|
|
40
40
|
LeaveMiddlewareFn: TypeAlias = Callable[
|
|
@@ -497,12 +497,15 @@ class Channel:
|
|
|
497
497
|
return
|
|
498
498
|
topic = format_topic(self._clean_endpoint(), self.name, event_subtype)
|
|
499
499
|
try:
|
|
500
|
-
await self._pubsub.publish(
|
|
500
|
+
await self._pubsub.publish(
|
|
501
|
+
topic,
|
|
502
|
+
_event_to_distributed_bytes(event, event_subtype, self._clean_endpoint()),
|
|
503
|
+
)
|
|
501
504
|
except Exception:
|
|
502
505
|
return
|
|
503
506
|
|
|
504
507
|
async def _handle_pubsub_message(self, _topic: str, data: bytes) -> None:
|
|
505
|
-
event =
|
|
508
|
+
event = _distributed_bytes_to_event(data)
|
|
506
509
|
if event is None:
|
|
507
510
|
return
|
|
508
511
|
if event.node_id and event.node_id == self.node_id:
|
|
@@ -578,3 +581,133 @@ class Channel:
|
|
|
578
581
|
await hooks.after_message(event, err)
|
|
579
582
|
except Exception:
|
|
580
583
|
return
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
def _now_ms() -> int:
|
|
587
|
+
import time
|
|
588
|
+
|
|
589
|
+
return int(time.time() * 1000)
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
def _event_to_distributed_bytes(event: Event, subtype: str, endpoint: str) -> bytes:
|
|
593
|
+
import json
|
|
594
|
+
|
|
595
|
+
if event.action == ServerActions.BROADCAST.value:
|
|
596
|
+
message_type = "USER_MESSAGE"
|
|
597
|
+
elif event.action == ServerActions.PRESENCE.value and (
|
|
598
|
+
subtype.endswith("remove") or event.event == "LEAVE"
|
|
599
|
+
):
|
|
600
|
+
message_type = "PRESENCE_REMOVED"
|
|
601
|
+
elif event.action == ServerActions.PRESENCE.value:
|
|
602
|
+
message_type = "PRESENCE_UPDATE"
|
|
603
|
+
elif event.action == InternalActions.ASSIGNS.value:
|
|
604
|
+
message_type = "ASSIGNS_UPDATE"
|
|
605
|
+
elif event.action == InternalActions.USER_COMMAND.value and event.event == "user:remove":
|
|
606
|
+
message_type = "USER_REMOVE"
|
|
607
|
+
elif event.action == InternalActions.USER_COMMAND.value:
|
|
608
|
+
message_type = "EVICT_USER"
|
|
609
|
+
else:
|
|
610
|
+
message_type = "USER_MESSAGE"
|
|
611
|
+
|
|
612
|
+
envelope: dict[str, object] = {
|
|
613
|
+
"protocol": "pondsocket.distributed",
|
|
614
|
+
"version": 1,
|
|
615
|
+
"type": message_type,
|
|
616
|
+
"messageId": uuid(),
|
|
617
|
+
"sourceNodeId": event.node_id,
|
|
618
|
+
"endpointName": endpoint,
|
|
619
|
+
"channelName": event.channel_name,
|
|
620
|
+
"timestamp": _now_ms(),
|
|
621
|
+
}
|
|
622
|
+
if message_type == "USER_MESSAGE":
|
|
623
|
+
envelope.update(
|
|
624
|
+
{
|
|
625
|
+
"fromUserId": "CHANNEL",
|
|
626
|
+
"event": event.event,
|
|
627
|
+
"payload": event.payload if event.payload is not None else {},
|
|
628
|
+
"requestId": event.request_id,
|
|
629
|
+
"recipientDescriptor": "ALL_USERS",
|
|
630
|
+
}
|
|
631
|
+
)
|
|
632
|
+
elif message_type == "PRESENCE_UPDATE":
|
|
633
|
+
payload = event.payload if isinstance(event.payload, dict) else {}
|
|
634
|
+
envelope["event"] = event.event
|
|
635
|
+
envelope["userId"] = ""
|
|
636
|
+
envelope["presence"] = payload.get("changed", {})
|
|
637
|
+
elif message_type == "PRESENCE_REMOVED":
|
|
638
|
+
envelope["userId"] = ""
|
|
639
|
+
elif message_type == "ASSIGNS_UPDATE":
|
|
640
|
+
envelope["userId"] = event.payload.get("userId", "") if isinstance(event.payload, dict) else ""
|
|
641
|
+
envelope["assigns"] = event.payload if isinstance(event.payload, dict) else {}
|
|
642
|
+
elif message_type in {"EVICT_USER", "USER_REMOVE"}:
|
|
643
|
+
payload = event.payload if isinstance(event.payload, dict) else {}
|
|
644
|
+
envelope["userId"] = payload.get("userId", "")
|
|
645
|
+
envelope["reason"] = payload.get("reason", "")
|
|
646
|
+
return json.dumps(envelope, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
def _distributed_bytes_to_event(data: bytes) -> Event | None:
|
|
650
|
+
import json
|
|
651
|
+
|
|
652
|
+
try:
|
|
653
|
+
raw = json.loads(data.decode("utf-8"))
|
|
654
|
+
except (UnicodeDecodeError, json.JSONDecodeError):
|
|
655
|
+
return None
|
|
656
|
+
if not isinstance(raw, dict):
|
|
657
|
+
return None
|
|
658
|
+
if raw.get("protocol") != "pondsocket.distributed":
|
|
659
|
+
return None
|
|
660
|
+
if raw.get("version") != 1:
|
|
661
|
+
return None
|
|
662
|
+
message_type = raw.get("type")
|
|
663
|
+
channel_name = raw.get("channelName")
|
|
664
|
+
node_id = raw.get("sourceNodeId")
|
|
665
|
+
if not isinstance(message_type, str) or not isinstance(channel_name, str) or not isinstance(node_id, str):
|
|
666
|
+
return None
|
|
667
|
+
request_id = str(raw.get("requestId") or uuid())
|
|
668
|
+
if message_type == "USER_MESSAGE":
|
|
669
|
+
return Event(
|
|
670
|
+
action=ServerActions.BROADCAST.value,
|
|
671
|
+
channel_name=channel_name,
|
|
672
|
+
request_id=request_id,
|
|
673
|
+
event=str(raw.get("event") or ""),
|
|
674
|
+
payload=raw.get("payload") if raw.get("payload") is not None else {},
|
|
675
|
+
node_id=node_id,
|
|
676
|
+
)
|
|
677
|
+
if message_type == "PRESENCE_UPDATE":
|
|
678
|
+
return Event(
|
|
679
|
+
action=ServerActions.PRESENCE.value,
|
|
680
|
+
channel_name=channel_name,
|
|
681
|
+
request_id=request_id,
|
|
682
|
+
event=str(raw.get("event") or PresenceEventTypes.UPDATE.value),
|
|
683
|
+
payload={"presence": [], "changed": raw.get("presence") or {}},
|
|
684
|
+
node_id=node_id,
|
|
685
|
+
)
|
|
686
|
+
if message_type == "PRESENCE_REMOVED":
|
|
687
|
+
return Event(
|
|
688
|
+
action=ServerActions.PRESENCE.value,
|
|
689
|
+
channel_name=channel_name,
|
|
690
|
+
request_id=request_id,
|
|
691
|
+
event=PresenceEventTypes.LEAVE.value,
|
|
692
|
+
payload={"presence": [], "changed": {"userId": raw.get("userId") or ""}},
|
|
693
|
+
node_id=node_id,
|
|
694
|
+
)
|
|
695
|
+
if message_type == "ASSIGNS_UPDATE":
|
|
696
|
+
return Event(
|
|
697
|
+
action=InternalActions.ASSIGNS.value,
|
|
698
|
+
channel_name=channel_name,
|
|
699
|
+
request_id=request_id,
|
|
700
|
+
event="assigns:update",
|
|
701
|
+
payload={"userId": raw.get("userId") or "", "assigns": raw.get("assigns") or {}},
|
|
702
|
+
node_id=node_id,
|
|
703
|
+
)
|
|
704
|
+
if message_type in {"EVICT_USER", "USER_REMOVE"}:
|
|
705
|
+
return Event(
|
|
706
|
+
action=InternalActions.USER_COMMAND.value,
|
|
707
|
+
channel_name=channel_name,
|
|
708
|
+
request_id=request_id,
|
|
709
|
+
event="user:remove" if message_type == "USER_REMOVE" else "user:evict",
|
|
710
|
+
payload={"userId": raw.get("userId") or "", "reason": raw.get("reason") or ""},
|
|
711
|
+
node_id=node_id,
|
|
712
|
+
)
|
|
713
|
+
return None
|
|
@@ -29,7 +29,12 @@ def match_topic(pattern: str, topic: str) -> bool:
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
def format_topic(endpoint: str, channel: str, event: str) -> str:
|
|
32
|
-
|
|
32
|
+
del event
|
|
33
|
+
return f"pondsocket:v1:default:{endpoint}:{channel}"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def format_heartbeat_topic() -> str:
|
|
37
|
+
return "pondsocket:v1:default:__heartbeat__"
|
|
33
38
|
|
|
34
39
|
|
|
35
40
|
def format_presence_topic(endpoint: str, channel: str) -> str:
|
|
@@ -41,4 +46,4 @@ def format_message_topic(endpoint: str, channel: str) -> str:
|
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
def format_system_topic(event: str) -> str:
|
|
44
|
-
return f"pondsocket:system:{event}"
|
|
49
|
+
return f"pondsocket:v1:default:system:{event}"
|
|
@@ -38,10 +38,10 @@ def test_match_topic_minimal_wildcard_pattern_matches_prefix() -> None:
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
def test_format_helpers() -> None:
|
|
41
|
-
assert format_topic("api", "room", "message") == "pondsocket:api:room
|
|
42
|
-
assert format_presence_topic("api", "room") == "pondsocket:api:room
|
|
43
|
-
assert format_message_topic("api", "room") == "pondsocket:api:room
|
|
44
|
-
assert format_system_topic("ping") == "pondsocket:system:ping"
|
|
41
|
+
assert format_topic("api", "room", "message") == "pondsocket:v1:default:api:room"
|
|
42
|
+
assert format_presence_topic("api", "room") == "pondsocket:v1:default:api:room"
|
|
43
|
+
assert format_message_topic("api", "room") == "pondsocket:v1:default:api:room"
|
|
44
|
+
assert format_system_topic("ping") == "pondsocket:v1:default:system:ping"
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def test_local_pubsub_satisfies_protocol() -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|