forked from andremussche/DelphiWebsockets
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
uROIdServerWebsocketHandling.pas
81 lines (68 loc) · 2.49 KB
/
uROIdServerWebsocketHandling.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
unit uROIdServerWebsocketHandling;
interface
uses
IdServerWebsocketHandling, IdServerWebsocketContext,
IdContext,
Classes, IdIOHandlerWebsocket;
type
TOnRemObjectsRequest = procedure(const AThread: TIdContext; const strmRequest: TMemoryStream; const strmResponse: TMemoryStream) of object;
TROIdServerWSContext = class(TIdServerWSContext)
private
FOnRemObjectsRequest: TOnRemObjectsRequest;
public
property OnRemObjectsRequest: TOnRemObjectsRequest read FOnRemObjectsRequest write FOnRemObjectsRequest;
end;
TROIdServerWebsocketHandling = class(TIdServerWebsocketHandling)
protected
class procedure DoWSExecute(AThread: TIdContext; aSocketIOHandler: TIdServerSocketIOHandling_Ext); override;
class procedure HandleWSMessage(AContext: TIdServerWSContext; aType: TWSDataType; aRequestStrm, aResponseStrm: TMemoryStream;
aSocketIOHandler: TIdServerSocketIOHandling_Ext);override;
end;
const
C_ROWSNR: array[0..5] of AnsiChar = 'ROWSNR';
implementation
uses
uROHTTPWebsocketServer, uROClientIntf;
{ TROIdServerWebsocketHandling }
class procedure TROIdServerWebsocketHandling.DoWSExecute(AThread: TIdContext;
aSocketIOHandler: TIdServerSocketIOHandling_Ext);
var
transport: TROTransportContext;
begin
try
inherited DoWSExecute(AThread, aSocketIOHandler);
finally
transport := AThread.Data as TROTransportContext;
//detach RO transport
if transport <> nil then
(transport as IROTransport)._Release;
end;
end;
class procedure TROIdServerWebsocketHandling.HandleWSMessage(
AContext: TIdServerWSContext; aType: TWSDataType; aRequestStrm, aResponseStrm: TMemoryStream;
aSocketIOHandler: TIdServerSocketIOHandling_Ext);
var
cWSNR: array[0..High(C_ROWSNR)] of AnsiChar;
rocontext: TROIdServerWSContext;
begin
if aRequestStrm.Size > Length(C_ROWSNR) + SizeOf(Integer) then
begin
aRequestStrm.Position := aRequestStrm.Size - Length(C_ROWSNR) - SizeOf(Integer);
aRequestStrm.Read(cWSNR[0], Length(cWSNR));
end
else
cWSNR := '';
if cWSNR = C_ROWSNR then
begin
rocontext := AContext as TROIdServerWSContext;
if Assigned(rocontext.OnRemObjectsRequest) then
rocontext.OnRemObjectsRequest(AContext, aRequestStrm, aResponseStrm);
end
// else if SameText(context.path, '/RemObjects') then
// begin
// ProcessRemObjectsRequest(AThread, strmRequest, strmResponse, transport);
// end
else
inherited HandleWSMessage(AContext, aType, aRequestStrm, aResponseStrm, aSocketIOHandler);
end;
end.