@quenty/remoting 12.18.0 → 12.18.1
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/CHANGELOG.md +11 -0
- package/package.json +11 -11
- package/src/Shared/GetRemoteEvent.lua +30 -17
- package/src/Shared/GetRemoteFunction.lua +30 -17
- package/src/Shared/Interface/Remoting.lua +238 -133
- package/src/Shared/Interface/RemotingMember.lua +13 -8
- package/src/Shared/Realm/RemotingRealmUtils.lua +3 -2
- package/src/Shared/Realm/RemotingRealms.lua +11 -3
- package/src/Shared/ResourceConstants.lua +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [12.18.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/remoting@12.18.0...@quenty/remoting@12.18.1) (2025-04-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Add types to packages ([2374fb2](https://github.com/Quenty/NevermoreEngine/commit/2374fb2b043cfbe0e9b507b3316eec46a4e353a0))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [12.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/remoting@12.17.2...@quenty/remoting@12.18.0) (2025-04-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @quenty/remoting
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/remoting",
|
|
3
|
-
"version": "12.18.
|
|
3
|
+
"version": "12.18.1",
|
|
4
4
|
"description": "Global remoting retrieval system for Roblox (RemoteFunctions/RemoteEvents)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
"Quenty"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@quenty/brio": "^14.17.
|
|
30
|
-
"@quenty/instanceutils": "^13.17.
|
|
31
|
-
"@quenty/loader": "^10.8.
|
|
32
|
-
"@quenty/maid": "^3.4.
|
|
33
|
-
"@quenty/promise": "^10.10.
|
|
34
|
-
"@quenty/promisemaid": "^5.10.
|
|
35
|
-
"@quenty/remotefunctionutils": "^10.10.
|
|
36
|
-
"@quenty/rx": "^13.17.
|
|
37
|
-
"@quenty/table": "^3.7.
|
|
29
|
+
"@quenty/brio": "^14.17.1",
|
|
30
|
+
"@quenty/instanceutils": "^13.17.1",
|
|
31
|
+
"@quenty/loader": "^10.8.1",
|
|
32
|
+
"@quenty/maid": "^3.4.1",
|
|
33
|
+
"@quenty/promise": "^10.10.2",
|
|
34
|
+
"@quenty/promisemaid": "^5.10.2",
|
|
35
|
+
"@quenty/remotefunctionutils": "^10.10.2",
|
|
36
|
+
"@quenty/rx": "^13.17.1",
|
|
37
|
+
"@quenty/table": "^3.7.2"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "78c3ac0ab08dd18085b6e6e6e4f745e76ed99f68"
|
|
43
43
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Provides getting named global [RemoteEvent] resources.
|
|
3
4
|
@class GetRemoteEvent
|
|
@@ -45,7 +46,7 @@ local RunService = game:GetService("RunService")
|
|
|
45
46
|
local ResourceConstants = require("ResourceConstants")
|
|
46
47
|
|
|
47
48
|
if not RunService:IsRunning() then
|
|
48
|
-
return function(name)
|
|
49
|
+
return function(name: string): RemoteEvent
|
|
49
50
|
local event = Instance.new("RemoteEvent")
|
|
50
51
|
event.Archivable = false
|
|
51
52
|
event.Name = "Mock" .. name
|
|
@@ -53,33 +54,45 @@ if not RunService:IsRunning() then
|
|
|
53
54
|
return event
|
|
54
55
|
end
|
|
55
56
|
elseif RunService:IsServer() then
|
|
56
|
-
|
|
57
|
-
assert(type(name) == "string", "Bad name")
|
|
58
|
-
|
|
57
|
+
local function getOrCreateStorage(): Instance
|
|
59
58
|
local storage = ReplicatedStorage:FindFirstChild(ResourceConstants.REMOTE_EVENT_STORAGE_NAME)
|
|
60
|
-
if
|
|
61
|
-
storage
|
|
62
|
-
storage.Name = ResourceConstants.REMOTE_EVENT_STORAGE_NAME
|
|
63
|
-
storage.Archivable = false
|
|
64
|
-
storage.Parent = ReplicatedStorage
|
|
59
|
+
if storage then
|
|
60
|
+
return storage
|
|
65
61
|
end
|
|
66
62
|
|
|
63
|
+
local created = Instance.new("Folder")
|
|
64
|
+
created.Name = ResourceConstants.REMOTE_EVENT_STORAGE_NAME
|
|
65
|
+
created.Archivable = false
|
|
66
|
+
created.Parent = ReplicatedStorage
|
|
67
|
+
return created
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return function(name: string): RemoteEvent
|
|
71
|
+
assert(type(name) == "string", "Bad name")
|
|
72
|
+
|
|
73
|
+
local storage = getOrCreateStorage()
|
|
74
|
+
|
|
67
75
|
local event = storage:FindFirstChild(name)
|
|
68
|
-
if event then
|
|
76
|
+
if event and event:IsA("RemoteEvent") then
|
|
69
77
|
return event
|
|
70
78
|
end
|
|
71
79
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
80
|
+
local created = Instance.new("RemoteEvent")
|
|
81
|
+
created.Name = name
|
|
82
|
+
created.Archivable = false
|
|
83
|
+
created.Parent = storage
|
|
76
84
|
|
|
77
|
-
return
|
|
85
|
+
return created
|
|
78
86
|
end
|
|
79
87
|
else -- RunService:IsClient()
|
|
80
|
-
return function(name)
|
|
88
|
+
return function(name: string): RemoteEvent
|
|
81
89
|
assert(type(name) == "string", "Bad name")
|
|
82
90
|
|
|
83
|
-
|
|
91
|
+
local found = ReplicatedStorage:WaitForChild(ResourceConstants.REMOTE_EVENT_STORAGE_NAME):WaitForChild(name)
|
|
92
|
+
if found and found:IsA("RemoteEvent") then
|
|
93
|
+
return found
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
error("Could not find remote event " .. name)
|
|
84
97
|
end
|
|
85
98
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Provides getting named global [RemoteFunction] resources.
|
|
3
4
|
|
|
@@ -48,7 +49,7 @@ local RunService = game:GetService("RunService")
|
|
|
48
49
|
local ResourceConstants = require("ResourceConstants")
|
|
49
50
|
|
|
50
51
|
if not RunService:IsRunning() then
|
|
51
|
-
return function(name)
|
|
52
|
+
return function(name: string): RemoteFunction
|
|
52
53
|
local func = Instance.new("RemoteFunction")
|
|
53
54
|
func.Name = "Mock" .. name
|
|
54
55
|
func.Archivable = false
|
|
@@ -56,33 +57,45 @@ if not RunService:IsRunning() then
|
|
|
56
57
|
return func
|
|
57
58
|
end
|
|
58
59
|
elseif RunService:IsServer() then
|
|
59
|
-
|
|
60
|
-
assert(type(name) == "string", "Bad name")
|
|
61
|
-
|
|
60
|
+
local function getOrCreateStorage(): Instance
|
|
62
61
|
local storage = ReplicatedStorage:FindFirstChild(ResourceConstants.REMOTE_FUNCTION_STORAGE_NAME)
|
|
63
|
-
if
|
|
64
|
-
storage
|
|
65
|
-
storage.Name = ResourceConstants.REMOTE_FUNCTION_STORAGE_NAME
|
|
66
|
-
storage.Archivable = false
|
|
67
|
-
storage.Parent = ReplicatedStorage
|
|
62
|
+
if storage then
|
|
63
|
+
return storage
|
|
68
64
|
end
|
|
69
65
|
|
|
66
|
+
local created = Instance.new("Folder")
|
|
67
|
+
created.Name = ResourceConstants.REMOTE_FUNCTION_STORAGE_NAME
|
|
68
|
+
created.Archivable = false
|
|
69
|
+
created.Parent = ReplicatedStorage
|
|
70
|
+
|
|
71
|
+
return created
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
return function(name: string): RemoteFunction
|
|
75
|
+
assert(type(name) == "string", "Bad name")
|
|
76
|
+
|
|
77
|
+
local storage = getOrCreateStorage()
|
|
70
78
|
local func = storage:FindFirstChild(name)
|
|
71
|
-
if func then
|
|
79
|
+
if func and func:IsA("RemoteFunction") then
|
|
72
80
|
return func
|
|
73
81
|
end
|
|
74
82
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
local created = Instance.new("RemoteFunction")
|
|
84
|
+
created.Name = name
|
|
85
|
+
created.Archivable = false
|
|
86
|
+
created.Parent = storage
|
|
79
87
|
|
|
80
|
-
return
|
|
88
|
+
return created
|
|
81
89
|
end
|
|
82
90
|
else -- RunService:IsClient()
|
|
83
|
-
return function(name)
|
|
91
|
+
return function(name: string): RemoteFunction
|
|
84
92
|
assert(type(name) == "string", "Bad name")
|
|
85
93
|
|
|
86
|
-
|
|
94
|
+
local found = ReplicatedStorage:WaitForChild(ResourceConstants.REMOTE_FUNCTION_STORAGE_NAME):WaitForChild(name)
|
|
95
|
+
if found and found:IsA("RemoteFunction") then
|
|
96
|
+
return found
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
error("Could not find remote function " .. name)
|
|
87
100
|
end
|
|
88
101
|
end
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Offers a thin wrapper around Roblox remoting instances and events. Designed to reduce
|
|
3
4
|
the amount of code needed to construct a large set of RemoteFunction/RemoteEvent instances.
|
|
@@ -20,14 +21,16 @@ local RemotingRealms = require("RemotingRealms")
|
|
|
20
21
|
local RemotingRealmUtils = require("RemotingRealmUtils")
|
|
21
22
|
local RxBrioUtils = require("RxBrioUtils")
|
|
22
23
|
local RxInstanceUtils = require("RxInstanceUtils")
|
|
24
|
+
local _Observable = require("Observable")
|
|
25
|
+
local _Brio = require("Brio")
|
|
23
26
|
|
|
24
27
|
local RAW_MEMBERS = {
|
|
25
|
-
_name = true
|
|
26
|
-
_maid = true
|
|
27
|
-
_instance = true
|
|
28
|
-
_remoteObjects = true
|
|
29
|
-
_container = true
|
|
30
|
-
_defaultRemotingRealm = true
|
|
28
|
+
_name = true,
|
|
29
|
+
_maid = true,
|
|
30
|
+
_instance = true,
|
|
31
|
+
_remoteObjects = true,
|
|
32
|
+
_container = true,
|
|
33
|
+
_defaultRemotingRealm = true,
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
local REMOTE_EVENT_SUFFIX = "Event"
|
|
@@ -40,17 +43,77 @@ Remoting.__index = Remoting
|
|
|
40
43
|
Remoting.Realms = RemotingRealms
|
|
41
44
|
|
|
42
45
|
Remoting.Server = {
|
|
43
|
-
new = function(instance, name)
|
|
46
|
+
new = function(instance: Instance, name: string)
|
|
44
47
|
return Remoting.new(instance, name, RemotingRealms.SERVER)
|
|
45
|
-
end
|
|
48
|
+
end,
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
Remoting.Client = {
|
|
49
|
-
new = function(instance, name)
|
|
52
|
+
new = function(instance: Instance, name: string)
|
|
50
53
|
return Remoting.new(instance, name, RemotingRealms.CLIENT)
|
|
51
|
-
end
|
|
54
|
+
end,
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
export type Remoting = typeof(setmetatable(
|
|
58
|
+
{} :: {
|
|
59
|
+
_maid: Maid.Maid,
|
|
60
|
+
_instance: Instance,
|
|
61
|
+
_name: string,
|
|
62
|
+
_remoteObjects: { [string]: RemoteEvent | BindableEvent | RemoteFunction },
|
|
63
|
+
_container: Folder?,
|
|
64
|
+
_remotingRealm: RemotingRealms.RemotingRealm,
|
|
65
|
+
_useDummyObject: boolean,
|
|
66
|
+
_remoteFolderName: string,
|
|
67
|
+
|
|
68
|
+
-- Public methods
|
|
69
|
+
DeclareEvent: (self: Remoting, memberName: string) -> (),
|
|
70
|
+
DeclareMethod: (self: Remoting, memberName: string) -> (),
|
|
71
|
+
Connect: (self: Remoting, memberName: string, callback: (...any) -> ()) -> Maid.Maid,
|
|
72
|
+
Bind: (self: Remoting, memberName: string, callback: (...any) -> ()) -> Maid.Maid,
|
|
73
|
+
FireClient: (self: Remoting, memberName: string, player: Player, ...any) -> (),
|
|
74
|
+
FireAllClients: (self: Remoting, memberName: string, ...any) -> (),
|
|
75
|
+
FireAllClientsExcept: (self: Remoting, memberName: string, excludePlayer: Player, ...any) -> (),
|
|
76
|
+
FireServer: (self: Remoting, memberName: string, ...any) -> (),
|
|
77
|
+
PromiseFireServer: (self: Remoting, memberName: string, ...any) -> Promise.Promise<()>,
|
|
78
|
+
PromiseInvokeServer: (self: Remoting, memberName: string, ...any) -> Promise.Promise<...any>,
|
|
79
|
+
GetContainerClass: (self: Remoting) -> string,
|
|
80
|
+
|
|
81
|
+
-- Private methods
|
|
82
|
+
_getDummyMemberName: (self: Remoting, memberName: string, suffix: string) -> string,
|
|
83
|
+
_getMemberName: (self: Remoting, memberName: string, objectType: string) -> string,
|
|
84
|
+
_getDebugMemberName: (self: Remoting, memberName: string) -> string,
|
|
85
|
+
_ensureContainer: (self: Remoting) -> Folder,
|
|
86
|
+
_observeFolderBrio: (self: Remoting) -> _Observable.Observable<_Brio.Brio<Folder>>,
|
|
87
|
+
_observeRemoteEventBrio: (
|
|
88
|
+
self: Remoting,
|
|
89
|
+
memberName: string
|
|
90
|
+
) -> _Observable.Observable<_Brio.Brio<RemoteEvent>>,
|
|
91
|
+
_observeRemoteFunctionBrio: (
|
|
92
|
+
self: Remoting,
|
|
93
|
+
memberName: string
|
|
94
|
+
) -> _Observable.Observable<_Brio.Brio<RemoteFunction>>,
|
|
95
|
+
_promiseContainer: (self: Remoting, maid: Maid.Maid) -> Promise.Promise<Folder>,
|
|
96
|
+
_promiseRemoteEvent: (self: Remoting, maid: Maid.Maid, memberName: string) -> Promise.Promise<RemoteEvent>,
|
|
97
|
+
_getOrCreateRemoteEvent: (self: Remoting, memberName: string) -> RemoteEvent | BindableEvent,
|
|
98
|
+
_getOrCreateRemoteFunction: (self: Remoting, memberName: string) -> RemoteFunction | BindableFunction,
|
|
99
|
+
_promiseRemoteFunction: (
|
|
100
|
+
self: Remoting,
|
|
101
|
+
maid: Maid.Maid,
|
|
102
|
+
memberName: string
|
|
103
|
+
) -> Promise.Promise<RemoteFunction>,
|
|
104
|
+
_translateCallback: (
|
|
105
|
+
self: Remoting,
|
|
106
|
+
maid: Maid.Maid,
|
|
107
|
+
memberName: string,
|
|
108
|
+
callback: (...any) -> ...any
|
|
109
|
+
) -> (...any) -> ...any,
|
|
110
|
+
|
|
111
|
+
-- Public remoting member export
|
|
112
|
+
[string]: RemotingMember.RemotingMember,
|
|
113
|
+
},
|
|
114
|
+
Remoting
|
|
115
|
+
))
|
|
116
|
+
|
|
54
117
|
--[=[
|
|
55
118
|
Creates a new remoting instance
|
|
56
119
|
|
|
@@ -59,7 +122,7 @@ Remoting.Client = {
|
|
|
59
122
|
@param remotingRealm RemotingRealm?
|
|
60
123
|
@return Remoting
|
|
61
124
|
]=]
|
|
62
|
-
function Remoting.new(instance, name, remotingRealm)
|
|
125
|
+
function Remoting.new(instance: Instance, name: string, remotingRealm: RemotingRealms.RemotingRealm?): Remoting
|
|
63
126
|
assert(typeof(instance) == "Instance", "Bad instance")
|
|
64
127
|
assert(type(name) == "string", "Bad name")
|
|
65
128
|
assert(RemotingRealmUtils.isRemotingRealm(remotingRealm) or remotingRealm == nil, "Bad remotingRealm")
|
|
@@ -76,14 +139,14 @@ function Remoting.new(instance, name, remotingRealm)
|
|
|
76
139
|
self._remoteFolderName = string.format("%sRemotes", self._name)
|
|
77
140
|
self._remoteObjects = {}
|
|
78
141
|
|
|
79
|
-
return self
|
|
142
|
+
return self :: any
|
|
80
143
|
end
|
|
81
144
|
|
|
82
|
-
|
|
145
|
+
(Remoting :: any).__index = function(self, index)
|
|
83
146
|
if Remoting[index] then
|
|
84
147
|
return Remoting[index]
|
|
85
148
|
elseif RAW_MEMBERS[index] then
|
|
86
|
-
return rawget(self, index)
|
|
149
|
+
return rawget(self :: any, index)
|
|
87
150
|
else
|
|
88
151
|
return RemotingMember.new(self, index, self._remotingRealm)
|
|
89
152
|
end
|
|
@@ -93,10 +156,10 @@ end
|
|
|
93
156
|
Connects to a given remote event.
|
|
94
157
|
|
|
95
158
|
@param memberName string
|
|
96
|
-
@param callback
|
|
159
|
+
@param callback (...) -> ()
|
|
97
160
|
@return MaidTask
|
|
98
161
|
]=]
|
|
99
|
-
function Remoting
|
|
162
|
+
function Remoting.Connect(self: Remoting, memberName: string, callback: (...any) -> ())
|
|
100
163
|
assert(type(memberName) == "string", "Bad memberName")
|
|
101
164
|
assert(type(callback) == "function", "Bad callback")
|
|
102
165
|
|
|
@@ -107,30 +170,39 @@ function Remoting:Connect(memberName, callback)
|
|
|
107
170
|
self:DeclareEvent(memberName)
|
|
108
171
|
|
|
109
172
|
self:_getOrCreateRemoteEvent(self:_getDummyMemberName(memberName, "OnClientEvent"))
|
|
110
|
-
local bindableEvent =
|
|
173
|
+
local bindableEvent: BindableEvent =
|
|
174
|
+
self:_getOrCreateRemoteEvent(self:_getDummyMemberName(memberName, "OnServerEvent")) :: any
|
|
111
175
|
connectMaid:GiveTask(bindableEvent.Event:Connect(callback))
|
|
112
176
|
else
|
|
113
|
-
local remoteEvent = self:_getOrCreateRemoteEvent(memberName)
|
|
177
|
+
local remoteEvent: RemoteEvent = self:_getOrCreateRemoteEvent(memberName) :: any
|
|
114
178
|
connectMaid:GiveTask(remoteEvent.OnServerEvent:Connect(callback))
|
|
115
179
|
end
|
|
116
180
|
|
|
117
181
|
-- TODO: Cleanup if nothing else is expecting this
|
|
118
182
|
elseif self._remotingRealm == RemotingRealms.CLIENT then
|
|
119
183
|
connectMaid._warning = task.delay(5, function()
|
|
120
|
-
warn(
|
|
184
|
+
warn(
|
|
185
|
+
string.format(
|
|
186
|
+
"[Remoting] - Failed to find RemoteEvent %q, event may never connect",
|
|
187
|
+
self:_getDebugMemberName(memberName)
|
|
188
|
+
)
|
|
189
|
+
)
|
|
121
190
|
end)
|
|
122
191
|
|
|
123
192
|
if self._useDummyObject then
|
|
124
|
-
connectMaid:GiveTask(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
193
|
+
connectMaid:GiveTask(
|
|
194
|
+
self:_observeRemoteEventBrio(self:_getDummyMemberName(memberName, "OnClientEvent"))
|
|
195
|
+
:Subscribe(function(brio)
|
|
196
|
+
if brio:IsDead() then
|
|
197
|
+
return
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
connectMaid._warning = nil
|
|
201
|
+
|
|
202
|
+
local maid, bindableEvent: any = brio:ToMaidAndValue()
|
|
203
|
+
maid:GiveTask((bindableEvent :: BindableEvent).Event:Connect(callback))
|
|
204
|
+
end)
|
|
205
|
+
)
|
|
134
206
|
else
|
|
135
207
|
connectMaid:GiveTask(self:_observeRemoteEventBrio(memberName):Subscribe(function(brio)
|
|
136
208
|
if brio:IsDead() then
|
|
@@ -147,9 +219,9 @@ function Remoting:Connect(memberName, callback)
|
|
|
147
219
|
error("[Remoting.Connect] - Unknown RunService state")
|
|
148
220
|
end
|
|
149
221
|
|
|
150
|
-
self._maid[connectMaid] = connectMaid
|
|
222
|
+
self._maid[connectMaid :: any] = connectMaid
|
|
151
223
|
connectMaid:GiveTask(function()
|
|
152
|
-
self._maid[connectMaid] = nil
|
|
224
|
+
self._maid[connectMaid :: any] = nil
|
|
153
225
|
end)
|
|
154
226
|
|
|
155
227
|
return connectMaid
|
|
@@ -162,42 +234,50 @@ end
|
|
|
162
234
|
@param memberName string
|
|
163
235
|
@param callback any
|
|
164
236
|
]=]
|
|
165
|
-
function Remoting
|
|
237
|
+
function Remoting.Bind(self: Remoting, memberName: string, callback: (...any) -> ...any)
|
|
166
238
|
assert(type(memberName) == "string", "Bad memberName")
|
|
167
239
|
assert(type(callback) == "function", "Bad callback")
|
|
168
240
|
|
|
169
|
-
local bindMaid = Maid.new()
|
|
241
|
+
local bindMaid: Maid.Maid = Maid.new()
|
|
170
242
|
|
|
171
243
|
if self._remotingRealm == RemotingRealms.SERVER then
|
|
172
244
|
if self._useDummyObject then
|
|
173
245
|
self:DeclareMethod(memberName)
|
|
174
246
|
|
|
175
|
-
local bindableFunction =
|
|
247
|
+
local bindableFunction: BindableFunction =
|
|
248
|
+
self:_getOrCreateRemoteFunction(self:_getDummyMemberName(memberName, "OnServerInvoke")) :: any
|
|
176
249
|
bindableFunction.OnInvoke = self:_translateCallback(bindMaid, memberName, callback)
|
|
177
250
|
else
|
|
178
|
-
local remoteFunction = self:_getOrCreateRemoteFunction(memberName)
|
|
251
|
+
local remoteFunction: RemoteFunction = self:_getOrCreateRemoteFunction(memberName) :: any
|
|
179
252
|
remoteFunction.OnServerInvoke = self:_translateCallback(bindMaid, memberName, callback)
|
|
180
253
|
end
|
|
181
254
|
|
|
182
255
|
-- TODO: Cleanup if nothing else is expecting this
|
|
183
256
|
elseif self._remotingRealm == RemotingRealms.CLIENT then
|
|
184
257
|
bindMaid._warning = task.delay(5, function()
|
|
185
|
-
warn(
|
|
258
|
+
warn(
|
|
259
|
+
string.format(
|
|
260
|
+
"[Remoting] - Failed to find RemoteEvent %q, event may never fire",
|
|
261
|
+
self:_getDebugMemberName(memberName)
|
|
262
|
+
)
|
|
263
|
+
)
|
|
186
264
|
end)
|
|
187
265
|
|
|
188
266
|
if self._useDummyObject then
|
|
189
|
-
bindMaid:GiveTask(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
267
|
+
bindMaid:GiveTask(
|
|
268
|
+
self:_observeRemoteFunctionBrio(self:_getDummyMemberName(memberName, "OnClientInvoke"))
|
|
269
|
+
:Subscribe(function(brio)
|
|
270
|
+
if brio:IsDead() then
|
|
271
|
+
return
|
|
272
|
+
end
|
|
193
273
|
|
|
194
|
-
|
|
274
|
+
bindMaid._warning = nil
|
|
195
275
|
|
|
196
|
-
local maid, remoteFunction = brio:ToMaidAndValue()
|
|
276
|
+
local maid, remoteFunction: any = brio:ToMaidAndValue()
|
|
197
277
|
remoteFunction.OnInvoke = self:_translateCallback(maid, memberName, callback)
|
|
198
|
-
|
|
278
|
+
end)
|
|
279
|
+
)
|
|
199
280
|
else
|
|
200
|
-
|
|
201
281
|
bindMaid:GiveTask(self:_observeRemoteFunctionBrio(memberName):Subscribe(function(brio)
|
|
202
282
|
if brio:IsDead() then
|
|
203
283
|
return
|
|
@@ -215,9 +295,9 @@ function Remoting:Bind(memberName, callback)
|
|
|
215
295
|
error("[Remoting.Bind] - Unknown RunService state")
|
|
216
296
|
end
|
|
217
297
|
|
|
218
|
-
self._maid[bindMaid] = bindMaid
|
|
298
|
+
self._maid[bindMaid :: any] = bindMaid
|
|
219
299
|
bindMaid:GiveTask(function()
|
|
220
|
-
self._maid[bindMaid] = nil
|
|
300
|
+
self._maid[bindMaid :: any] = nil
|
|
221
301
|
end)
|
|
222
302
|
|
|
223
303
|
return bindMaid
|
|
@@ -228,7 +308,7 @@ end
|
|
|
228
308
|
|
|
229
309
|
@param memberName string
|
|
230
310
|
]=]
|
|
231
|
-
function Remoting
|
|
311
|
+
function Remoting.DeclareEvent(self: Remoting, memberName: string)
|
|
232
312
|
assert(type(memberName) == "string", "Bad memberName")
|
|
233
313
|
|
|
234
314
|
if self._remotingRealm == RemotingRealms.SERVER then
|
|
@@ -246,7 +326,7 @@ end
|
|
|
246
326
|
|
|
247
327
|
@param memberName string
|
|
248
328
|
]=]
|
|
249
|
-
function Remoting
|
|
329
|
+
function Remoting.DeclareMethod(self: Remoting, memberName: string)
|
|
250
330
|
assert(type(memberName) == "string", "Bad memberName")
|
|
251
331
|
|
|
252
332
|
if self._remotingRealm == RemotingRealms.SERVER then
|
|
@@ -259,7 +339,7 @@ function Remoting:DeclareMethod(memberName)
|
|
|
259
339
|
end
|
|
260
340
|
end
|
|
261
341
|
|
|
262
|
-
function Remoting
|
|
342
|
+
function Remoting._translateCallback(self: Remoting, maid: Maid.Maid, memberName: string, callback: (...any) -> ...any)
|
|
263
343
|
local alive = true
|
|
264
344
|
maid:GiveTask(function()
|
|
265
345
|
alive = false
|
|
@@ -267,14 +347,19 @@ function Remoting:_translateCallback(maid, memberName, callback)
|
|
|
267
347
|
|
|
268
348
|
return function(...)
|
|
269
349
|
if not alive then
|
|
270
|
-
error(
|
|
350
|
+
error(
|
|
351
|
+
string.format(
|
|
352
|
+
"[Remoting] - Function for %s is disconnected and can't be called",
|
|
353
|
+
self:_getDebugMemberName(memberName)
|
|
354
|
+
)
|
|
355
|
+
)
|
|
271
356
|
return
|
|
272
357
|
end
|
|
273
358
|
|
|
274
359
|
local results = table.pack(callback(...))
|
|
275
360
|
|
|
276
361
|
local hasPromise = false
|
|
277
|
-
for i=1, results.n do
|
|
362
|
+
for i = 1, results.n do
|
|
278
363
|
if Promise.isPromise(results[i]) then
|
|
279
364
|
hasPromise = true
|
|
280
365
|
break
|
|
@@ -287,7 +372,7 @@ function Remoting:_translateCallback(maid, memberName, callback)
|
|
|
287
372
|
promise = results[1]
|
|
288
373
|
else
|
|
289
374
|
local data = {}
|
|
290
|
-
for i=1, results.n do
|
|
375
|
+
for i = 1, results.n do
|
|
291
376
|
table.insert(data, results[i])
|
|
292
377
|
end
|
|
293
378
|
|
|
@@ -319,18 +404,18 @@ end
|
|
|
319
404
|
@param player Player
|
|
320
405
|
@param ... any
|
|
321
406
|
]=]
|
|
322
|
-
function Remoting
|
|
407
|
+
function Remoting.FireClient(self: Remoting, memberName: string, player: Player, ...)
|
|
323
408
|
assert(type(memberName) == "string", "Bad memberName")
|
|
324
409
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
325
410
|
assert(self._remotingRealm == RemotingRealms.SERVER, "FireClient must be called on server")
|
|
326
411
|
|
|
327
412
|
if self._useDummyObject then
|
|
328
|
-
local bindableEvent = self:_getOrCreateRemoteEvent(memberName)
|
|
413
|
+
local bindableEvent: BindableEvent = self:_getOrCreateRemoteEvent(memberName) :: any
|
|
329
414
|
bindableEvent:Fire(...)
|
|
330
415
|
return
|
|
331
416
|
end
|
|
332
417
|
|
|
333
|
-
local remoteEvent = self:_getOrCreateRemoteEvent(memberName)
|
|
418
|
+
local remoteEvent: RemoteEvent = self:_getOrCreateRemoteEvent(memberName) :: any
|
|
334
419
|
remoteEvent:FireClient(player, ...)
|
|
335
420
|
end
|
|
336
421
|
|
|
@@ -344,18 +429,19 @@ end
|
|
|
344
429
|
@param player Player
|
|
345
430
|
@param ... any
|
|
346
431
|
]=]
|
|
347
|
-
function Remoting
|
|
432
|
+
function Remoting.InvokeClient(self: Remoting, memberName: string, player: Player, ...)
|
|
348
433
|
assert(type(memberName) == "string", "Bad memberName")
|
|
349
434
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
350
435
|
assert(self._remotingRealm == RemotingRealms.SERVER, "InvokeClient must be called on server")
|
|
351
436
|
|
|
352
437
|
if self._useDummyObject then
|
|
353
|
-
local bindableFunction =
|
|
438
|
+
local bindableFunction: BindableFunction =
|
|
439
|
+
self:_getOrCreateRemoteFunction(self:_getDummyMemberName(memberName, "OnClientInvoke")) :: any
|
|
354
440
|
bindableFunction:Invoke(...)
|
|
355
441
|
return
|
|
356
442
|
end
|
|
357
443
|
|
|
358
|
-
local remoteFunction = self:_getOrCreateRemoteFunction(memberName)
|
|
444
|
+
local remoteFunction: RemoteFunction = self:_getOrCreateRemoteFunction(memberName) :: any
|
|
359
445
|
remoteFunction:InvokeClient(player, ...)
|
|
360
446
|
end
|
|
361
447
|
|
|
@@ -368,17 +454,18 @@ end
|
|
|
368
454
|
@param memberName string
|
|
369
455
|
@param ... any
|
|
370
456
|
]=]
|
|
371
|
-
function Remoting
|
|
457
|
+
function Remoting.FireAllClients(self: Remoting, memberName: string, ...)
|
|
372
458
|
assert(type(memberName) == "string", "Bad memberName")
|
|
373
459
|
assert(self._remotingRealm == RemotingRealms.SERVER, "FireAllClients must be called on server")
|
|
374
460
|
|
|
375
461
|
if self._useDummyObject then
|
|
376
|
-
local bindableEvent =
|
|
462
|
+
local bindableEvent: BindableEvent =
|
|
463
|
+
self:_getOrCreateRemoteEvent(self:_getDummyMemberName(memberName, "OnClientEvent")) :: any
|
|
377
464
|
bindableEvent:Fire(...)
|
|
378
465
|
return
|
|
379
466
|
end
|
|
380
467
|
|
|
381
|
-
local remoteEvent = self:_getOrCreateRemoteEvent(memberName)
|
|
468
|
+
local remoteEvent: RemoteEvent = self:_getOrCreateRemoteEvent(memberName) :: any
|
|
382
469
|
remoteEvent:FireAllClients(...)
|
|
383
470
|
end
|
|
384
471
|
|
|
@@ -391,19 +478,23 @@ end
|
|
|
391
478
|
@param excludePlayer Player | nil
|
|
392
479
|
@param ... any
|
|
393
480
|
]=]
|
|
394
|
-
function Remoting
|
|
481
|
+
function Remoting.FireAllClientsExcept(self: Remoting, memberName: string, excludePlayer: Player, ...)
|
|
395
482
|
assert(type(memberName) == "string", "Bad memberName")
|
|
396
|
-
assert(
|
|
483
|
+
assert(
|
|
484
|
+
typeof(excludePlayer) == "Instance" and excludePlayer:IsA("Player") or excludePlayer == nil,
|
|
485
|
+
"Bad excludePlayer"
|
|
486
|
+
)
|
|
397
487
|
assert(self._remotingRealm == RemotingRealms.SERVER, "FireAllClientsExcept must be called on server")
|
|
398
488
|
|
|
399
489
|
if self._useDummyObject then
|
|
400
|
-
local bindableEvent =
|
|
490
|
+
local bindableEvent: BindableEvent =
|
|
491
|
+
self:_getOrCreateRemoteEvent(self:_getDummyMemberName(memberName, "OnClientEvent")) :: any
|
|
401
492
|
bindableEvent:Fire(...)
|
|
402
493
|
return
|
|
403
494
|
end
|
|
404
495
|
|
|
405
|
-
local remoteEvent = self:_getOrCreateRemoteEvent(memberName)
|
|
406
|
-
for _, player in
|
|
496
|
+
local remoteEvent: RemoteEvent = self:_getOrCreateRemoteEvent(memberName) :: any
|
|
497
|
+
for _, player in Players:GetPlayers() do
|
|
407
498
|
if player ~= excludePlayer then
|
|
408
499
|
remoteEvent:FireClient(player, ...)
|
|
409
500
|
end
|
|
@@ -417,7 +508,7 @@ end
|
|
|
417
508
|
@param memberName string
|
|
418
509
|
@param ... any
|
|
419
510
|
]=]
|
|
420
|
-
function Remoting
|
|
511
|
+
function Remoting.FireServer(self: Remoting, memberName: string, ...)
|
|
421
512
|
assert(type(memberName) == "string", "Bad memberName")
|
|
422
513
|
assert(self._remotingRealm == RemotingRealms.CLIENT, "FireServer must be called on client")
|
|
423
514
|
|
|
@@ -432,7 +523,7 @@ end
|
|
|
432
523
|
@param ... any
|
|
433
524
|
@return Promise
|
|
434
525
|
]=]
|
|
435
|
-
function Remoting
|
|
526
|
+
function Remoting.PromiseFireServer(self: Remoting, memberName: string, ...)
|
|
436
527
|
assert(type(memberName) == "string", "Bad memberName")
|
|
437
528
|
assert(self._remotingRealm == RemotingRealms.CLIENT, "PromiseFireServer must be called on client")
|
|
438
529
|
|
|
@@ -446,18 +537,17 @@ function Remoting:PromiseFireServer(memberName, ...)
|
|
|
446
537
|
bindableEvent:Fire(Players.LocalPlayer, table.unpack(args, 1, args.n))
|
|
447
538
|
end)
|
|
448
539
|
else
|
|
449
|
-
promise = self:_promiseRemoteEvent(fireMaid, memberName)
|
|
450
|
-
:
|
|
451
|
-
|
|
452
|
-
end)
|
|
540
|
+
promise = self:_promiseRemoteEvent(fireMaid, memberName):Then(function(remoteEvent)
|
|
541
|
+
remoteEvent:FireServer(table.unpack(args, 1, args.n))
|
|
542
|
+
end)
|
|
453
543
|
end
|
|
454
544
|
|
|
455
545
|
promise:Finally(function()
|
|
456
|
-
self._maid[fireMaid] = nil
|
|
546
|
+
self._maid[fireMaid :: any] = nil
|
|
457
547
|
end)
|
|
458
|
-
self._maid[fireMaid] = fireMaid
|
|
548
|
+
self._maid[fireMaid :: any] = fireMaid
|
|
459
549
|
fireMaid:GiveTask(function()
|
|
460
|
-
self._maid[fireMaid] = nil
|
|
550
|
+
self._maid[fireMaid :: any] = nil
|
|
461
551
|
end)
|
|
462
552
|
|
|
463
553
|
-- TODO: Warn if remote event doesn't exist
|
|
@@ -473,7 +563,7 @@ end
|
|
|
473
563
|
@param ... any
|
|
474
564
|
@return any
|
|
475
565
|
]=]
|
|
476
|
-
function Remoting
|
|
566
|
+
function Remoting.InvokeServer(self: Remoting, memberName: string, ...): ...any
|
|
477
567
|
assert(type(memberName) == "string", "Bad memberName")
|
|
478
568
|
|
|
479
569
|
return self:PromiseInvokeServer(memberName, ...):Wait()
|
|
@@ -485,9 +575,9 @@ end
|
|
|
485
575
|
@client
|
|
486
576
|
@param memberName string
|
|
487
577
|
@param ... any
|
|
488
|
-
@return Promise
|
|
578
|
+
@return Promise<...any>
|
|
489
579
|
]=]
|
|
490
|
-
function Remoting
|
|
580
|
+
function Remoting.PromiseInvokeServer(self: Remoting, memberName: string, ...): Promise.Promise<...any>
|
|
491
581
|
assert(type(memberName) == "string", "Bad memberName")
|
|
492
582
|
|
|
493
583
|
local invokeMaid = Maid.new()
|
|
@@ -497,21 +587,28 @@ function Remoting:PromiseInvokeServer(memberName, ...)
|
|
|
497
587
|
if self._useDummyObject then
|
|
498
588
|
promise = self:_promiseRemoteFunction(invokeMaid, self:_getDummyMemberName(memberName, "OnServerInvoke"))
|
|
499
589
|
:Then(function(remoteFunction)
|
|
500
|
-
return invokeMaid:GivePromise(
|
|
590
|
+
return invokeMaid:GivePromise(
|
|
591
|
+
RemoteFunctionUtils.promiseInvokeBindableFunction(
|
|
592
|
+
remoteFunction,
|
|
593
|
+
Players.LocalPlayer,
|
|
594
|
+
table.unpack(args, 1, args.n)
|
|
595
|
+
)
|
|
596
|
+
)
|
|
501
597
|
end)
|
|
502
598
|
else
|
|
503
|
-
promise = self:_promiseRemoteFunction(invokeMaid, memberName)
|
|
504
|
-
:
|
|
505
|
-
|
|
506
|
-
|
|
599
|
+
promise = self:_promiseRemoteFunction(invokeMaid, memberName):Then(function(remoteFunction)
|
|
600
|
+
return invokeMaid:GivePromise(
|
|
601
|
+
RemoteFunctionUtils.promiseInvokeServer(remoteFunction, table.unpack(args, 1, args.n))
|
|
602
|
+
)
|
|
603
|
+
end)
|
|
507
604
|
end
|
|
508
605
|
|
|
509
606
|
promise:Finally(function()
|
|
510
|
-
self._maid[invokeMaid] = nil
|
|
607
|
+
self._maid[invokeMaid :: any] = nil
|
|
511
608
|
end)
|
|
512
|
-
self._maid[invokeMaid] = invokeMaid
|
|
609
|
+
self._maid[invokeMaid :: any] = invokeMaid
|
|
513
610
|
invokeMaid:GiveTask(function()
|
|
514
|
-
self._maid[invokeMaid] = nil
|
|
611
|
+
self._maid[invokeMaid :: any] = nil
|
|
515
612
|
end)
|
|
516
613
|
|
|
517
614
|
-- TODO: Warn if remote function doesn't exist
|
|
@@ -528,55 +625,57 @@ end
|
|
|
528
625
|
@param ... any
|
|
529
626
|
@return Promise<any>
|
|
530
627
|
]=]
|
|
531
|
-
function Remoting
|
|
628
|
+
function Remoting.PromiseInvokeClient(self: Remoting, memberName: string, player: Player, ...)
|
|
532
629
|
assert(type(memberName) == "string", "Bad memberName")
|
|
533
630
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
534
631
|
|
|
535
|
-
local invokeMaid = Maid.new()
|
|
632
|
+
local invokeMaid: Maid.Maid = Maid.new()
|
|
536
633
|
|
|
537
634
|
local promise
|
|
538
635
|
if self._useDummyObject then
|
|
539
|
-
local bindableFunction =
|
|
636
|
+
local bindableFunction: BindableFunction =
|
|
637
|
+
self:_getOrCreateRemoteFunction(self:_getDummyMemberName(memberName, "OnClientInvoke")) :: any
|
|
540
638
|
promise = invokeMaid:GivePromise(RemoteFunctionUtils.promiseInvokeBindableFunction(bindableFunction, ...))
|
|
541
639
|
else
|
|
542
|
-
local remoteFunction = self:_getOrCreateRemoteFunction(memberName)
|
|
640
|
+
local remoteFunction: RemoteFunction = self:_getOrCreateRemoteFunction(memberName) :: any
|
|
543
641
|
promise = invokeMaid:GivePromise(RemoteFunctionUtils.promiseInvokeClient(remoteFunction, player, ...))
|
|
544
642
|
end
|
|
545
643
|
|
|
546
644
|
promise:Finally(function()
|
|
547
|
-
self._maid[invokeMaid] = nil
|
|
645
|
+
self._maid[invokeMaid :: any] = nil
|
|
548
646
|
end)
|
|
549
647
|
|
|
550
|
-
self._maid[invokeMaid] = invokeMaid
|
|
648
|
+
self._maid[invokeMaid :: any] = invokeMaid
|
|
551
649
|
invokeMaid:GiveTask(function()
|
|
552
|
-
self._maid[invokeMaid] = nil
|
|
650
|
+
self._maid[invokeMaid :: any] = nil
|
|
553
651
|
end)
|
|
554
652
|
|
|
555
653
|
return promise
|
|
556
654
|
end
|
|
557
655
|
|
|
558
|
-
function Remoting
|
|
656
|
+
function Remoting.GetContainerClass(_self: Remoting): string
|
|
559
657
|
return "Configuration"
|
|
560
658
|
end
|
|
561
659
|
|
|
562
|
-
function Remoting
|
|
660
|
+
function Remoting._ensureContainer(self: Remoting): Folder
|
|
563
661
|
assert(self._remotingRealm == RemotingRealms.SERVER, "Folder should only be created on server")
|
|
564
662
|
|
|
565
663
|
if self._container then
|
|
566
664
|
return self._container
|
|
567
665
|
end
|
|
568
666
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
667
|
+
local created: Folder = self._maid:Add(Instance.new(self:GetContainerClass())) :: any
|
|
668
|
+
created.Name = self._remoteFolderName
|
|
669
|
+
created.Archivable = false
|
|
670
|
+
created.Parent = self._instance
|
|
573
671
|
|
|
574
|
-
self._maid:GiveTask(
|
|
672
|
+
self._maid:GiveTask(created)
|
|
673
|
+
self._container = created
|
|
575
674
|
|
|
576
|
-
return
|
|
675
|
+
return created
|
|
577
676
|
end
|
|
578
677
|
|
|
579
|
-
function Remoting
|
|
678
|
+
function Remoting._observeRemoteFunctionBrio(self: Remoting, memberName: string)
|
|
580
679
|
assert(type(memberName) == "string", "Bad memberName")
|
|
581
680
|
|
|
582
681
|
local remoteFunctionName = self:_getMemberName(memberName, REMOTE_FUNCTION_SUFFIX)
|
|
@@ -588,11 +687,11 @@ function Remoting:_observeRemoteFunctionBrio(memberName)
|
|
|
588
687
|
else
|
|
589
688
|
return RxInstanceUtils.observeLastNamedChildBrio(item, "RemoteFunction", remoteFunctionName)
|
|
590
689
|
end
|
|
591
|
-
end)
|
|
690
|
+
end),
|
|
592
691
|
})
|
|
593
692
|
end
|
|
594
693
|
|
|
595
|
-
function Remoting
|
|
694
|
+
function Remoting._observeRemoteEventBrio(self: Remoting, memberName: string)
|
|
596
695
|
assert(type(memberName) == "string", "Bad memberName")
|
|
597
696
|
|
|
598
697
|
local remoteFunctionName = self:_getMemberName(memberName, REMOTE_EVENT_SUFFIX)
|
|
@@ -604,48 +703,54 @@ function Remoting:_observeRemoteEventBrio(memberName)
|
|
|
604
703
|
else
|
|
605
704
|
return RxInstanceUtils.observeLastNamedChildBrio(item, "RemoteEvent", remoteFunctionName)
|
|
606
705
|
end
|
|
607
|
-
end)
|
|
706
|
+
end),
|
|
608
707
|
})
|
|
609
708
|
end
|
|
610
709
|
|
|
611
|
-
function Remoting
|
|
710
|
+
function Remoting._promiseContainer(self: Remoting, maid: Maid.Maid): Promise.Promise<Folder>
|
|
612
711
|
return maid:GivePromise(promiseChild(self._instance, self._remoteFolderName, 5))
|
|
613
712
|
end
|
|
614
713
|
|
|
615
|
-
function Remoting
|
|
714
|
+
function Remoting._promiseRemoteEvent(self: Remoting, maid: Maid.Maid, memberName: string): Promise.Promise<RemoteEvent>
|
|
616
715
|
local remoteEventName = self:_getMemberName(memberName, REMOTE_EVENT_SUFFIX)
|
|
617
|
-
return self:_promiseContainer(maid)
|
|
618
|
-
:
|
|
619
|
-
|
|
620
|
-
end)
|
|
716
|
+
return self:_promiseContainer(maid):Then(function(container)
|
|
717
|
+
return maid:GivePromise(promiseChild(container, remoteEventName, 5))
|
|
718
|
+
end)
|
|
621
719
|
end
|
|
622
720
|
|
|
623
|
-
function Remoting
|
|
721
|
+
function Remoting._promiseRemoteFunction(
|
|
722
|
+
self: Remoting,
|
|
723
|
+
maid: Maid.Maid,
|
|
724
|
+
memberName: string
|
|
725
|
+
): Promise.Promise<RemoteFunction>
|
|
624
726
|
local remoteEventName = self:_getMemberName(memberName, REMOTE_FUNCTION_SUFFIX)
|
|
625
|
-
return self:_promiseContainer(maid)
|
|
626
|
-
:
|
|
627
|
-
|
|
628
|
-
end)
|
|
727
|
+
return self:_promiseContainer(maid):Then(function(container)
|
|
728
|
+
return maid:GivePromise(promiseChild(container, remoteEventName, 5))
|
|
729
|
+
end)
|
|
629
730
|
end
|
|
630
731
|
|
|
631
|
-
function Remoting
|
|
732
|
+
function Remoting._observeFolderBrio(self: Remoting): _Observable.Observable<_Brio.Brio<Folder>>
|
|
632
733
|
assert(self._instance, "Not initialized")
|
|
633
734
|
|
|
634
|
-
return RxInstanceUtils.observeLastNamedChildBrio(
|
|
735
|
+
return RxInstanceUtils.observeLastNamedChildBrio(
|
|
736
|
+
self._instance,
|
|
737
|
+
self:GetContainerClass(),
|
|
738
|
+
self._remoteFolderName
|
|
739
|
+
) :: any
|
|
635
740
|
end
|
|
636
741
|
|
|
637
|
-
function Remoting
|
|
742
|
+
function Remoting._getOrCreateRemoteFunction(self: Remoting, memberName: string): RemoteFunction | BindableFunction
|
|
638
743
|
assert(type(memberName) == "string", "Bad memberName")
|
|
639
744
|
|
|
640
745
|
local remoteFunctionName = self:_getMemberName(memberName, REMOTE_FUNCTION_SUFFIX)
|
|
641
746
|
|
|
642
747
|
if self._remoteObjects[remoteFunctionName] then
|
|
643
|
-
return self._remoteObjects[remoteFunctionName]
|
|
748
|
+
return self._remoteObjects[remoteFunctionName] :: any
|
|
644
749
|
end
|
|
645
750
|
|
|
646
751
|
local container = self:_ensureContainer()
|
|
647
752
|
|
|
648
|
-
local remoteFunction
|
|
753
|
+
local remoteFunction: Instance
|
|
649
754
|
if self._useDummyObject then
|
|
650
755
|
remoteFunction = Instance.new("BindableFunction")
|
|
651
756
|
else
|
|
@@ -656,24 +761,24 @@ function Remoting:_getOrCreateRemoteFunction(memberName)
|
|
|
656
761
|
remoteFunction.Archivable = false
|
|
657
762
|
remoteFunction.Parent = container
|
|
658
763
|
|
|
659
|
-
self._remoteObjects[remoteFunctionName] = remoteFunction
|
|
764
|
+
self._remoteObjects[remoteFunctionName] = remoteFunction :: any
|
|
660
765
|
self._maid[remoteFunction] = remoteFunction
|
|
661
766
|
|
|
662
|
-
return remoteFunction
|
|
767
|
+
return remoteFunction :: any
|
|
663
768
|
end
|
|
664
769
|
|
|
665
|
-
function Remoting
|
|
770
|
+
function Remoting._getOrCreateRemoteEvent(self: Remoting, memberName: string): RemoteEvent | BindableEvent
|
|
666
771
|
assert(type(memberName) == "string", "Bad memberName")
|
|
667
772
|
|
|
668
773
|
local remoteEventName = self:_getMemberName(memberName, REMOTE_EVENT_SUFFIX)
|
|
669
774
|
|
|
670
775
|
if self._remoteObjects[remoteEventName] then
|
|
671
|
-
return self._remoteObjects[remoteEventName]
|
|
776
|
+
return self._remoteObjects[remoteEventName] :: any
|
|
672
777
|
end
|
|
673
778
|
|
|
674
779
|
local container = self:_ensureContainer()
|
|
675
780
|
|
|
676
|
-
local remoteEvent
|
|
781
|
+
local remoteEvent: Instance
|
|
677
782
|
if self._useDummyObject then
|
|
678
783
|
remoteEvent = Instance.new("BindableEvent")
|
|
679
784
|
else
|
|
@@ -685,31 +790,31 @@ function Remoting:_getOrCreateRemoteEvent(memberName)
|
|
|
685
790
|
remoteEvent.Parent = container
|
|
686
791
|
|
|
687
792
|
self._maid[remoteEvent] = remoteEvent
|
|
688
|
-
self._remoteObjects[remoteEventName] = remoteEvent
|
|
793
|
+
self._remoteObjects[remoteEventName] = remoteEvent :: any
|
|
689
794
|
|
|
690
|
-
return remoteEvent
|
|
795
|
+
return remoteEvent :: any
|
|
691
796
|
end
|
|
692
797
|
|
|
693
|
-
function Remoting
|
|
798
|
+
function Remoting._getMemberName(_self: Remoting, memberName: string, objectType: string): string
|
|
694
799
|
return memberName .. objectType
|
|
695
800
|
end
|
|
696
801
|
|
|
697
|
-
function Remoting
|
|
802
|
+
function Remoting._getDummyMemberName(self: Remoting, memberName: string, suffix: string): string
|
|
698
803
|
assert(self._useDummyObject, "Not dummy mode")
|
|
699
804
|
|
|
700
805
|
return memberName .. "_" .. suffix .. "_"
|
|
701
806
|
end
|
|
702
807
|
|
|
703
|
-
function Remoting
|
|
808
|
+
function Remoting._getDebugMemberName(self: Remoting, memberName: string): string
|
|
704
809
|
return string.format("%s.%s", self._name, memberName)
|
|
705
810
|
end
|
|
706
811
|
|
|
707
812
|
--[=[
|
|
708
813
|
Cleans up the remoting object
|
|
709
814
|
]=]
|
|
710
|
-
function Remoting
|
|
815
|
+
function Remoting.Destroy(self: Remoting)
|
|
711
816
|
self._maid:DoCleaning()
|
|
712
|
-
setmetatable(self, nil)
|
|
817
|
+
setmetatable(self :: any, nil)
|
|
713
818
|
end
|
|
714
819
|
|
|
715
820
|
return Remoting
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
Helper class for the [Remoting] object which allows more natural syntax
|
|
3
4
|
to be used against the remoting API surface.
|
|
@@ -13,6 +14,8 @@ local RemotingMember = {}
|
|
|
13
14
|
RemotingMember.ClassName = "RemotingMember"
|
|
14
15
|
RemotingMember.__index = RemotingMember
|
|
15
16
|
|
|
17
|
+
export type RemotingMember = typeof(setmetatable({}, RemotingMember))
|
|
18
|
+
|
|
16
19
|
--[=[
|
|
17
20
|
Constructs a new RemotingMember
|
|
18
21
|
|
|
@@ -21,7 +24,7 @@ RemotingMember.__index = RemotingMember
|
|
|
21
24
|
@param remotingRealm RemotingRealms
|
|
22
25
|
@return RemotingMember
|
|
23
26
|
]=]
|
|
24
|
-
function RemotingMember.new(remoting, memberName, remotingRealm)
|
|
27
|
+
function RemotingMember.new(remoting, memberName: string, remotingRealm: RemotingRealms.RemotingRealm): RemotingMember
|
|
25
28
|
local self = setmetatable({}, RemotingMember)
|
|
26
29
|
|
|
27
30
|
self._remoting = assert(remoting, "No remoting")
|
|
@@ -40,7 +43,7 @@ end
|
|
|
40
43
|
@param callback function
|
|
41
44
|
@return MaidTask
|
|
42
45
|
]=]
|
|
43
|
-
function RemotingMember:Bind(callback)
|
|
46
|
+
function RemotingMember:Bind(callback: (...any) -> ...any)
|
|
44
47
|
assert(type(callback) == "function", "Bad callback")
|
|
45
48
|
|
|
46
49
|
return self._remoting:Bind(self._memberName, callback)
|
|
@@ -57,7 +60,7 @@ end
|
|
|
57
60
|
@param callback function
|
|
58
61
|
@return MaidTask
|
|
59
62
|
]=]
|
|
60
|
-
function RemotingMember:Connect(callback)
|
|
63
|
+
function RemotingMember:Connect(callback: (...any) -> ())
|
|
61
64
|
assert(type(callback) == "function", "Bad callback")
|
|
62
65
|
|
|
63
66
|
return self._remoting:Connect(self._memberName, callback)
|
|
@@ -125,7 +128,6 @@ function RemotingMember:PromiseFireServer(...)
|
|
|
125
128
|
return self._remoting:PromiseFireServer(self._memberName, ...)
|
|
126
129
|
end
|
|
127
130
|
|
|
128
|
-
|
|
129
131
|
--[=[
|
|
130
132
|
Invokes the client from the server.
|
|
131
133
|
|
|
@@ -136,7 +138,7 @@ end
|
|
|
136
138
|
@param ... any
|
|
137
139
|
@return Promise<any>
|
|
138
140
|
]=]
|
|
139
|
-
function RemotingMember:PromiseInvokeClient(player, ...)
|
|
141
|
+
function RemotingMember:PromiseInvokeClient(player: Player, ...)
|
|
140
142
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
141
143
|
assert(self._remotingRealm == RemotingRealms.SERVER, "PromiseInvokeClient must be called on client")
|
|
142
144
|
|
|
@@ -182,8 +184,11 @@ end
|
|
|
182
184
|
@param excludePlayer Player | nil
|
|
183
185
|
@param ... any
|
|
184
186
|
]=]
|
|
185
|
-
function RemotingMember:FireAllClientsExcept(excludePlayer, ...)
|
|
186
|
-
assert(
|
|
187
|
+
function RemotingMember:FireAllClientsExcept(excludePlayer: Player, ...)
|
|
188
|
+
assert(
|
|
189
|
+
typeof(excludePlayer) == "Instance" and excludePlayer:IsA("Player") or excludePlayer == nil,
|
|
190
|
+
"Bad excludePlayer"
|
|
191
|
+
)
|
|
187
192
|
assert(self._remotingRealm == RemotingRealms.SERVER, "FireAllClientsExcept must be called on server")
|
|
188
193
|
|
|
189
194
|
self._remoting:FireAllClientsExcept(self._memberName, excludePlayer, ...)
|
|
@@ -198,7 +203,7 @@ end
|
|
|
198
203
|
@param player Instance
|
|
199
204
|
@param ... any
|
|
200
205
|
]=]
|
|
201
|
-
function RemotingMember:FireClient(player, ...)
|
|
206
|
+
function RemotingMember:FireClient(player: Player, ...)
|
|
202
207
|
assert(self._remotingRealm == RemotingRealms.SERVER, "FireClient must be called on client")
|
|
203
208
|
assert(typeof(player) == "Instance" and player:IsA("Player"), "Bad player")
|
|
204
209
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class RemotingRealmUtils
|
|
3
4
|
]=]
|
|
@@ -10,11 +11,11 @@ local RemotingRealms = require("RemotingRealms")
|
|
|
10
11
|
|
|
11
12
|
local RemotingRealmUtils = {}
|
|
12
13
|
|
|
13
|
-
function RemotingRealmUtils.isRemotingRealm(realm)
|
|
14
|
+
function RemotingRealmUtils.isRemotingRealm(realm: any): boolean
|
|
14
15
|
return realm == RemotingRealms.SERVER or realm == RemotingRealms.CLIENT
|
|
15
16
|
end
|
|
16
17
|
|
|
17
|
-
function RemotingRealmUtils.inferRemotingRealm()
|
|
18
|
+
function RemotingRealmUtils.inferRemotingRealm(): RemotingRealms.RemotingRealm
|
|
18
19
|
if RunService:IsServer() then
|
|
19
20
|
return RemotingRealms.SERVER
|
|
20
21
|
elseif RunService:IsClient() then
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
--!strict
|
|
1
2
|
--[=[
|
|
2
3
|
@class RemotingRealms
|
|
3
4
|
]=]
|
|
@@ -6,7 +7,14 @@ local require = require(script.Parent.loader).load(script)
|
|
|
6
7
|
|
|
7
8
|
local Table = require("Table")
|
|
8
9
|
|
|
10
|
+
export type RemotingRealm = "server" | "client"
|
|
11
|
+
|
|
12
|
+
export type RemotingRealms = {
|
|
13
|
+
SERVER: "server",
|
|
14
|
+
CLIENT: "client",
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
return Table.readonly({
|
|
10
|
-
SERVER = "server"
|
|
11
|
-
CLIENT = "client"
|
|
12
|
-
})
|
|
18
|
+
SERVER = "server",
|
|
19
|
+
CLIENT = "client",
|
|
20
|
+
} :: RemotingRealms)
|