Skip to content

Commit 473edad

Browse files
authored
Merge pull request #34 from JarbasHiveMind/release-0.1.0a1
Release 0.1.0a1
2 parents 35f4f02 + cda886e commit 473edad

File tree

5 files changed

+73
-195
lines changed

5 files changed

+73
-195
lines changed

CHANGELOG.md

+3-178
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,12 @@
11
# Changelog
22

3-
## [Unreleased](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/HEAD)
3+
## [0.1.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.1.0a1) (2024-10-30)
44

5-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a29...HEAD)
5+
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.0.4...0.1.0a1)
66

77
**Merged pull requests:**
88

9-
- feat:semver [\#32](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/32) ([JarbasAl](https://github.com/JarbasAl))
10-
11-
## [V0.0.4a29](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a29) (2024-10-24)
12-
13-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a28...V0.0.4a29)
14-
15-
**Merged pull requests:**
16-
17-
- fix:missing session in handshake [\#31](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/31) ([JarbasAl](https://github.com/JarbasAl))
18-
19-
## [V0.0.4a28](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a28) (2024-10-24)
20-
21-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a27...V0.0.4a28)
22-
23-
**Merged pull requests:**
24-
25-
- fix:binary payloads [\#30](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/30) ([JarbasAl](https://github.com/JarbasAl))
26-
27-
## [V0.0.4a27](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a27) (2024-07-12)
28-
29-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a26...V0.0.4a27)
30-
31-
**Fixed bugs:**
32-
33-
- fix/event\_removal [\#29](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/29) ([JarbasAl](https://github.com/JarbasAl))
34-
35-
## [V0.0.4a26](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a26) (2024-06-12)
36-
37-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a25...V0.0.4a26)
38-
39-
**Fixed bugs:**
40-
41-
- fix/wss\_connection [\#28](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/28) ([JarbasAl](https://github.com/JarbasAl))
42-
43-
## [V0.0.4a25](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a25) (2024-06-05)
44-
45-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a24...V0.0.4a25)
46-
47-
**Implemented enhancements:**
48-
49-
- feat/INTERCOM msg type [\#27](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/27) ([JarbasAl](https://github.com/JarbasAl))
50-
51-
## [V0.0.4a24](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a24) (2024-06-04)
52-
53-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a23...V0.0.4a24)
54-
55-
## [V0.0.4a23](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a23) (2024-05-30)
56-
57-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a22...V0.0.4a23)
58-
59-
**Implemented enhancements:**
60-
61-
- feat/target\_site\_id [\#26](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/26) ([JarbasAl](https://github.com/JarbasAl))
62-
63-
## [V0.0.4a22](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a22) (2024-05-21)
64-
65-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a20...V0.0.4a22)
66-
67-
## [V0.0.4a20](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a20) (2024-05-20)
68-
69-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a21...V0.0.4a20)
70-
71-
## [V0.0.4a21](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a21) (2024-05-20)
72-
73-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a19...V0.0.4a21)
74-
75-
**Implemented enhancements:**
76-
77-
- feat/better\_kwargs [\#24](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/24) ([JarbasAl](https://github.com/JarbasAl))
78-
79-
## [V0.0.4a19](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a19) (2024-04-21)
80-
81-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a18...V0.0.4a19)
82-
83-
**Fixed bugs:**
84-
85-
- fix/clients\_manage\_their\_own\_sessions [\#23](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/23) ([JarbasAl](https://github.com/JarbasAl))
86-
87-
## [V0.0.4a18](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a18) (2024-01-16)
88-
89-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a17...V0.0.4a18)
90-
91-
**Closed issues:**
92-
93-
- SSLError\(1, '\[SSL: TLSV1\_ALERT\_PROTOCOL\_VERSION\] tlsv1 alert protocol version \(\_ssl.c:1002\)'\) [\#16](https://github.com/JarbasHiveMind/hivemind-websocket-client/issues/16)
94-
95-
## [V0.0.4a17](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a17) (2023-11-21)
96-
97-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a16...V0.0.4a17)
98-
99-
## [V0.0.4a16](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a16) (2023-10-31)
100-
101-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a15...V0.0.4a16)
102-
103-
## [V0.0.4a15](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a15) (2023-10-31)
104-
105-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a14...V0.0.4a15)
106-
107-
## [V0.0.4a14](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a14) (2023-10-26)
108-
109-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a13...V0.0.4a14)
110-
111-
## [V0.0.4a13](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a13) (2023-10-26)
112-
113-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a12...V0.0.4a13)
114-
115-
**Fixed bugs:**
116-
117-
- refactor/mycroft\_events [\#21](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/21) ([JarbasAl](https://github.com/JarbasAl))
118-
119-
## [V0.0.4a12](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a12) (2023-10-17)
120-
121-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a11...V0.0.4a12)
122-
123-
## [V0.0.4a11](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a11) (2023-09-29)
124-
125-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a10...V0.0.4a11)
126-
127-
**Fixed bugs:**
128-
129-
- explicit session [\#20](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/20) ([JarbasAl](https://github.com/JarbasAl))
130-
131-
## [V0.0.4a10](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a10) (2023-09-14)
132-
133-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a9...V0.0.4a10)
134-
135-
**Implemented enhancements:**
136-
137-
- feat/identity\_file host [\#19](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/19) ([JarbasAl](https://github.com/JarbasAl))
138-
139-
## [V0.0.4a9](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a9) (2023-09-14)
140-
141-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a8...V0.0.4a9)
142-
143-
**Implemented enhancements:**
144-
145-
- feat/identity\_file [\#18](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/18) ([JarbasAl](https://github.com/JarbasAl))
146-
147-
## [V0.0.4a8](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a8) (2023-09-12)
148-
149-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a7...V0.0.4a8)
150-
151-
**Implemented enhancements:**
152-
153-
- add site\_id [\#17](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/17) ([JarbasAl](https://github.com/JarbasAl))
154-
155-
## [V0.0.4a7](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a7) (2023-09-06)
156-
157-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a6...V0.0.4a7)
158-
159-
## [V0.0.4a6](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a6) (2023-08-03)
160-
161-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a5...V0.0.4a6)
162-
163-
## [V0.0.4a5](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a5) (2023-08-03)
164-
165-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/V0.0.4a4...V0.0.4a5)
166-
167-
## [V0.0.4a4](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/V0.0.4a4) (2023-08-03)
168-
169-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.0.1...V0.0.4a4)
170-
171-
**Implemented enhancements:**
172-
173-
- Feat/binary [\#4](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/4) ([JarbasAl](https://github.com/JarbasAl))
174-
- feat/mycroft\_drop\_in\_support [\#1](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/1) ([JarbasAl](https://github.com/JarbasAl))
175-
176-
**Closed issues:**
177-
178-
- SSL "Internal error" when spinning up the client [\#3](https://github.com/JarbasHiveMind/hivemind-websocket-client/issues/3)
179-
180-
**Merged pull requests:**
181-
182-
- ovos rebase + handshake + session support [\#15](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/15) ([JarbasAl](https://github.com/JarbasAl))
183-
- Feat/mycroft drop in support [\#5](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/5) ([JarbasAl](https://github.com/JarbasAl))
184-
- Upgrade websocket-client to 1.2.1 [\#2](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/2) ([emphasize](https://github.com/emphasize))
9+
- feat:binary handlers [\#33](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/33) ([JarbasAl](https://github.com/JarbasAl))
18510

18611

18712

hivemind_bus_client/client.py

+49-8
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,33 @@
44
from threading import Event
55
from typing import Union, Optional, Callable
66

7+
import pgpy
78
from ovos_bus_client import Message as MycroftMessage, MessageBusClient as OVOSBusClient
89
from ovos_bus_client.session import Session
9-
from ovos_utils.log import LOG
10-
from ovos_utils.messagebus import FakeBus
1110
from pyee import EventEmitter
1211
from websocket import ABNF
1312
from websocket import WebSocketApp, WebSocketConnectionClosedException
14-
import pgpy
15-
from hivemind_bus_client.serialization import HiveMindBinaryPayloadType
13+
1614
from hivemind_bus_client.identity import NodeIdentity
1715
from hivemind_bus_client.message import HiveMessage, HiveMessageType
16+
from hivemind_bus_client.serialization import HiveMindBinaryPayloadType
1817
from hivemind_bus_client.serialization import get_bitstring, decode_bitstring
1918
from hivemind_bus_client.util import serialize_message, \
2019
encrypt_as_json, decrypt_from_json, encrypt_bin, decrypt_bin
20+
from ovos_utils.log import LOG
21+
from ovos_utils.messagebus import FakeBus
22+
23+
24+
class BinaryDataCallbacks:
25+
def handle_receive_tts(self, bin_data: bytes,
26+
utterance: str,
27+
lang: str,
28+
file_name: str):
29+
LOG.warning(f"Ignoring received binary TTS audio: {utterance} with {len(bin_data)} bytes")
30+
31+
def handle_receive_file(self, bin_data: bytes,
32+
file_name: str):
33+
LOG.warning(f"Ignoring received binary file: {file_name} with {len(bin_data)} bytes")
2134

2235

2336
class HiveMessageWaiter:
@@ -87,7 +100,9 @@ def __init__(self, key: Optional[str] = None,
87100
compress: bool = True,
88101
binarize: bool = True,
89102
identity: NodeIdentity = None,
90-
internal_bus: Optional[OVOSBusClient] = None):
103+
internal_bus: Optional[OVOSBusClient] = None,
104+
bin_callbacks: BinaryDataCallbacks = BinaryDataCallbacks()):
105+
self.bin_callbacks = bin_callbacks
91106

92107
self.identity = identity or None
93108
self._password = password
@@ -268,20 +283,45 @@ def on_message(self, *args):
268283
message = decode_bitstring(message)
269284
elif isinstance(message, str):
270285
message = json.loads(message)
271-
if "ciphertext" in message:
286+
if isinstance(message, dict) and "ciphertext" in message:
272287
LOG.error("got encrypted message, but could not decrypt!")
273288
return
289+
290+
if (isinstance(message, HiveMessage) and message.msg_type == HiveMessageType.BINARY):
291+
self._handle_binary(message)
292+
return
274293
self.emitter.emit('message', message) # raw message
275294
self._handle_hive_protocol(HiveMessage(**message))
276295

296+
def _handle_binary(self, message: HiveMessage):
297+
assert message.msg_type == HiveMessageType.BINARY
298+
bin_data = message.payload
299+
LOG.debug(f"Got binary data of type: {message.bin_type}")
300+
if message.bin_type == HiveMindBinaryPayloadType.TTS_AUDIO:
301+
lang = message.metadata.get("lang")
302+
utt = message.metadata.get("utterance")
303+
file_name = message.metadata.get("file_name")
304+
try:
305+
self.bin_callbacks.handle_receive_tts(bin_data, utt, lang, file_name)
306+
except:
307+
LOG.exception("Error in binary callback: handle_receive_tts")
308+
elif message.bin_type == HiveMindBinaryPayloadType.FILE:
309+
file_name = message.metadata.get("file_name")
310+
try:
311+
self.bin_callbacks.handle_receive_file(bin_data, file_name)
312+
except:
313+
LOG.exception("Error in binary callback: handle_receive_file")
314+
else:
315+
LOG.warning(f"Ignoring received untyped binary data: {len(bin_data)} bytes")
316+
277317
def _handle_hive_protocol(self, message: HiveMessage):
278318
# LOG.debug(f"received HiveMind message: {message.msg_type}")
279319
if message.msg_type == HiveMessageType.BUS:
280320
self.internal_bus.emit(message.payload)
281321
self.emitter.emit(message.msg_type, message) # hive message
282322

283323
def emit(self, message: Union[MycroftMessage, HiveMessage],
284-
binary_type: HiveMindBinaryPayloadType=HiveMindBinaryPayloadType.UNDEFINED):
324+
binary_type: HiveMindBinaryPayloadType = HiveMindBinaryPayloadType.UNDEFINED):
285325
if isinstance(message, MycroftMessage):
286326
message = HiveMessage(msg_type=HiveMessageType.BUS,
287327
payload=message)
@@ -324,7 +364,8 @@ def emit(self, message: Union[MycroftMessage, HiveMessage],
324364
bitstr = get_bitstring(hive_type=message.msg_type,
325365
payload=message.payload,
326366
compressed=self.compress,
327-
binary_type=binary_type)
367+
binary_type=binary_type,
368+
hivemeta=message.metadata)
328369
if self.crypto_key:
329370
ws_payload = encrypt_bin(self.crypto_key, bitstr.bytes)
330371
else:

hivemind_bus_client/message.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from ovos_bus_client import Message
55
from ovos_utils.json_helper import merge_dict
6-
from typing import Union, List, Optional
6+
from typing import Union, List, Optional, Dict, Any
77

88

99
class HiveMessageType(str, Enum):
@@ -36,6 +36,9 @@ class HiveMindBinaryPayloadType(IntEnum):
3636
RAW_AUDIO = 1 # binary content is raw audio (TODO spec exactly what "raw audio" means)
3737
NUMPY_IMAGE = 2 # binary content is an image as a numpy array, eg. webcam picture
3838
FILE = 3 # binary is a file to be saved, additional metadata provided elsewhere
39+
STT_AUDIO_TRANSCRIBE = 4 # full audio sentence to perform STT and return transcripts
40+
STT_AUDIO_HANDLE = 5 # full audio sentence to perform STT and handle transcription immediately
41+
TTS_AUDIO = 6 # synthesized TTS audio to be played
3942

4043

4144
class HiveMessage:
@@ -47,7 +50,8 @@ def __init__(self, msg_type: Union[HiveMessageType, str],
4750
target_peers: Optional[List[str]]=None,
4851
target_site_id: Optional[str] =None,
4952
target_pubkey: Optional[str] =None,
50-
bin_type: HiveMindBinaryPayloadType = HiveMindBinaryPayloadType.UNDEFINED):
53+
bin_type: HiveMindBinaryPayloadType = HiveMindBinaryPayloadType.UNDEFINED,
54+
metadata: Optional[Dict[str, Any]] = None):
5155
# except for the hivemind node classes receiving the message and
5256
# creating the object nothing should be able to change these values
5357
# node classes might change them a runtime by the private attribute
@@ -59,6 +63,7 @@ def __init__(self, msg_type: Union[HiveMessageType, str],
5963

6064
self._msg_type = msg_type
6165
self._bin_type = bin_type
66+
self._meta = metadata or {}
6267

6368
# the payload is more or less a free for all
6469
# the msg_type determines what happens to the message, but the
@@ -82,6 +87,10 @@ def __init__(self, msg_type: Union[HiveMessageType, str],
8287
self._route = route or [] # where did this message come from
8388
self._targets = target_peers or [] # where will it be sent
8489

90+
@property
91+
def metadata(self) -> Dict[str, Any]:
92+
return self._meta
93+
8594
@property
8695
def target_site_id(self) -> str:
8796
return self._site_id
@@ -145,6 +154,7 @@ def as_dict(self) -> dict:
145154

146155
return {"msg_type": self.msg_type,
147156
"payload": pload,
157+
"metadata": self.metadata,
148158
"route": self.route,
149159
"node": self.node_id,
150160
"target_site_id": self.target_site_id,
@@ -166,6 +176,7 @@ def deserialize(payload: Union[str, dict]) -> 'HiveMessage':
166176
if "msg_type" in payload:
167177
try:
168178
return HiveMessage(payload["msg_type"], payload["payload"],
179+
metadata=payload.get("metadata", {}),
169180
target_site_id=payload.get("target_site_id"),
170181
target_pubkey=payload.get("target_pubkey"))
171182
except:
@@ -175,13 +186,15 @@ def deserialize(payload: Union[str, dict]) -> 'HiveMessage':
175186
try:
176187
# NOTE: technically could also be SHARED_BUS or THIRDPRTY
177188
return HiveMessage(HiveMessageType.BUS,
178-
Message.deserialize(payload),
189+
payload=Message.deserialize(payload),
190+
metadata=payload.get("metadata", {}),
179191
target_site_id=payload.get("target_site_id"),
180192
target_pubkey=payload.get("target_pubkey"))
181193
except:
182194
pass # not a mycroft message
183195

184196
return HiveMessage(HiveMessageType.THIRDPRTY, payload,
197+
metadata=payload.get("metadata", {}),
185198
target_site_id=payload.get("target_site_id"),
186199
target_pubkey=payload.get("target_pubkey"))
187200

hivemind_bus_client/serialization.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ def _decode_bitstring_v1(s):
120120
payload = bytes2str(payload.bytes, compressed)
121121
else:
122122
payload = payload.bytes
123-
meta["bin_type"] = bin_type
124123

125-
kwargs = {a: meta[a] for a in signature(HiveMessage).parameters if a in meta}
126-
return HiveMessage(hive_type, payload, **kwargs)
124+
return HiveMessage(hive_type, payload,
125+
metadata=meta, bin_type=bin_type)
127126

128127

129128
def mycroft2bitstring(msg, compressed=False):

0 commit comments

Comments
 (0)