87 lines
2.7 KiB
ObjectPascal
87 lines
2.7 KiB
ObjectPascal
unit IdServerWebsocketContext;
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes,
|
|
IdCustomTCPServer, IdIOHandlerWebsocket,
|
|
IdServerBaseHandling, IdServerSocketIOHandling, IdContext, IdIOHandlerStack;
|
|
|
|
type
|
|
TIdServerWSContext = class;
|
|
|
|
TWebsocketChannelRequest = procedure(const AContext: TIdServerWSContext; aType: TWSDataType; const strmRequest, strmResponse: TMemoryStream) of object;
|
|
|
|
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;
|
|
FOnCustomChannelExecute: TWebsocketChannelRequest;
|
|
FSocketIO: TIdServerSocketIOHandling;
|
|
FOnDestroy: TIdContextEvent;
|
|
public
|
|
function IOHandler: TIdIOHandlerStack;
|
|
function WebsocketImpl: TWebsocketImplementationProxy;
|
|
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 OnCustomChannelExecute: TWebsocketChannelRequest read FOnCustomChannelExecute write FOnCustomChannelExecute;
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
StrUtils;
|
|
|
|
{ TIdServerWSContext }
|
|
|
|
destructor TIdServerWSContext.Destroy;
|
|
begin
|
|
if Assigned(OnDestroy) then
|
|
OnDestroy(Self);
|
|
inherited;
|
|
end;
|
|
|
|
function TIdServerWSContext.IOHandler: TIdIOHandlerStack;
|
|
begin
|
|
Result := Self.Connection.IOHandler as TIdIOHandlerStack;
|
|
end;
|
|
|
|
function TIdServerWSContext.IsSocketIO: Boolean;
|
|
begin
|
|
//FDocument = '/socket.io/1/websocket/13412152'
|
|
Result := StartsText('/socket.io/1/websocket/', FPath);
|
|
end;
|
|
|
|
function TIdServerWSContext.WebsocketImpl: TWebsocketImplementationProxy;
|
|
begin
|
|
Result := (IOHandler as IWebsocketFunctions).WebsocketImpl;
|
|
end;
|
|
|
|
end.
|