Commit 5cc2b73b by emsys

websocket wired up in client. ws client connection error.

parent 80ed6f36
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{012E57DC-0378-4E45-B2F6-DFA72B2D10B1}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<Projects Include="emiMobileServer\emiMobileServer.dproj">
<Dependencies/>
</Projects>
<Projects Include="webEMIMobile\webEmiMobile.dproj">
<Dependencies/>
</Projects>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Default.Personality.12</Borland.Personality>
<Borland.ProjectType/>
<BorlandProject>
<Default.Personality/>
</BorlandProject>
</ProjectExtensions>
<Target Name="emiMobileServer">
<MSBuild Projects="emiMobileServer\emiMobileServer.dproj"/>
</Target>
<Target Name="emiMobileServer:Clean">
<MSBuild Projects="emiMobileServer\emiMobileServer.dproj" Targets="Clean"/>
</Target>
<Target Name="emiMobileServer:Make">
<MSBuild Projects="emiMobileServer\emiMobileServer.dproj" Targets="Make"/>
</Target>
<Target Name="webEmiMobile">
<MSBuild Projects="webEMIMobile\webEmiMobile.dproj"/>
</Target>
<Target Name="webEmiMobile:Clean">
<MSBuild Projects="webEMIMobile\webEmiMobile.dproj" Targets="Clean"/>
</Target>
<Target Name="webEmiMobile:Make">
<MSBuild Projects="webEMIMobile\webEmiMobile.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="emiMobileServer;webEmiMobile"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="emiMobileServer:Clean;webEmiMobile:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="emiMobileServer:Make;webEmiMobile:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
...@@ -27,6 +27,8 @@ object WsServerModule: TWsServerModule ...@@ -27,6 +27,8 @@ object WsServerModule: TWsServerModule
OnGetSecret = XDataServer1JWTGetSecret OnGetSecret = XDataServer1JWTGetSecret
end end
object XDataServer1WebSocket: TSparkleWebSocketMiddleware object XDataServer1WebSocket: TSparkleWebSocketMiddleware
AllowedOrigins.Strings = (
'*')
end end
end end
end end
...@@ -3,6 +3,7 @@ unit Ws.ServiceImpl; ...@@ -3,6 +3,7 @@ unit Ws.ServiceImpl;
interface interface
uses uses
Common.Logging,
System.SysUtils, System.SysUtils,
XData.Server.Module, XData.Server.Module,
XData.Service.Common, XData.Service.Common,
...@@ -37,6 +38,8 @@ var ...@@ -37,6 +38,8 @@ var
JSONObject: TJSONObject; JSONObject: TJSONObject;
MsgStr: string; MsgStr: string;
begin begin
Logger.Log(1, 'websocket begin-------');
// Check if the client sent an websocket request, if yes the IWebSocketUpgrader interface will be available. // Check if the client sent an websocket request, if yes the IWebSocketUpgrader interface will be available.
Upgrader := THttpServerContext.Current.Item<IWebSocketUpgrader>; Upgrader := THttpServerContext.Current.Item<IWebSocketUpgrader>;
if Upgrader = nil then if Upgrader = nil then
...@@ -44,10 +47,12 @@ begin ...@@ -44,10 +47,12 @@ begin
TXDataOperationContext.Current.Handler.SetStatusCode(400); TXDataOperationContext.Current.Handler.SetStatusCode(400);
Exit; Exit;
end; end;
Logger.Log(1, 'websocket upgrading-------');
// Upgrade to websocket // Upgrade to websocket
WebSocket := Upgrader.Upgrade; WebSocket := Upgrader.Upgrade;
Logger.Log(1, 'websocket upgraded-------');
// Send a message to client every 2 seconds // Send a message to client every 2 seconds
Timer := TSparkleTimer.Create( Timer := TSparkleTimer.Create(
procedure(Value: TObject) procedure(Value: TObject)
...@@ -65,12 +70,12 @@ begin ...@@ -65,12 +70,12 @@ begin
Msg := WebSocket.Receive; Msg := WebSocket.Receive;
case Msg.MessageType of case Msg.MessageType of
TWebSocketMessageType.Text: TWebSocketMessageType.Text:
Logger.Log(1, 'Web Socket Message: ' + MsgStr);
//TODO: HERE we need to create a map to store connections for later //TODO: HERE we need to create a map to store connections for later
// and implement protocol to communicate // and implement protocol to communicate
// store websocket obj, handle another layer of compression/encryption, // store websocket obj, handle another layer of compression/encryption,
// probably store the websocket connection in a map with device id or some other uuid // probably store the websocket connection in a map with device id or some other uuid
self.ProcessJsonMessage(MsgStr); //self.ProcessJsonMessage(MsgStr);
//TWebSocketMessageType.Close: //TWebSocketMessageType.Close:
// WebSocket.SendClose(WebSocketStatusCodes.NormalClosure); // WebSocket.SendClose(WebSocketStatusCodes.NormalClosure);
end; end;
...@@ -94,10 +99,10 @@ begin ...@@ -94,10 +99,10 @@ begin
for request in MsgDTO.Request do for request in MsgDTO.Request do
begin begin
// Process each Request object // Process each Request object
Writeln('Action: ' + request.RequestId); Logger.Log(1, 'Action: ' + request.RequestId);
if request.RequestId = 'doLogin' then if request.RequestId = 'doLogin' then
begin begin
Writeln('Action: ' + request.RequestId); Logger.Log(1, 'Action: ' + request.RequestId);
//TODO: implement instantiation and handling of each request type //TODO: implement instantiation and handling of each request type
// not sure if upcasting works in delphi here but probably not so we do this: // not sure if upcasting works in delphi here but probably not so we do this:
// rawJsObj:=TJSONObject.ParseJSONValue(AMsg) as TJSONArray // rawJsObj:=TJSONObject.ParseJSONValue(AMsg) as TJSONArray
......
[Settings] [Settings]
LogFileNum=652 LogFileNum=677
webClientVersion=0.1.0 webClientVersion=0.1.0
object DataModule1: TDataModule1 object dmWebsocket: TdmWebsocket
Height = 480 Height = 480
Width = 640 Width = 640
object WebSocketClient1: TWebSocketClient object EMiMobileWebSocketClient: TWebSocketClient
UseSSL = True
Port = 443
HostName = 'webapps.em-sys.net'
PathName = '/emiMobile/ws/emimobile'
Protocols.Strings = (
'WEB')
OnConnect = EMiMobileWebSocketClientConnect
OnBinaryDataReceived = EMiMobileWebSocketClientBinaryDataReceived
OnDisconnect = EMiMobileWebSocketClientDisconnect
OnDataReceived = EMiMobileWebSocketClientDataReceived
OnMessageReceived = EMiMobileWebSocketClientMessageReceived
Left = 218 Left = 218
Top = 130 Top = 130
end end
......
...@@ -3,19 +3,29 @@ unit Module.Websocket; ...@@ -3,19 +3,29 @@ unit Module.Websocket;
interface interface
uses uses
System.SysUtils, System.Classes, WEBLib.WebSocketClient; System.SysUtils, System.Classes, WEBLib.WebSocketClient, Web, WEBLib.Controls, WEBLib.Modules;
type type
TDataModule1 = class(TDataModule) TdmWebsocket = class(TWebDataModule)
WebSocketClient1: TWebSocketClient;
private private
{ Private declarations } procedure EMiMobileWebSocketClientConnect(Sender: TObject);
procedure EMiMobileWebSocketClientDataReceived(Sender: TObject;
Origin: string; SocketData: TJSObjectRecord);
procedure EMiMobileWebSocketClientDisconnect(Sender: TObject);
procedure EMiMobileWebSocketClientMessageReceived(Sender: TObject;
AMessage: string);
procedure EMiMobileWebSocketClientBinaryDataReceived(Sender: TObject;
AData: TBytes);
public public
{ Public declarations } EMiMobileWebSocketClient: TWebSocketClient;
procedure DataModuleCreate(Sender: TObject);
end; end;
var var
DataModule1: TDataModule1; dmWebsocket: TdmWebsocket;
implementation implementation
...@@ -23,4 +33,37 @@ implementation ...@@ -23,4 +33,37 @@ implementation
{$R *.dfm} {$R *.dfm}
procedure TdmWebsocket.DataModuleCreate(Sender: TObject);
begin
end;
procedure TdmWebsocket.EMiMobileWebSocketClientBinaryDataReceived(
Sender: TObject; AData: TBytes);
begin
console.log('EMiMobileWebSocketClientBinaryDataReceived');
end;
procedure TdmWebsocket.EMiMobileWebSocketClientConnect(Sender: TObject);
begin
console.log('EMiMobileWebSocketClientConnect');
end;
procedure TdmWebsocket.EMiMobileWebSocketClientDataReceived(Sender: TObject;
Origin: string; SocketData: TJSObjectRecord);
begin
console.log('EMiMobileWebSocketClientDataReceived');
end;
procedure TdmWebsocket.EMiMobileWebSocketClientDisconnect(Sender: TObject);
begin
console.log('EMiMobileWebSocketClientDisconnect');
end;
procedure TdmWebsocket.EMiMobileWebSocketClientMessageReceived(Sender: TObject;
AMessage: string);
begin
console.log('EMiMobileWebSocketClientMessageReceived');
end;
end. end.
...@@ -6,7 +6,8 @@ uses ...@@ -6,7 +6,8 @@ uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls, System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, WEBLib.ExtCtrls, Vcl.Controls, Vcl.StdCtrls, WEBLib.Forms, WEBLib.Dialogs, WEBLib.ExtCtrls, Vcl.Controls, Vcl.StdCtrls,
WEBLib.StdCtrls, Data.DB, XData.Web.JsonDataset, XData.Web.Dataset, WEBLib.StdCtrls, Data.DB, XData.Web.JsonDataset, XData.Web.Dataset,
App.Types, ConnectionModule, XData.Web.Client, View.Map, View.Units, View.Complaints; App.Types, ConnectionModule, XData.Web.Client, View.Map, View.Units, View.Complaints,
Module.Websocket;
type type
TFViewMain = class(TWebForm) TFViewMain = class(TWebForm)
...@@ -48,6 +49,7 @@ type ...@@ -48,6 +49,7 @@ type
FComplaintsForm: TFViewComplaints; FComplaintsForm: TFViewComplaints;
FDetailsForm: TWebForm; FDetailsForm: TWebForm;
FLogoutProc: TLogoutProc; FLogoutProc: TLogoutProc;
//WebSocketModule: Module.Websocket;
[async] procedure RefreshBadgesAsync; [async] procedure RefreshBadgesAsync;
procedure ShowUnitDetails(UnitId: string); procedure ShowUnitDetails(UnitId: string);
procedure SetHeaderTitle(const title: string); procedure SetHeaderTitle(const title: string);
...@@ -137,6 +139,9 @@ begin ...@@ -137,6 +139,9 @@ begin
SetActivePanel(apMap); SetActivePanel(apMap);
RefreshBadgesAsync; RefreshBadgesAsync;
dmWebsocket := TdmWebsocket.Create(Self);
dmWebsocket.EMiMobileWebSocketClient.Active := True;
end; end;
...@@ -411,6 +416,7 @@ begin ...@@ -411,6 +416,7 @@ begin
end; end;
procedure TFViewMain.tmrGlobalRefreshTimer(Sender: TObject); procedure TFViewMain.tmrGlobalRefreshTimer(Sender: TObject);
begin begin
Inc(FGlobalRefreshTick); Inc(FGlobalRefreshTick);
......
...@@ -24,7 +24,8 @@ uses ...@@ -24,7 +24,8 @@ uses
View.ComplaintDetails in 'View.ComplaintDetails.pas' {FViewComplaintDetails: TWebForm} {*.html}, View.ComplaintDetails in 'View.ComplaintDetails.pas' {FViewComplaintDetails: TWebForm} {*.html},
View.UnitDetails in 'View.UnitDetails.pas' {FViewUnitDetails: TWebForm} {*.html}, View.UnitDetails in 'View.UnitDetails.pas' {FViewUnitDetails: TWebForm} {*.html},
uMapFilters in 'uMapFilters.pas', uMapFilters in 'uMapFilters.pas',
View.ComplaintArchive in 'View.ComplaintArchive.pas' {FViewComplaintArchive: TWebForm} {*.html}; View.ComplaintArchive in 'View.ComplaintArchive.pas' {FViewComplaintArchive: TWebForm} {*.html},
Module.Websocket in 'Module.Websocket.pas' {dmWebsocket: TDataModule};
{$R *.res} {$R *.res}
......
...@@ -194,6 +194,11 @@ ...@@ -194,6 +194,11 @@
<FormType>dfm</FormType> <FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass> <DesignClass>TWebForm</DesignClass>
</DCCReference> </DCCReference>
<DCCReference Include="Module.Websocket.pas">
<Form>dmWebsocket</Form>
<FormType>dfm</FormType>
<DesignClass>TDataModule</DesignClass>
</DCCReference>
<None Include="index.html"/> <None Include="index.html"/>
<None Include="css\app.css"/> <None Include="css\app.css"/>
<None Include="css\spinner.css"/> <None Include="css\spinner.css"/>
......
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