@rbxts/tether 1.0.0 → 1.0.2
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.
- package/README.md +44 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,2 +1,45 @@
|
|
|
1
1
|
# Tether
|
|
2
|
-
A message-based networking solution for Roblox with automatic binary serialization
|
|
2
|
+
A message-based networking solution for Roblox with automatic binary serialization
|
|
3
|
+
|
|
4
|
+
### In `shared/messaging.ts`
|
|
5
|
+
```ts
|
|
6
|
+
import { DataType } from "@rbxts/flamework-binary-serializer";
|
|
7
|
+
|
|
8
|
+
export const messageEmitter = new MessageEmitter<Message, MessageData>;
|
|
9
|
+
messageEmitter.initialize();
|
|
10
|
+
|
|
11
|
+
export const enum Message {
|
|
12
|
+
TEST
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface MessageData {
|
|
16
|
+
[Message.TEST]: {
|
|
17
|
+
readonly foo: string;
|
|
18
|
+
readonly n: DataType.u8;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
messageEmitter.addSerializer<Message.TOGGLE_MOVEMENT>(Message.TOGGLE_MOVEMENT);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
> [!CAUTION]
|
|
26
|
+
> Every single message kind must implement an interface for it's data (in the example that would be the object with the `foo` and `bar` fields) as well as call `MessageEmitter.addSerializer()`. Messages will not work if you don't do this.
|
|
27
|
+
|
|
28
|
+
### Server
|
|
29
|
+
```ts
|
|
30
|
+
import { Message, messageEmitter } from "shared/messaging";
|
|
31
|
+
|
|
32
|
+
messageEmitter.onServerMessage(Message.TEST, (player, data) => {
|
|
33
|
+
print(player, "sent data:", data);
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Client
|
|
38
|
+
```ts
|
|
39
|
+
import { Message, messageEmitter } from "shared/messaging";
|
|
40
|
+
|
|
41
|
+
messageEmitter.emitServer(Message.TEST, {
|
|
42
|
+
foo: "bar",
|
|
43
|
+
n: 69
|
|
44
|
+
});
|
|
45
|
+
```
|