Commit 45399c29 by Michael Brachmann

debugging websockets

parent f46aa96a
......@@ -3,33 +3,26 @@ unit Ws.ServiceImpl;
interface
uses
Common.Logging,
System.SysUtils,
XData.Server.Module,
XData.Service.Common,
Sparkle.WebSocket,
XData.Server.Module,
System.JSON,
Sparkle.Sys.Timer,
Sparkle.HttpServer.Context,
Ws.Service,
BaseRequest,
LoginRequest,
Pkg.Json.DTO,
Generics.Collections;
Ws.Service;
type
[ServiceImplementation]
TWebSocketService = class(TInterfacedObject, IWebSocketService)
public
function WebSockerConnectionHandler: TJSONObject;
private
function Health: string;
procedure ProcessJsonMessage(const AMsg: string);
end;
implementation
{ TWebSocketService }
uses
System.SysUtils,
Common.Logging,
Sparkle.WebSocket,
Sparkle.Sys.Timer,
Sparkle.HttpServer.Context;
function TWebSocketService.WebSockerConnectionHandler: TJSONObject;
var
......@@ -62,7 +55,6 @@ begin
end;
MsgStr := TEncoding.Default.GetString(Msg.Data);
//TODO: verify JWT in MsgStr against serverConfig.jwtTokenSecret
// use the BCL JOSE verify API once the correct method is confirmed
Logger.Log(1, 'websocket auth ok (token received, verification pending)-------');
Timer := TSparkleTimer.Create(
......@@ -83,7 +75,6 @@ begin
begin
MsgStr := TEncoding.Default.GetString(Msg.Data);
Logger.Log(1, 'Web Socket Message: ' + MsgStr);
//TODO: store connection in map with device id, implement message protocol
end;
TWebSocketMessageType.Close:
Break;
......@@ -94,52 +85,6 @@ begin
end;
end;
function TWebSocketService.Health: string;
begin
Result := 'ok';
end;
procedure TWebSocketService.ProcessJsonMessage(const AMsg: string);
var
MsgDTO: TBaseRequest;
request: TRequest;
rawJsObj: TJSONArray;
begin
MsgDTO := nil;
try
rawJsObj:=TJSONObject.ParseJSONValue(AMsg) as TJSONArray;
MsgDTO.FromJson(AMsg);
for request in MsgDTO.Request do
begin
// Process each Request object
Logger.Log(1, 'Action: ' + request.RequestId);
if request.RequestId = 'doLogin' then
begin
Logger.Log(1, 'Action: ' + request.RequestId);
//TODO: implement instantiation and handling of each request type
// not sure if upcasting works in delphi here but probably not so we do this:
// rawJsObj:=TJSONObject.ParseJSONValue(AMsg) as TJSONArray
// and then ---->
// loginRequest.FromJson(rawJsObj.Items[0].ToJSON());
var
loginRequest:TLoginRequest;
begin
loginRequest.FromJson(rawJsObj.Items[0].ToJSON());
//loginRequest.LoginInfo.Shift
//TODO: it would be really great to have the JDO convert to database sql
end;
end;
end;
// ... further logic
finally
MsgDTO.Free;
end;
end;
initialization
RegisterServiceType(TWebSocketService);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment