@rbxts/tether 1.0.1 → 1.0.3
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 +4 -1
- package/out/index.d.ts +11 -8
- package/out/init.luau +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,12 @@ export interface MessageData {
|
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
messageEmitter.addSerializer<Message.
|
|
22
|
+
messageEmitter.addSerializer<Message.TEST>(Message.TEST);
|
|
23
23
|
```
|
|
24
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
|
+
|
|
25
28
|
### Server
|
|
26
29
|
```ts
|
|
27
30
|
import { Message, messageEmitter } from "shared/messaging";
|
package/out/index.d.ts
CHANGED
|
@@ -2,8 +2,11 @@ import { Modding } from "@flamework/core";
|
|
|
2
2
|
import { type SerializerMetadata } from "@rbxts/flamework-binary-serializer";
|
|
3
3
|
type ClientMessageCallback<T = unknown> = (data: T) => void;
|
|
4
4
|
type ServerMessageCallback<T = unknown> = (player: Player, data: T) => void;
|
|
5
|
-
|
|
6
|
-
export declare
|
|
5
|
+
/** @metadata macro */
|
|
6
|
+
export declare function createMessageEmitter<MessageData>(metaForEachMessage?: Modding.Many<{
|
|
7
|
+
[Kind in keyof MessageData]: Modding.Many<SerializerMetadata<MessageData[Kind]>>;
|
|
8
|
+
}>): MessageEmitter<MessageData> | undefined;
|
|
9
|
+
declare class MessageEmitter<MessageData> {
|
|
7
10
|
private readonly clientCallbacks;
|
|
8
11
|
private readonly serverCallbacks;
|
|
9
12
|
private readonly serializers;
|
|
@@ -11,13 +14,13 @@ export declare class MessageEmitter<Message extends BaseMessage, MessageData ext
|
|
|
11
14
|
private readonly clientEvents;
|
|
12
15
|
constructor();
|
|
13
16
|
/** @metadata macro */
|
|
14
|
-
addSerializer<Kind extends
|
|
17
|
+
addSerializer<Kind extends keyof MessageData>(message: Kind, meta?: Modding.Many<SerializerMetadata<MessageData[Kind]>>): void;
|
|
15
18
|
initialize(): RBXScriptConnection;
|
|
16
|
-
onServerMessage<Kind extends
|
|
17
|
-
onClientMessage<Kind extends
|
|
18
|
-
emitServer<Kind extends
|
|
19
|
-
emitClient<Kind extends
|
|
20
|
-
emitAllClients<Kind extends
|
|
19
|
+
onServerMessage<Kind extends keyof MessageData>(message: Kind, callback: ServerMessageCallback<MessageData[Kind]>): () => void;
|
|
20
|
+
onClientMessage<Kind extends keyof MessageData>(message: Kind, callback: ClientMessageCallback<MessageData[Kind]>): () => void;
|
|
21
|
+
emitServer<Kind extends keyof MessageData>(message: Kind, data: MessageData[Kind], unreliable?: boolean): void;
|
|
22
|
+
emitClient<Kind extends keyof MessageData>(player: Player, message: Kind, data: MessageData[Kind], unreliable?: boolean): void;
|
|
23
|
+
emitAllClients<Kind extends keyof MessageData>(message: Kind, data: MessageData[Kind], unreliable?: boolean): void;
|
|
21
24
|
private getPacket;
|
|
22
25
|
/** @metadata macro */
|
|
23
26
|
private createMessageSerializer;
|
package/out/init.luau
CHANGED
|
@@ -4,7 +4,17 @@ local Networking = TS.import(script, TS.getModule(script, "@flamework", "network
|
|
|
4
4
|
local createBinarySerializer = TS.import(script, TS.getModule(script, "@rbxts", "flamework-binary-serializer").out).createBinarySerializer
|
|
5
5
|
local RunService = TS.import(script, TS.getModule(script, "@rbxts", "services")).RunService
|
|
6
6
|
local GlobalEvents = Networking.createEvent()
|
|
7
|
+
--* @metadata macro
|
|
7
8
|
local MessageEmitter
|
|
9
|
+
local function createMessageEmitter(metaForEachMessage)
|
|
10
|
+
if metaForEachMessage == nil then
|
|
11
|
+
return nil
|
|
12
|
+
end
|
|
13
|
+
local emitter = MessageEmitter.new()
|
|
14
|
+
for kind, meta in pairs(metaForEachMessage) do
|
|
15
|
+
emitter:addSerializer(kind, meta)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
8
18
|
do
|
|
9
19
|
MessageEmitter = setmetatable({}, {
|
|
10
20
|
__tostring = function()
|
|
@@ -152,5 +162,5 @@ do
|
|
|
152
162
|
end
|
|
153
163
|
end
|
|
154
164
|
return {
|
|
155
|
-
|
|
165
|
+
createMessageEmitter = createMessageEmitter,
|
|
156
166
|
}
|