Skip to content

Instantly share code, notes, and snippets.

@B-Ricey763
Last active September 22, 2022 00:35
Show Gist options
  • Select an option

  • Save B-Ricey763/dc625917644797acbf41eaa00504cb0b to your computer and use it in GitHub Desktop.

Select an option

Save B-Ricey763/dc625917644797acbf41eaa00504cb0b to your computer and use it in GitHub Desktop.
Bridge Extension rough draft. My setup is a folder called Bridge with these three files as descendants.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Comm = require(ReplicatedStorage.Packages.Comm)
local Client = {}
function Client.Starting(component)
local inboundMiddleware = component.Middleware and component.Middleware.Inbound
local outboundMiddleware = component.Middleware and component.Middleware.Outbound
component.Server = Comm.ClientComm.new(component.Instance, true, component.Tag):BuildObject(
inboundMiddleware,
outboundMiddleware
)
end
function Client.Stopped(component)
if component.Server then
component.Server:Destroy()
end
end
return Client
local RunService = game:GetService("RunService")
local IS_SERVER = RunService:IsServer()
local Client = require(script.Client)
local Server = require(script.Server)
return if IS_SERVER then Server else Client
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TableUtil = require(ReplicatedStorage.Packages.TableUtil)
local Comm = require(ReplicatedStorage.Packages.Comm)
local Server = {}
function Server.Starting(component)
if not component.Client then
return
end
local outboundMiddleware = component.Middleware and component.Middleware.Outbound
local inboundMiddleware = component.Middleware and component.Middleware.Inbound
component.Client = TableUtil.Copy(component.Client)
component._comm = Comm.ServerComm.new(component.Instance, component.Tag)
for k, v in pairs(component.Client) do
if type(v) == "function" then
component._comm:WrapMethod(component.Client, k, inboundMiddleware, outboundMiddleware)
elseif tostring(v) == "SIGNAL_MARKER" then -- Allow Knit.CreateSignal()
component.Client[k] = component._comm:CreateSignal(k, inboundMiddleware, outboundMiddleware)
elseif type(v) == "table" and tostring(v[1]) == "PROPERTY_MARKER" then -- Same thing as Knit
component.Client[k] = component._comm:CreateProperty(k, v[2], inboundMiddleware, outboundMiddleware)
end
end
component.Client.Server = component
end
function Server.Stopped(component)
if component._comm then
component._comm:Destroy()
end
end
return Server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment