|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import logging |
5 | | -from typing import TYPE_CHECKING, Any |
| 5 | +from typing import TYPE_CHECKING |
6 | 6 |
|
7 | 7 | from ably.realtime.connection import ConnectionState |
8 | 8 | from ably.rest.channel import Channel |
9 | 9 | from ably.rest.channel import Channels as RestChannels |
10 | 10 | from ably.transport.websockettransport import ProtocolMessageAction |
| 11 | +from ably.types.channeloptions import ChannelOptions |
11 | 12 | from ably.types.channelstate import ChannelState, ChannelStateChange |
12 | 13 | from ably.types.flags import Flag, has_flag |
13 | 14 | from ably.types.message import Message, MessageAction, MessageVersion |
|
20 | 21 |
|
21 | 22 | if TYPE_CHECKING: |
22 | 23 | from ably.realtime.realtime import AblyRealtime |
23 | | - from ably.util.crypto import CipherParams |
24 | 24 |
|
25 | 25 | log = logging.getLogger(__name__) |
26 | 26 |
|
27 | 27 |
|
28 | | -class ChannelOptions: |
29 | | - """Channel options for Ably Realtime channels |
30 | | -
|
31 | | - Attributes |
32 | | - ---------- |
33 | | - cipher : CipherParams, optional |
34 | | - Requests encryption for this channel when not null, and specifies encryption-related parameters. |
35 | | - params : Dict[str, str], optional |
36 | | - Channel parameters that configure the behavior of the channel. |
37 | | - """ |
38 | | - |
39 | | - def __init__(self, cipher: CipherParams | None = None, params: dict | None = None): |
40 | | - self.__cipher = cipher |
41 | | - self.__params = params |
42 | | - # Validate params |
43 | | - if self.__params and not isinstance(self.__params, dict): |
44 | | - raise AblyException("params must be a dictionary", 40000, 400) |
45 | | - |
46 | | - @property |
47 | | - def cipher(self): |
48 | | - """Get cipher configuration""" |
49 | | - return self.__cipher |
50 | | - |
51 | | - @property |
52 | | - def params(self) -> dict[str, str]: |
53 | | - """Get channel parameters""" |
54 | | - return self.__params |
55 | | - |
56 | | - def __eq__(self, other): |
57 | | - """Check equality with another ChannelOptions instance""" |
58 | | - if not isinstance(other, ChannelOptions): |
59 | | - return False |
60 | | - |
61 | | - return (self.__cipher == other.__cipher and |
62 | | - self.__params == other.__params) |
63 | | - |
64 | | - def __hash__(self): |
65 | | - """Make ChannelOptions hashable""" |
66 | | - return hash(( |
67 | | - self.__cipher, |
68 | | - tuple(sorted(self.__params.items())) if self.__params else None, |
69 | | - )) |
70 | | - |
71 | | - def to_dict(self) -> dict[str, Any]: |
72 | | - """Convert to dictionary representation""" |
73 | | - result = {} |
74 | | - if self.__cipher is not None: |
75 | | - result['cipher'] = self.__cipher |
76 | | - if self.__params: |
77 | | - result['params'] = self.__params |
78 | | - return result |
79 | | - |
80 | | - @classmethod |
81 | | - def from_dict(cls, options_dict: dict[str, Any]) -> ChannelOptions: |
82 | | - """Create ChannelOptions from dictionary""" |
83 | | - if not isinstance(options_dict, dict): |
84 | | - raise AblyException("options must be a dictionary", 40000, 400) |
85 | | - |
86 | | - return cls( |
87 | | - cipher=options_dict.get('cipher'), |
88 | | - params=options_dict.get('params'), |
89 | | - ) |
90 | | - |
91 | | - |
92 | 28 | class RealtimeChannel(EventEmitter, Channel): |
93 | 29 | """ |
94 | 30 | Ably Realtime Channel |
@@ -139,7 +75,7 @@ def __init__(self, realtime: AblyRealtime, name: str, channel_options: ChannelOp |
139 | 75 | self.__internal_state_emitter = EventEmitter() |
140 | 76 |
|
141 | 77 | # Initialize presence for this channel |
142 | | - from ably.realtime.realtimepresence import RealtimePresence |
| 78 | + from ably.realtime.presence import RealtimePresence |
143 | 79 | self.__presence = RealtimePresence(self) |
144 | 80 |
|
145 | 81 | # Pass channel options as dictionary to parent Channel class |
|
0 commit comments