Skip to content

Commit c80d12d

Browse files
author
Arnaud Bouchez
committed
net: enhanced TSocketsIOClient.LocalPublishedMethods()
- to register self if no Instance is supplied
1 parent 14edbc7 commit c80d12d

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.3.9321'
1+
'2.3.9322'

src/net/mormot.net.ws.client.pas

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ TSocketsIOClient = class(TEngineIOAbstract)
238238
procedure AfterOpen(OpenPayload: PUtf8Char);
239239
// handle server response after namespace connection request
240240
procedure AfterNamespaceConnect(const Response: TSocketIOMessage);
241-
procedure OnEvent(const aMessage: TSocketIOMessage);
242-
procedure OnAck(const Message: TSocketIOMessage);
241+
procedure OnEvent(const aMessage: TSocketIOMessage); virtual;
242+
procedure OnAck(const Message: TSocketIOMessage); virtual;
243243
public
244244
/// low-level client WebSockets connection factory for host and port
245245
// - calls THttpClientWebSockets.WebSocketsConnect for the Socket.IO protocol
@@ -276,9 +276,11 @@ TSocketsIOClient = class(TEngineIOAbstract)
276276
const Callback: TOnSocketIOEvent);
277277
/// register all published methods of a class as local namespace handlers
278278
// - published method names are case-sensitive Socket.IO event names
279+
// - if no Instance is supplied, will register self published methods
279280
// - the methods should follow the TOnSocketIOMethod exact signature, i.e.
280-
// ! procedure eventname(const Data: TDocVariantData);
281-
procedure LocalPublishedMethods(const Namespace: RawUtf8; Instance: TObject);
281+
// ! function eventname(const Data: TDocVariantData): RawJson;
282+
procedure LocalPublishedMethods(const Namespace: RawUtf8;
283+
Instance: TObject = nil);
282284
/// access to a given Socket.IO namespace
283285
// - sends a connect message if needed (for first-time registration)
284286
function Connect(const NameSpace: RawUtf8; const Data: RawUtf8 = '';
@@ -854,8 +856,9 @@ procedure TSocketsIOClient.LocalEvent(
854856
procedure TSocketsIOClient.LocalPublishedMethods(
855857
const Namespace: RawUtf8; Instance: TObject);
856858
begin
857-
if Instance <> nil then
858-
Local(NameSpace).RegisterPublishedMethods(Instance);
859+
if Instance = nil then
860+
Instance := self;
861+
Local(NameSpace).RegisterPublishedMethods(Instance);
859862
end;
860863

861864
function TSocketsIOClient.RemoteNames: TRawUtf8DynArray;

0 commit comments

Comments
 (0)