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
OnGetSecret = XDataServer1JWTGetSecret
end
object XDataServer1WebSocket: TSparkleWebSocketMiddleware
AllowedOrigins.Strings = (
'*')
end
end
end
......@@ -3,6 +3,7 @@ unit Ws.ServiceImpl;
interface
uses
Common.Logging,
System.SysUtils,
XData.Server.Module,
XData.Service.Common,
......@@ -37,6 +38,8 @@ var
JSONObject: TJSONObject;
MsgStr: string;
begin
Logger.Log(1, 'websocket begin-------');
// Check if the client sent an websocket request, if yes the IWebSocketUpgrader interface will be available.
Upgrader := THttpServerContext.Current.Item<IWebSocketUpgrader>;
if Upgrader = nil then
......@@ -44,10 +47,12 @@ begin
TXDataOperationContext.Current.Handler.SetStatusCode(400);
Exit;
end;
Logger.Log(1, 'websocket upgrading-------');
// Upgrade to websocket
WebSocket := Upgrader.Upgrade;
Logger.Log(1, 'websocket upgraded-------');
// Send a message to client every 2 seconds
Timer := TSparkleTimer.Create(
procedure(Value: TObject)
......@@ -65,12 +70,12 @@ begin
Msg := WebSocket.Receive;
case Msg.MessageType of
TWebSocketMessageType.Text:
Logger.Log(1, 'Web Socket Message: ' + MsgStr);
//TODO: HERE we need to create a map to store connections for later
// and implement protocol to communicate
// store websocket obj, handle another layer of compression/encryption,
// probably store the websocket connection in a map with device id or some other uuid
self.ProcessJsonMessage(MsgStr);
//self.ProcessJsonMessage(MsgStr);
//TWebSocketMessageType.Close:
// WebSocket.SendClose(WebSocketStatusCodes.NormalClosure);
end;
......@@ -94,10 +99,10 @@ begin
for request in MsgDTO.Request do
begin
// Process each Request object
Writeln('Action: ' + request.RequestId);
Logger.Log(1, 'Action: ' + request.RequestId);
if request.RequestId = 'doLogin' then
begin
Writeln('Action: ' + request.RequestId);
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
......
[Settings]
LogFileNum=652
LogFileNum=677
webClientVersion=0.1.0
object DataModule1: TDataModule1
object dmWebsocket: TdmWebsocket
Height = 480
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
Top = 130
end
......
......@@ -3,19 +3,29 @@ unit Module.Websocket;
interface
uses
System.SysUtils, System.Classes, WEBLib.WebSocketClient;
System.SysUtils, System.Classes, WEBLib.WebSocketClient, Web, WEBLib.Controls, WEBLib.Modules;
type
TDataModule1 = class(TDataModule)
WebSocketClient1: TWebSocketClient;
TdmWebsocket = class(TWebDataModule)
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 declarations }
EMiMobileWebSocketClient: TWebSocketClient;
procedure DataModuleCreate(Sender: TObject);
end;
var
DataModule1: TDataModule1;
dmWebsocket: TdmWebsocket;
implementation
......@@ -23,4 +33,37 @@ implementation
{$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.
......@@ -6,7 +6,8 @@ uses
System.SysUtils, System.Classes, JS, Web, WEBLib.Graphics, WEBLib.Controls,
WEBLib.Forms, WEBLib.Dialogs, WEBLib.ExtCtrls, Vcl.Controls, Vcl.StdCtrls,
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
TFViewMain = class(TWebForm)
......@@ -48,6 +49,7 @@ type
FComplaintsForm: TFViewComplaints;
FDetailsForm: TWebForm;
FLogoutProc: TLogoutProc;
//WebSocketModule: Module.Websocket;
[async] procedure RefreshBadgesAsync;
procedure ShowUnitDetails(UnitId: string);
procedure SetHeaderTitle(const title: string);
......@@ -137,6 +139,9 @@ begin
SetActivePanel(apMap);
RefreshBadgesAsync;
dmWebsocket := TdmWebsocket.Create(Self);
dmWebsocket.EMiMobileWebSocketClient.Active := True;
end;
......@@ -411,6 +416,7 @@ begin
end;
procedure TFViewMain.tmrGlobalRefreshTimer(Sender: TObject);
begin
Inc(FGlobalRefreshTick);
......
......@@ -24,7 +24,8 @@ uses
View.ComplaintDetails in 'View.ComplaintDetails.pas' {FViewComplaintDetails: TWebForm} {*.html},
View.UnitDetails in 'View.UnitDetails.pas' {FViewUnitDetails: TWebForm} {*.html},
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}
......
......@@ -194,6 +194,11 @@
<FormType>dfm</FormType>
<DesignClass>TWebForm</DesignClass>
</DCCReference>
<DCCReference Include="Module.Websocket.pas">
<Form>dmWebsocket</Form>
<FormType>dfm</FormType>
<DesignClass>TDataModule</DesignClass>
</DCCReference>
<None Include="index.html"/>
<None Include="css\app.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