2017-05-25 12:30:08 +02:00
|
|
|
unit SSEControllerU;
|
2022-12-09 09:58:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2023-01-02 22:24:03 +01:00
|
|
|
MVCFramework, MVCFramework.Commons, MVCFramework.SSEController;
|
2022-12-09 09:58:55 +01:00
|
|
|
|
|
|
|
type
|
2023-01-02 22:24:03 +01:00
|
|
|
[MVCPath('/stocks')]
|
|
|
|
TMySSEController = class(TMVCSSEController)
|
2022-12-09 09:58:55 +01:00
|
|
|
protected
|
2023-01-02 22:24:03 +01:00
|
|
|
function GetServerSentEvents(const LastEventID: String): TMVCSSEMessages; override;
|
2022-12-09 09:58:55 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2023-01-02 22:24:03 +01:00
|
|
|
MVCFramework.Logger, System.SysUtils, StorageU, System.DateUtils;
|
|
|
|
|
|
|
|
{ TMySSEController }
|
2022-12-09 09:58:55 +01:00
|
|
|
|
2023-01-02 22:24:03 +01:00
|
|
|
function TMySSEController.GetServerSentEvents(const LastEventID: String): TMVCSSEMessages;
|
2022-12-09 09:58:55 +01:00
|
|
|
var
|
|
|
|
lCurrentEventID: Integer;
|
2023-01-06 15:18:50 +01:00
|
|
|
lSSEMessage: TSSEMessage;
|
2022-12-09 09:58:55 +01:00
|
|
|
begin
|
2023-01-02 22:24:03 +01:00
|
|
|
Sleep(1000);
|
|
|
|
lSSEMessage.Event := 'stockupdate';
|
|
|
|
lSSEMessage.Data := GetNextDataToSend(StrToIntDef(LastEventID, 0), lCurrentEventID);
|
|
|
|
lSSEMessage.Id := lCurrentEventID.ToString;
|
|
|
|
Result := [
|
|
|
|
lSSEMessage
|
|
|
|
];
|
2022-12-09 09:58:55 +01:00
|
|
|
end;
|
|
|
|
|
2017-05-25 12:30:08 +02:00
|
|
|
end.
|
2022-12-09 09:58:55 +01:00
|
|
|
|