DelphiWebsockets/IdServerWebsocketContext.pas

87 lines
2.8 KiB
ObjectPascal
Raw Normal View History

2013-11-11 21:14:42 +01:00
unit IdServerWebsocketContext;
interface
{$I wsdefines.pas}
2013-11-11 21:14:42 +01:00
uses
Classes, strUtils
, IdContext
, IdCustomTCPServer
, IdCustomHTTPServer
//
, IdIOHandlerWebsocket
, IdServerBaseHandling
, IdServerSocketIOHandling
;
2013-11-11 21:14:42 +01:00
type
TIdServerWSContext = class;
TWebSocketUpgradeEvent = procedure(const AContext: TIdServerWSContext; ARequestInfo: TIdHTTPRequestInfo; var Accept:boolean) of object;
TWebsocketChannelRequest = procedure(const AContext: TIdServerWSContext; var aType:TWSDataType; const strmRequest, strmResponse: TMemoryStream) of object;
2013-11-11 21:14:42 +01:00
TIdServerWSContext = class(TIdServerContext)
private
FWebSocketKey: string;
FWebSocketVersion: Integer;
FPath: string;
FWebSocketProtocol: string;
FResourceName: string;
FOrigin: string;
FQuery: string;
FHost: string;
FWebSocketExtensions: string;
FCookie: string;
//FSocketIOPingSend: Boolean;
fOnWebSocketUpgrade: TWebSocketUpgradeEvent;
2013-11-11 21:14:42 +01:00
FOnCustomChannelExecute: TWebsocketChannelRequest;
FSocketIO: TIdServerSocketIOHandling;
FOnDestroy: TIdContextEvent;
public
function IOHandler: TIdIOHandlerWebsocket;
public
function IsSocketIO: Boolean;
property SocketIO: TIdServerSocketIOHandling read FSocketIO write FSocketIO;
//property SocketIO: TIdServerBaseHandling read FSocketIO write FSocketIO;
property OnDestroy: TIdContextEvent read FOnDestroy write FOnDestroy;
public
destructor Destroy; override;
property Path : string read FPath write FPath;
property Query : string read FQuery write FQuery;
property ResourceName: string read FResourceName write FResourceName;
property Host : string read FHost write FHost;
property Origin : string read FOrigin write FOrigin;
property Cookie : string read FCookie write FCookie;
property WebSocketKey : string read FWebSocketKey write FWebSocketKey;
property WebSocketProtocol : string read FWebSocketProtocol write FWebSocketProtocol;
property WebSocketVersion : Integer read FWebSocketVersion write FWebSocketVersion;
property WebSocketExtensions: string read FWebSocketExtensions write FWebSocketExtensions;
public
property OnWebSocketUpgrade: TWebsocketUpgradeEvent read FOnWebSocketUpgrade write FOnWebSocketUpgrade;
2013-11-11 21:14:42 +01:00
property OnCustomChannelExecute: TWebsocketChannelRequest read FOnCustomChannelExecute write FOnCustomChannelExecute;
end;
implementation
{ TIdServerWSContext }
destructor TIdServerWSContext.Destroy;
begin
if Assigned(OnDestroy) then
OnDestroy(Self);
inherited;
end;
function TIdServerWSContext.IOHandler: TIdIOHandlerWebsocket;
begin
Result := Self.Connection.IOHandler as TIdIOHandlerWebsocket;
end;
function TIdServerWSContext.IsSocketIO: Boolean;
begin
//FDocument = '/socket.io/1/websocket/13412152'
2013-11-18 14:27:13 +01:00
Result := StartsText('/socket.io/1/websocket/', FPath);
2013-11-11 21:14:42 +01:00
end;
end.