|
@@ -313,7 +313,7 @@ type
|
|
Procedure DoDisconnect; virtual; abstract;
|
|
Procedure DoDisconnect; virtual; abstract;
|
|
// Read message from connection. Return False if connection was closed.
|
|
// Read message from connection. Return False if connection was closed.
|
|
function DoReadMessage: Boolean;
|
|
function DoReadMessage: Boolean;
|
|
- procedure DispatchEvent(aInitialType : TFrameType; aFrame: TWSFrame);
|
|
|
|
|
|
+ procedure DispatchEvent(aInitialType : TFrameType; aFrame: TWSFrame; aMessageContent: TBytes);
|
|
Procedure SetHandShakeRequest(aRequest : TWSHandShakeRequest);
|
|
Procedure SetHandShakeRequest(aRequest : TWSHandShakeRequest);
|
|
Function HandleIncoming(aFrame: TWSFrame) : Boolean; virtual;
|
|
Function HandleIncoming(aFrame: TWSFrame) : Boolean; virtual;
|
|
function GetHandshakeCompleted: Boolean; virtual; abstract;
|
|
function GetHandshakeCompleted: Boolean; virtual; abstract;
|
|
@@ -502,7 +502,6 @@ begin
|
|
FlagPong : Self:=ftPong;
|
|
FlagPong : Self:=ftPong;
|
|
else
|
|
else
|
|
Self:=ftFutureOpcodes;
|
|
Self:=ftFutureOpcodes;
|
|
- //Raise EConvertError.CreateFmt(SErrInvalidFrameType,[aValue]);
|
|
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1210,7 +1209,7 @@ begin
|
|
Result:=DoReadMessage;
|
|
Result:=DoReadMessage;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWSConnection.DispatchEvent(aInitialType : TFrameType; aFrame : TWSFrame);
|
|
|
|
|
|
+procedure TWSConnection.DispatchEvent(aInitialType: TFrameType; aFrame: TWSFrame; aMessageContent: TBytes);
|
|
|
|
|
|
Var
|
|
Var
|
|
msg: TWSMessage;
|
|
msg: TWSMessage;
|
|
@@ -1220,11 +1219,8 @@ begin
|
|
ftPing,
|
|
ftPing,
|
|
ftPong,
|
|
ftPong,
|
|
ftClose :
|
|
ftClose :
|
|
- begin
|
|
|
|
- If Assigned(FOnControl) then
|
|
|
|
- FOnControl(Self,aInitialType,FMessageContent);
|
|
|
|
- FMessageContent:=[];
|
|
|
|
- end;
|
|
|
|
|
|
+ If Assigned(FOnControl) then
|
|
|
|
+ FOnControl(Self,aInitialType,aMessageContent);
|
|
ftBinary,
|
|
ftBinary,
|
|
ftText :
|
|
ftText :
|
|
begin
|
|
begin
|
|
@@ -1238,16 +1234,15 @@ begin
|
|
Msg.Sequences:=[fsContinuation];
|
|
Msg.Sequences:=[fsContinuation];
|
|
if aFrame.FinalFrame then
|
|
if aFrame.FinalFrame then
|
|
Msg.Sequences:=Msg.Sequences+[fsLast];
|
|
Msg.Sequences:=Msg.Sequences+[fsLast];
|
|
- Msg.PayLoad:=FMessageContent;
|
|
|
|
|
|
+ Msg.PayLoad:=aMessageContent;
|
|
FOnMessageReceived(Self, Msg);
|
|
FOnMessageReceived(Self, Msg);
|
|
end;
|
|
end;
|
|
- FMessageContent:=[];
|
|
|
|
end;
|
|
end;
|
|
ftContinuation: ; // Cannot happen normally
|
|
ftContinuation: ; // Cannot happen normally
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TWSConnection.HandleIncoming(aFrame : TWSFrame) : Boolean;
|
|
|
|
|
|
+function TWSConnection.HandleIncoming(aFrame: TWSFrame) : Boolean;
|
|
|
|
|
|
Procedure UpdateCloseState;
|
|
Procedure UpdateCloseState;
|
|
|
|
|
|
@@ -1279,8 +1274,7 @@ begin
|
|
{ If control frame it must be complete }
|
|
{ If control frame it must be complete }
|
|
if ((aFrame.FrameType=ftPing) or
|
|
if ((aFrame.FrameType=ftPing) or
|
|
(aFrame.FrameType=ftPong) or
|
|
(aFrame.FrameType=ftPong) or
|
|
- (aFrame.FrameType=ftClose) or
|
|
|
|
- (aFrame.FrameType=ftContinuation))
|
|
|
|
|
|
+ (aFrame.FrameType=ftClose))
|
|
and (not aFrame.FinalFrame) then
|
|
and (not aFrame.FinalFrame) then
|
|
begin
|
|
begin
|
|
Close('', CLOSE_PROTOCOL_ERROR);
|
|
Close('', CLOSE_PROTOCOL_ERROR);
|
|
@@ -1289,21 +1283,30 @@ begin
|
|
Exit;
|
|
Exit;
|
|
end;
|
|
end;
|
|
// here we handle payload.
|
|
// here we handle payload.
|
|
- if aFrame.FrameType<>ftContinuation then
|
|
|
|
|
|
+ if aFrame.FrameType in [ftBinary,ftText] then
|
|
|
|
+ begin
|
|
FInitialOpcode:=aFrame.FrameType;
|
|
FInitialOpcode:=aFrame.FrameType;
|
|
- if aFrame.FrameType in [ftPong,ftBinary,ftText,ftPing] then
|
|
|
|
FMessageContent:=aFrame.Payload.Data;
|
|
FMessageContent:=aFrame.Payload.Data;
|
|
|
|
+ end;
|
|
// Special handling
|
|
// Special handling
|
|
Case aFrame.FrameType of
|
|
Case aFrame.FrameType of
|
|
ftContinuation:
|
|
ftContinuation:
|
|
- FMessageContent.Append(aFrame.Payload.Data);
|
|
|
|
|
|
+ begin
|
|
|
|
+ FMessageContent.Append(aFrame.Payload.Data);
|
|
|
|
+ if aFrame.FinalFrame then
|
|
|
|
+ DispatchEvent(FInitialOpcode,aFrame,FMessageContent);
|
|
|
|
+ end;
|
|
|
|
+
|
|
ftPing:
|
|
ftPing:
|
|
begin
|
|
begin
|
|
if aFrame.Payload.DataLength > 125 then
|
|
if aFrame.Payload.DataLength > 125 then
|
|
Close('', CLOSE_PROTOCOL_ERROR)
|
|
Close('', CLOSE_PROTOCOL_ERROR)
|
|
else
|
|
else
|
|
if not (woPongExplicit in Options) then
|
|
if not (woPongExplicit in Options) then
|
|
|
|
+ begin
|
|
Send(ftPong,aFrame.Payload.Data);
|
|
Send(ftPong,aFrame.Payload.Data);
|
|
|
|
+ DispatchEvent(ftPing,aFrame,aFrame.Payload.Data);
|
|
|
|
+ end;
|
|
end;
|
|
end;
|
|
ftClose:
|
|
ftClose:
|
|
begin
|
|
begin
|
|
@@ -1311,11 +1314,11 @@ begin
|
|
Result:=FCloseState=csNone;
|
|
Result:=FCloseState=csNone;
|
|
if Result then
|
|
if Result then
|
|
begin
|
|
begin
|
|
- FMessageContent:=aFrame.Payload.Data;
|
|
|
|
if not (woCloseExplicit in Options) then
|
|
if not (woCloseExplicit in Options) then
|
|
begin
|
|
begin
|
|
Close('', CLOSE_NORMAL_CLOSURE); // Will update state
|
|
Close('', CLOSE_NORMAL_CLOSURE); // Will update state
|
|
Result:=False; // We can disconnect.
|
|
Result:=False; // We can disconnect.
|
|
|
|
+ DispatchEvent(ftClose,aFrame,aFrame.Payload.Data);
|
|
end
|
|
end
|
|
else
|
|
else
|
|
UpdateCloseState
|
|
UpdateCloseState
|
|
@@ -1323,11 +1326,12 @@ begin
|
|
else
|
|
else
|
|
UpdateCloseState;
|
|
UpdateCloseState;
|
|
end;
|
|
end;
|
|
|
|
+ ftBinary,ftText:
|
|
|
|
+ if aFrame.FinalFrame then
|
|
|
|
+ DispatchEvent(FInitialOpcode,aFrame,aFrame.Payload.Data);
|
|
else
|
|
else
|
|
; // avoid Compiler warning
|
|
; // avoid Compiler warning
|
|
End;
|
|
End;
|
|
- if (aFrame.FinalFrame) or (woIndividualFrames in Options) then
|
|
|
|
- DispatchEvent(FInitialOpcode,aFrame);
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
function TWSConnection.FrameClass: TWSFrameClass;
|
|
function TWSConnection.FrameClass: TWSFrameClass;
|
|
@@ -1336,7 +1340,7 @@ begin
|
|
Result:=TWSFrame;
|
|
Result:=TWSFrame;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TWSConnection.Send(const AMessage: UTF8String);
|
|
|
|
|
|
+procedure TWSConnection.Send(const AMessage: UTF8string);
|
|
|
|
|
|
var
|
|
var
|
|
aFrame: TWSFrame;
|
|
aFrame: TWSFrame;
|
|
@@ -1412,7 +1416,7 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-Function TWSConnection.DoReadMessage : Boolean ;
|
|
|
|
|
|
+function TWSConnection.DoReadMessage: Boolean;
|
|
|
|
|
|
Var
|
|
Var
|
|
F : TWSFrame;
|
|
F : TWSFrame;
|