Skip to content

Commit d3ecd82

Browse files
committed
2 parents 51266bb + 38bdc4a commit d3ecd82

File tree

10 files changed

+189
-13
lines changed

10 files changed

+189
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This project uses [semantic versioning](https://semver.org/spec/v2.0.0.html).
1111
### Improvements
1212
- Type improvements
1313

14-
## [version 0.5.3](incomplete): 7/31/2023
14+
## [version 0.5.3](https://github.com/ffrostflame/BridgeNet2/releases/tag/v0.5.3): 7/31/2023
1515

1616
### Added
1717
- A mock API for when BridgeNet2 is ran in edit mode. Limitations: InvokeServerAsync will infinitely yield, connections will never run.

docs/Tutorials/Using Identifiers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ local anotherThing = BridgeNet2.ReferenceIdentifier("anotherThing")
3232

3333
sendSomeData:Fire({
3434
[firstThingToSend] = 5,
35-
[anotherThingToSend] = false,
35+
[anotherThing] = false,
3636
})
3737
```
38-
At the cost of 2 lines of code, we completely solved the problem! Our code is now both readable and efficient.
38+
At the cost of 2 lines of code, we completely solved the problem! Our code is now both readable and efficient.

sourcemap.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"name":"bridgenet2-test","className":"DataModel","filePaths":["testing.project.json"],"children":[{"name":"ReplicatedStorage","className":"ReplicatedStorage","children":[{"name":"Packages","className":"Folder","children":[{"name":"RemotePacketSizeCounter","className":"ModuleScript","filePaths":["Packages\\RemotePacketSizeCounter.lua"]},{"name":"TableKit","className":"ModuleScript","filePaths":["Packages\\TableKit.lua"]},{"name":"_Index","className":"Folder","children":[{"name":"[email protected]","className":"Folder","children":[{"name":"tablekit","className":"ModuleScript","filePaths":["Packages\\_Index\\[email protected]\\tablekit\\src\\init.luau","Packages\\_Index\\[email protected]\\tablekit\\default.project.json"]}]},{"name":"[email protected]","className":"Folder","children":[{"name":"remotepacketsizecounter","className":"ModuleScript","filePaths":["Packages\\_Index\\[email protected]\\remotepacketsizecounter\\src\\init.luau","Packages\\_Index\\[email protected]\\remotepacketsizecounter\\default.project.json"]}]}]},{"name":"bridgenet2","className":"ModuleScript","filePaths":["src\\init.luau"],"children":[{"name":"Client","className":"ModuleScript","filePaths":["src\\Client\\init.luau"],"children":[{"name":"ClientBridge","className":"ModuleScript","filePaths":["src\\Client\\ClientBridge.luau"]},{"name":"ClientConnection","className":"ModuleScript","filePaths":["src\\Client\\ClientConnection.luau"]},{"name":"ClientIdentifiers","className":"ModuleScript","filePaths":["src\\Client\\ClientIdentifiers.luau"]},{"name":"ClientProcess","className":"ModuleScript","filePaths":["src\\Client\\ClientProcess.luau"]}]},{"name":"Constants","className":"ModuleScript","filePaths":["src\\Constants.luau"]},{"name":"PublicTypes","className":"ModuleScript","filePaths":["src\\PublicTypes.luau"]},{"name":"Server","className":"ModuleScript","filePaths":["src\\Server\\init.luau"],"children":[{"name":"HandleInvalidPlayer","className":"ModuleScript","filePaths":["src\\Server\\HandleInvalidPlayer.luau"]},{"name":"PlayerContainers","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\init.luau"],"children":[{"name":"All","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\All.luau"]},{"name":"Except","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Except.luau"]},{"name":"Players","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Players.luau"]},{"name":"Single","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Single.luau"]}]},{"name":"ServerBridge","className":"ModuleScript","filePaths":["src\\Server\\ServerBridge.luau"]},{"name":"ServerConnection","className":"ModuleScript","filePaths":["src\\Server\\ServerConnection.luau"]},{"name":"ServerIdentifiers","className":"ModuleScript","filePaths":["src\\Server\\ServerIdentifiers.luau"]},{"name":"ServerProcess","className":"ModuleScript","filePaths":["src\\Server\\ServerProcess.luau"]}]},{"name":"Studio","className":"Folder","children":[{"name":"MockBridge","className":"ModuleScript","filePaths":["src\\Studio\\MockBridge.luau"]},{"name":"MockConnection","className":"ModuleScript","filePaths":["src\\Studio\\MockConnection.luau"]},{"name":"MockIdentifiers","className":"ModuleScript","filePaths":["src\\Studio\\MockIdentifiers.luau"]}]},{"name":"Types","className":"ModuleScript","filePaths":["src\\Types.luau"]},{"name":"Utilities","className":"Folder","children":[{"name":"NetworkUtils","className":"ModuleScript","filePaths":["src\\Utilities\\NetworkUtils.luau"]},{"name":"Output","className":"ModuleScript","filePaths":["src\\Utilities\\Output.luau"]},{"name":"RecycledSpawn","className":"ModuleScript","filePaths":["src\\Utilities\\RecycledSpawn.luau"]},{"name":"isEditMode","className":"ModuleScript","filePaths":["src\\Utilities\\isEditMode.luau"]},{"name":"tostringData","className":"ModuleScript","filePaths":["src\\Utilities\\tostringData.luau"]}]},{"name":"version","className":"ModuleScript","filePaths":["src\\version.luau"]}]}]},{"name":"benches","className":"Folder","children":[{"name":"Hex.bench","className":"ModuleScript","filePaths":["benchmarks\\Hex.bench.luau"]}]},{"name":"framework","className":"ModuleScript","filePaths":["testing/framework\\init.luau"],"children":[{"name":"bootstrapper","className":"ModuleScript","filePaths":["testing/framework\\bootstrapper.luau"]},{"name":"expect","className":"ModuleScript","filePaths":["testing/framework\\expect.luau"]}]}]},{"name":"ServerScriptService","className":"ServerScriptService","children":[{"name":"featureTests","className":"Script","filePaths":["testing/tests/server\\featureTests\\init.server.luau"]}]},{"name":"StarterPlayer","className":"StarterPlayer","children":[{"name":"StarterPlayerScripts","className":"StarterPlayerScripts","children":[{"name":"featureTests","className":"LocalScript","filePaths":["testing/tests/client\\featureTests\\init.client.luau"]}]}]}]}
1+
{"name":"bridgenet2-test","className":"DataModel","filePaths":["testing.project.json"],"children":[{"name":"ReplicatedStorage","className":"ReplicatedStorage","children":[{"name":"Packages","className":"Folder","children":[{"name":"RemotePacketSizeCounter","className":"ModuleScript","filePaths":["Packages\\RemotePacketSizeCounter.lua"]},{"name":"TableKit","className":"ModuleScript","filePaths":["Packages\\TableKit.lua"]},{"name":"_Index","className":"Folder","children":[{"name":"[email protected]","className":"Folder","children":[{"name":"tablekit","className":"ModuleScript","filePaths":["Packages\\_Index\\[email protected]\\tablekit\\src\\init.luau","Packages\\_Index\\[email protected]\\tablekit\\default.project.json"]}]},{"name":"[email protected]","className":"Folder","children":[{"name":"remotepacketsizecounter","className":"ModuleScript","filePaths":["Packages\\_Index\\[email protected]\\remotepacketsizecounter\\src\\init.luau","Packages\\_Index\\[email protected]\\remotepacketsizecounter\\default.project.json"]}]}]},{"name":"bridgenet2","className":"ModuleScript","filePaths":["src\\init.luau"],"children":[{"name":"Client","className":"ModuleScript","filePaths":["src\\Client\\init.luau"],"children":[{"name":"ClientBridge","className":"ModuleScript","filePaths":["src\\Client\\ClientBridge.luau"]},{"name":"ClientConnection","className":"ModuleScript","filePaths":["src\\Client\\ClientConnection.luau"]},{"name":"ClientIdentifiers","className":"Folder"},{"name":"ClientIdentifiers","className":"ModuleScript","filePaths":["src\\Client\\ClientIdentifiers.luau"]},{"name":"ClientProcess","className":"ModuleScript","filePaths":["src\\Client\\ClientProcess.luau"]}]},{"name":"Constants","className":"ModuleScript","filePaths":["src\\Constants.luau"]},{"name":"PublicTypes","className":"ModuleScript","filePaths":["src\\PublicTypes.luau"]},{"name":"Server","className":"ModuleScript","filePaths":["src\\Server\\init.luau"],"children":[{"name":"HandleInvalidPlayer","className":"ModuleScript","filePaths":["src\\Server\\HandleInvalidPlayer.luau"]},{"name":"PlayerContainers","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\init.luau"],"children":[{"name":"All","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\All.luau"]},{"name":"Except","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Except.luau"]},{"name":"Players","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Players.luau"]},{"name":"Single","className":"ModuleScript","filePaths":["src\\Server\\PlayerContainers\\Single.luau"]}]},{"name":"ServerBridge","className":"ModuleScript","filePaths":["src\\Server\\ServerBridge.luau"]},{"name":"ServerConnection","className":"ModuleScript","filePaths":["src\\Server\\ServerConnection.luau"]},{"name":"ServerIdentifiers","className":"ModuleScript","filePaths":["src\\Server\\ServerIdentifiers.luau"]},{"name":"ServerProcess","className":"ModuleScript","filePaths":["src\\Server\\ServerProcess.luau"]}]},{"name":"Studio","className":"Folder","children":[{"name":"MockBridge","className":"ModuleScript","filePaths":["src\\Studio\\MockBridge.luau"]},{"name":"MockConnection","className":"ModuleScript","filePaths":["src\\Studio\\MockConnection.luau"]},{"name":"MockIdentifiers","className":"ModuleScript","filePaths":["src\\Studio\\MockIdentifiers.luau"]}]},{"name":"Types","className":"ModuleScript","filePaths":["src\\Types.luau"]},{"name":"Utilities","className":"Folder","children":[{"name":"NetworkUtils","className":"ModuleScript","filePaths":["src\\Utilities\\NetworkUtils.luau"]},{"name":"Output","className":"ModuleScript","filePaths":["src\\Utilities\\Output.luau"]},{"name":"RecycledSpawn","className":"ModuleScript","filePaths":["src\\Utilities\\RecycledSpawn.luau"]},{"name":"isEditMode","className":"ModuleScript","filePaths":["src\\Utilities\\isEditMode.luau"]},{"name":"tostringData","className":"ModuleScript","filePaths":["src\\Utilities\\tostringData.luau"]}]},{"name":"version","className":"ModuleScript","filePaths":["src\\version.luau"]}]}]},{"name":"benches","className":"Folder","children":[{"name":"Hex.bench","className":"ModuleScript","filePaths":["benchmarks\\Hex.bench.luau"]}]},{"name":"framework","className":"ModuleScript","filePaths":["testing/framework\\init.luau"],"children":[{"name":"bootstrapper","className":"ModuleScript","filePaths":["testing/framework\\bootstrapper.luau"]},{"name":"expect","className":"ModuleScript","filePaths":["testing/framework\\expect.luau"]}]}]},{"name":"ServerScriptService","className":"ServerScriptService","children":[{"name":"featureTests","className":"Script","filePaths":["testing/tests/server\\featureTests\\init.server.luau"]}]},{"name":"StarterPlayer","className":"StarterPlayer","children":[{"name":"StarterPlayerScripts","className":"StarterPlayerScripts","children":[{"name":"featureTests","className":"LocalScript","filePaths":["testing/tests/client\\featureTests\\init.client.luau"]}]}]}]}

src/Client/ClientBridge.luau

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ local RemotePacketSizeCounter = require(script.Parent.Parent.Parent.RemotePacket
99
local Types = require(script.Parent.Parent.Types)
1010
local tostringData = require(script.Parent.Parent.Utilities.tostringData)
1111

12+
--[=[
13+
This class handles the client-sided interface of BridgeNet2.
14+
15+
@class clientBridgePrototype
16+
]=]
1217
local clientBridgePrototype = {}
1318

1419
local CLASS_METATABLE = { __index = clientBridgePrototype }
@@ -17,14 +22,31 @@ function CLASS_METATABLE:__tostring()
1722
return "ClientBridge"
1823
end
1924

25+
--[=[
26+
Sets the rate limit, cannot be used client-sided.
27+
28+
@ignore
29+
@return string
30+
]=]
2031
function clientBridgePrototype:RateLimit()
2132
Output.warn("cannot call :RateLimit() from client")
2233
end
2334

35+
--[=[
36+
Disables the rate limit, cannot be used client-sided.
37+
38+
@ignore
39+
@return string
40+
]=]
2441
function clientBridgePrototype:DisableRateLimit()
2542
Output.warn("cannot call :DisableRateLimit() from client")
2643
end
2744

45+
--[=[
46+
Sets some middleware to run when a bridge is fired from the server.
47+
48+
@param middlewareTable {(object: any) -> any}
49+
]=]
2850
function clientBridgePrototype:InboundMiddleware(middlewareTable: { (object: any) -> any })
2951
Output.fatalAssert(tostring(self) == "ClientBridge", "InboundMiddleware called with . instead of :")
3052
Output.fatalAssert(
@@ -36,6 +58,11 @@ function clientBridgePrototype:InboundMiddleware(middlewareTable: { (object: any
3658
self._inboundMiddleware = middlewareTable
3759
end
3860

61+
--[=[
62+
Sets some middleware to run when a bridge is fired from the local client.
63+
64+
@param middlewareTable {(object: any) -> any}
65+
]=]
3966
function clientBridgePrototype:OutboundMiddleware(middlewareTable: { (object: any) -> any })
4067
Output.fatalAssert(tostring(self) == "ClientBridge", "OutboundMiddleware called with . instead of :")
4168
Output.fatalAssert(
@@ -47,6 +74,11 @@ function clientBridgePrototype:OutboundMiddleware(middlewareTable: { (object: an
4774
self._outboundMiddleware = middlewareTable
4875
end
4976

77+
--[=[
78+
Fires the bridge locally, which can then be recieved from the server along with packet data sent along.
79+
80+
@param content any
81+
]=]
5082
function clientBridgePrototype:Fire(content: any)
5183
Output.fatalAssert(tostring(self) == "ClientBridge", "Fire called with . instead of :")
5284

@@ -96,7 +128,13 @@ function clientBridgePrototype:Fire(content: any)
96128
end
97129
end
98130

99-
function clientBridgePrototype:Connect(callback: (content: Types.Content) -> (), name: string?): RBXScriptConnection
131+
--[=[
132+
Connects the bridge to any events recieved from the server, this is when inbound middleware is ran. This shares identical behavior with [RemoteEvent.OnServerEvent:Connect].
133+
134+
@param callback (content: Types.Content) -> ()
135+
@return RBXScriptConnection
136+
]=]
137+
function clientBridgePrototype:Connect(callback: (content: Types.Content) -> (), name: string?)
100138
Output.fatalAssert(tostring(self) == "ClientBridge", "connect called with . instead of :")
101139
Output.typecheck("function", "Connect", "callback", callback)
102140

@@ -175,6 +213,12 @@ function clientBridgePrototype:Connect(callback: (content: Types.Content) -> (),
175213
end)
176214
end
177215

216+
--[=[
217+
Connects the bridge to any events recieved from the server, this is when inbound middleware is ran. This shares identical behavior with [RemoteEvent.OnServerEvent:Wait].
218+
219+
@yields
220+
@return any
221+
]=]
178222
function clientBridgePrototype:Wait()
179223
Output.fatalAssert(tostring(self) == "ClientBridge", "Wait called with . instead of :")
180224
-- Again, very basic QoL implementation of :Wait()
@@ -185,6 +229,14 @@ function clientBridgePrototype:Wait()
185229
return coroutine.yield()
186230
end
187231

232+
--[=[
233+
Invokes the server, then returns a value afterwards. This function yields the thread until content is recieved.
234+
235+
@yields
236+
237+
@param content any
238+
@return any
239+
]=]
188240
function clientBridgePrototype:InvokeServerAsync(content: any)
189241
Output.fatalAssert(tostring(self) == "ClientBridge", "InvokeServerAsync called with . instead of :")
190242
self:Fire({ ClientIdentifiers.ref("REQUEST", 3, false), content })
@@ -202,6 +254,12 @@ function clientBridgePrototype:InvokeServerAsync(content: any)
202254
return coroutine.yield()
203255
end
204256

257+
--[=[
258+
Connects the bridge to any events recieved from the server, this is when inbound middleware is ran. This shares identical behavior with [clientBridgePrototype:Connect] with the difference being that the event instantly disconnects on recieved.
259+
260+
@param func (content: Types.Content) -> ()
261+
@return RBXScriptConnection
262+
]=]
205263
function clientBridgePrototype:Once(func: (content: Types.Content) -> ())
206264
Output.fatalAssert(tostring(self) == "ClientBridge", "Once called with . instead of :")
207265
-- Instantly disconnects. Very basic QoL implementation
@@ -214,6 +272,9 @@ function clientBridgePrototype:Once(func: (content: Types.Content) -> ())
214272
return connection
215273
end
216274

275+
--[=[
276+
Destroys the bridge it was called on.
277+
]=]
217278
function clientBridgePrototype:Destroy()
218279
Output.fatalAssert(tostring(self) == "ClientBridge", "Destroy called with . instead of :")
219280
-- Don't actually do any logic here- remember that ClientBridges are really just listening objects that let the end user communicate.

src/Client/ClientConnection.luau

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ return function(identifier, callback)
2828

2929
self._disconnectCallback = ClientProcess.connect(identifier, callback)
3030

31-
return (self :: unknown) :: RBXScriptConnection
31+
return self :: unknown
3232
end

0 commit comments

Comments
 (0)