unit Chilkat.WebSocket;

{
  Pascal wrapper for Chilkat WebSocket.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TWebSocket wraps CkWebSocket via the C bridge layer. }
  TWebSocket = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetIdleTimeoutMs: Integer;
    procedure SetIdleTimeoutMs(AValue: Integer);
    function  GetFrameOpcode: string;
    function  GetFrameDataLen: Integer;
    function  GetFinalFrame: Boolean;
    function  GetIsConnected: Boolean;
    function  GetCloseAutoRespond: Boolean;
    procedure SetCloseAutoRespond(AValue: Boolean);
    function  GetPingAutoRespond: Boolean;
    procedure SetPingAutoRespond(AValue: Boolean);
    function  GetNeedSendPong: Boolean;
    function  GetCloseReceived: Boolean;
    function  GetCloseStatusCode: Integer;
    function  GetCloseReason: string;
    function  GetPongAutoConsume: Boolean;
    procedure SetPongAutoConsume(AValue: Boolean);
    function  GetPongConsumed: Boolean;
    function  GetReadFrameFailReason: Integer;
    function  GetFrameOpcodeInt: Integer;
    function  GetUncommonOptions: string;
    function  GetHeartbeatMs: Integer;
    procedure SetHeartbeatMs(AValue: Integer);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property IdleTimeoutMs: Integer read GetIdleTimeoutMs write SetIdleTimeoutMs;
    property FrameOpcode: string read GetFrameOpcode;
    property FrameDataLen: Integer read GetFrameDataLen;
    property FinalFrame: Boolean read GetFinalFrame;
    property IsConnected: Boolean read GetIsConnected;
    property CloseAutoRespond: Boolean read GetCloseAutoRespond write SetCloseAutoRespond;
    property PingAutoRespond: Boolean read GetPingAutoRespond write SetPingAutoRespond;
    property NeedSendPong: Boolean read GetNeedSendPong;
    property CloseReceived: Boolean read GetCloseReceived;
    property CloseStatusCode: Integer read GetCloseStatusCode;
    property CloseReason: string read GetCloseReason;
    property PongAutoConsume: Boolean read GetPongAutoConsume write SetPongAutoConsume;
    property PongConsumed: Boolean read GetPongConsumed;
    property ReadFrameFailReason: Integer read GetReadFrameFailReason;
    property FrameOpcodeInt: Integer read GetFrameOpcodeInt;
    property UncommonOptions: string read GetUncommonOptions;
    property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  UseConnection(connection: TChilkatBase): Boolean;
    function  AddClientHeaders: Boolean;
    function  ValidateServerHandshake: Boolean;
    function  SendFrame(const stringToSend: string; finalFrame: Boolean): Boolean;
    function  ReadFrame: Boolean;
    function  GetFrameData: string;
    function  GetFrameDataBd(binData: TChilkatBase): Boolean;
    function  GetFrameDataSb(sb: TChilkatBase): Boolean;
    function  SendFrameSb(sbToSend: TChilkatBase; finalFrame: Boolean): Boolean;
    function  SendFrameBd(bdToSend: TChilkatBase; finalFrame: Boolean): Boolean;
    function  PollDataAvailable: Boolean;
    function  SendPing(const pingData: string): Boolean;
    function  SendPong: Boolean;
    function  SendClose(includeStatus: Boolean; statusCode: Integer; const reason: string): Boolean;
    function  CloseConnection: Boolean;
    function  ShareConnection(ws: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkWebSocket_Create  = function(): Pointer; cdecl;
  TCkWebSocket_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkWebSocket_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkWebSocket_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkWebSocket_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkWebSocket_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkWebSocket_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkWebSocket_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkWebSocket_get_IdleTimeoutMs = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_put_IdleTimeoutMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkWebSocket_get_FrameOpcode = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_FrameDataLen = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_get_FinalFrame = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_get_IsConnected = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_get_CloseAutoRespond = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_put_CloseAutoRespond = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkWebSocket_get_PingAutoRespond = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_put_PingAutoRespond = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkWebSocket_get_NeedSendPong = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_get_CloseReceived = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_get_CloseStatusCode = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_get_CloseReason = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_PongAutoConsume = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_put_PongAutoConsume = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkWebSocket_get_PongConsumed = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_get_ReadFrameFailReason = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_get_FrameOpcodeInt = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkWebSocket_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkWebSocket_UseConnection = function(handle: Pointer; connection: Pointer): LongBool; cdecl;
  TCkWebSocket_AddClientHeaders = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_ValidateServerHandshake = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_SendFrame = function(handle: Pointer; stringToSend: PAnsiChar; finalFrame: LongBool): LongBool; cdecl;
  TCkWebSocket_ReadFrame = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_GetFrameData = function(handle: Pointer): PAnsiChar; cdecl;
  TCkWebSocket_GetFrameDataBd = function(handle: Pointer; binData: Pointer): LongBool; cdecl;
  TCkWebSocket_GetFrameDataSb = function(handle: Pointer; sb: Pointer): LongBool; cdecl;
  TCkWebSocket_SendFrameSb = function(handle: Pointer; sbToSend: Pointer; finalFrame: LongBool): LongBool; cdecl;
  TCkWebSocket_SendFrameBd = function(handle: Pointer; bdToSend: Pointer; finalFrame: LongBool): LongBool; cdecl;
  TCkWebSocket_PollDataAvailable = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_SendPing = function(handle: Pointer; pingData: PAnsiChar): LongBool; cdecl;
  TCkWebSocket_SendPong = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_SendClose = function(handle: Pointer; includeStatus: LongBool; statusCode: Integer; reason: PAnsiChar): LongBool; cdecl;
  TCkWebSocket_CloseConnection = function(handle: Pointer): LongBool; cdecl;
  TCkWebSocket_ShareConnection = function(handle: Pointer; ws: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkWebSocket_Create:  TCkWebSocket_Create  = nil;
  CkWebSocket_Dispose: TCkWebSocket_Dispose = nil;
  CkWebSocket_SetAbortCheckCallback:   TCkWebSocket_SetAbortCheckCallback   = nil;
  CkWebSocket_SetPercentDoneCallback:  TCkWebSocket_SetPercentDoneCallback  = nil;
  CkWebSocket_SetProgressInfoCallback: TCkWebSocket_SetProgressInfoCallback = nil;
  CkWebSocket_get_LastErrorHtml: TCkWebSocket_get_LastErrorHtml = nil;
  CkWebSocket_get_LastErrorText: TCkWebSocket_get_LastErrorText = nil;
  CkWebSocket_get_LastErrorXml: TCkWebSocket_get_LastErrorXml = nil;
  CkWebSocket_get_Version: TCkWebSocket_get_Version = nil;
  CkWebSocket_get_DebugLogFilePath: TCkWebSocket_get_DebugLogFilePath = nil;
  CkWebSocket_put_DebugLogFilePath: TCkWebSocket_put_DebugLogFilePath = nil;
  CkWebSocket_get_VerboseLogging: TCkWebSocket_get_VerboseLogging = nil;
  CkWebSocket_put_VerboseLogging: TCkWebSocket_put_VerboseLogging = nil;
  CkWebSocket_get_LastMethodSuccess: TCkWebSocket_get_LastMethodSuccess = nil;
  CkWebSocket_put_LastMethodSuccess: TCkWebSocket_put_LastMethodSuccess = nil;
  CkWebSocket_get_IdleTimeoutMs: TCkWebSocket_get_IdleTimeoutMs = nil;
  CkWebSocket_put_IdleTimeoutMs: TCkWebSocket_put_IdleTimeoutMs = nil;
  CkWebSocket_get_FrameOpcode: TCkWebSocket_get_FrameOpcode = nil;
  CkWebSocket_get_FrameDataLen: TCkWebSocket_get_FrameDataLen = nil;
  CkWebSocket_get_FinalFrame: TCkWebSocket_get_FinalFrame = nil;
  CkWebSocket_get_IsConnected: TCkWebSocket_get_IsConnected = nil;
  CkWebSocket_get_CloseAutoRespond: TCkWebSocket_get_CloseAutoRespond = nil;
  CkWebSocket_put_CloseAutoRespond: TCkWebSocket_put_CloseAutoRespond = nil;
  CkWebSocket_get_PingAutoRespond: TCkWebSocket_get_PingAutoRespond = nil;
  CkWebSocket_put_PingAutoRespond: TCkWebSocket_put_PingAutoRespond = nil;
  CkWebSocket_get_NeedSendPong: TCkWebSocket_get_NeedSendPong = nil;
  CkWebSocket_get_CloseReceived: TCkWebSocket_get_CloseReceived = nil;
  CkWebSocket_get_CloseStatusCode: TCkWebSocket_get_CloseStatusCode = nil;
  CkWebSocket_get_CloseReason: TCkWebSocket_get_CloseReason = nil;
  CkWebSocket_get_PongAutoConsume: TCkWebSocket_get_PongAutoConsume = nil;
  CkWebSocket_put_PongAutoConsume: TCkWebSocket_put_PongAutoConsume = nil;
  CkWebSocket_get_PongConsumed: TCkWebSocket_get_PongConsumed = nil;
  CkWebSocket_get_ReadFrameFailReason: TCkWebSocket_get_ReadFrameFailReason = nil;
  CkWebSocket_get_FrameOpcodeInt: TCkWebSocket_get_FrameOpcodeInt = nil;
  CkWebSocket_get_UncommonOptions: TCkWebSocket_get_UncommonOptions = nil;
  CkWebSocket_get_HeartbeatMs: TCkWebSocket_get_HeartbeatMs = nil;
  CkWebSocket_put_HeartbeatMs: TCkWebSocket_put_HeartbeatMs = nil;
  CkWebSocket_UseConnection: TCkWebSocket_UseConnection = nil;
  CkWebSocket_AddClientHeaders: TCkWebSocket_AddClientHeaders = nil;
  CkWebSocket_ValidateServerHandshake: TCkWebSocket_ValidateServerHandshake = nil;
  CkWebSocket_SendFrame: TCkWebSocket_SendFrame = nil;
  CkWebSocket_ReadFrame: TCkWebSocket_ReadFrame = nil;
  CkWebSocket_GetFrameData: TCkWebSocket_GetFrameData = nil;
  CkWebSocket_GetFrameDataBd: TCkWebSocket_GetFrameDataBd = nil;
  CkWebSocket_GetFrameDataSb: TCkWebSocket_GetFrameDataSb = nil;
  CkWebSocket_SendFrameSb: TCkWebSocket_SendFrameSb = nil;
  CkWebSocket_SendFrameBd: TCkWebSocket_SendFrameBd = nil;
  CkWebSocket_PollDataAvailable: TCkWebSocket_PollDataAvailable = nil;
  CkWebSocket_SendPing: TCkWebSocket_SendPing = nil;
  CkWebSocket_SendPong: TCkWebSocket_SendPong = nil;
  CkWebSocket_SendClose: TCkWebSocket_SendClose = nil;
  CkWebSocket_CloseConnection: TCkWebSocket_CloseConnection = nil;
  CkWebSocket_ShareConnection: TCkWebSocket_ShareConnection = nil;

constructor TWebSocket.Create;
begin
  inherited Create;
  FHandle := CkWebSocket_Create();
end;

destructor TWebSocket.Destroy;
begin
  if FHandle <> nil then
    CkWebSocket_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TWebSocket_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TWebSocket;
begin
  Result := 0;
  obj := TWebSocket(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TWebSocket_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TWebSocket;
begin
  Result := 0;
  obj := TWebSocket(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TWebSocket_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TWebSocket;
begin
  obj := TWebSocket(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TWebSocket.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkWebSocket_SetAbortCheckCallback(FHandle, @TWebSocket_AbortCheckThunk, Self)
  else
    CkWebSocket_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TWebSocket.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkWebSocket_SetPercentDoneCallback(FHandle, @TWebSocket_PercentDoneThunk, Self)
  else
    CkWebSocket_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TWebSocket.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkWebSocket_SetProgressInfoCallback(FHandle, @TWebSocket_ProgressInfoThunk, Self)
  else
    CkWebSocket_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TWebSocket.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkWebSocket_get_LastErrorHtml(FHandle));
end;

function TWebSocket.GetLastErrorText: string;
begin
  Result := CkToStr(CkWebSocket_get_LastErrorText(FHandle));
end;

function TWebSocket.GetLastErrorXml: string;
begin
  Result := CkToStr(CkWebSocket_get_LastErrorXml(FHandle));
end;

function TWebSocket.GetVersion: string;
begin
  Result := CkToStr(CkWebSocket_get_Version(FHandle));
end;

function TWebSocket.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkWebSocket_get_DebugLogFilePath(FHandle));
end;

procedure TWebSocket.SetDebugLogFilePath(AValue: string);
begin
  CkWebSocket_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TWebSocket.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkWebSocket_get_VerboseLogging(FHandle));
end;

procedure TWebSocket.SetVerboseLogging(AValue: Boolean);
begin
  CkWebSocket_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TWebSocket.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkWebSocket_get_LastMethodSuccess(FHandle));
end;

procedure TWebSocket.SetLastMethodSuccess(AValue: Boolean);
begin
  CkWebSocket_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TWebSocket.GetIdleTimeoutMs: Integer;
begin
  Result := CkWebSocket_get_IdleTimeoutMs(FHandle);
end;

procedure TWebSocket.SetIdleTimeoutMs(AValue: Integer);
begin
  CkWebSocket_put_IdleTimeoutMs(FHandle, AValue);
end;

function TWebSocket.GetFrameOpcode: string;
begin
  Result := CkToStr(CkWebSocket_get_FrameOpcode(FHandle));
end;

function TWebSocket.GetFrameDataLen: Integer;
begin
  Result := CkWebSocket_get_FrameDataLen(FHandle);
end;

function TWebSocket.GetFinalFrame: Boolean;
begin
  Result := Boolean(CkWebSocket_get_FinalFrame(FHandle));
end;

function TWebSocket.GetIsConnected: Boolean;
begin
  Result := Boolean(CkWebSocket_get_IsConnected(FHandle));
end;

function TWebSocket.GetCloseAutoRespond: Boolean;
begin
  Result := Boolean(CkWebSocket_get_CloseAutoRespond(FHandle));
end;

procedure TWebSocket.SetCloseAutoRespond(AValue: Boolean);
begin
  CkWebSocket_put_CloseAutoRespond(FHandle, LongBool(AValue));
end;

function TWebSocket.GetPingAutoRespond: Boolean;
begin
  Result := Boolean(CkWebSocket_get_PingAutoRespond(FHandle));
end;

procedure TWebSocket.SetPingAutoRespond(AValue: Boolean);
begin
  CkWebSocket_put_PingAutoRespond(FHandle, LongBool(AValue));
end;

function TWebSocket.GetNeedSendPong: Boolean;
begin
  Result := Boolean(CkWebSocket_get_NeedSendPong(FHandle));
end;

function TWebSocket.GetCloseReceived: Boolean;
begin
  Result := Boolean(CkWebSocket_get_CloseReceived(FHandle));
end;

function TWebSocket.GetCloseStatusCode: Integer;
begin
  Result := CkWebSocket_get_CloseStatusCode(FHandle);
end;

function TWebSocket.GetCloseReason: string;
begin
  Result := CkToStr(CkWebSocket_get_CloseReason(FHandle));
end;

function TWebSocket.GetPongAutoConsume: Boolean;
begin
  Result := Boolean(CkWebSocket_get_PongAutoConsume(FHandle));
end;

procedure TWebSocket.SetPongAutoConsume(AValue: Boolean);
begin
  CkWebSocket_put_PongAutoConsume(FHandle, LongBool(AValue));
end;

function TWebSocket.GetPongConsumed: Boolean;
begin
  Result := Boolean(CkWebSocket_get_PongConsumed(FHandle));
end;

function TWebSocket.GetReadFrameFailReason: Integer;
begin
  Result := CkWebSocket_get_ReadFrameFailReason(FHandle);
end;

function TWebSocket.GetFrameOpcodeInt: Integer;
begin
  Result := CkWebSocket_get_FrameOpcodeInt(FHandle);
end;

function TWebSocket.GetUncommonOptions: string;
begin
  Result := CkToStr(CkWebSocket_get_UncommonOptions(FHandle));
end;

function TWebSocket.GetHeartbeatMs: Integer;
begin
  Result := CkWebSocket_get_HeartbeatMs(FHandle);
end;

procedure TWebSocket.SetHeartbeatMs(AValue: Integer);
begin
  CkWebSocket_put_HeartbeatMs(FHandle, AValue);
end;

function TWebSocket.UseConnection(connection: TChilkatBase): Boolean;
begin
  Result := Boolean(CkWebSocket_UseConnection(FHandle, connection.Handle));
end;

function TWebSocket.AddClientHeaders: Boolean;
begin
  Result := Boolean(CkWebSocket_AddClientHeaders(FHandle));
end;

function TWebSocket.ValidateServerHandshake: Boolean;
begin
  Result := Boolean(CkWebSocket_ValidateServerHandshake(FHandle));
end;

function TWebSocket.SendFrame(const stringToSend: string; finalFrame: Boolean): Boolean;
begin
  Result := Boolean(CkWebSocket_SendFrame(FHandle, PAnsiChar(StrToCk(stringToSend)), LongBool(finalFrame)));
end;

function TWebSocket.ReadFrame: Boolean;
begin
  Result := Boolean(CkWebSocket_ReadFrame(FHandle));
end;

function TWebSocket.GetFrameData: string;
begin
  Result := CkToStr(CkWebSocket_GetFrameData(FHandle));
end;

function TWebSocket.GetFrameDataBd(binData: TChilkatBase): Boolean;
begin
  Result := Boolean(CkWebSocket_GetFrameDataBd(FHandle, binData.Handle));
end;

function TWebSocket.GetFrameDataSb(sb: TChilkatBase): Boolean;
begin
  Result := Boolean(CkWebSocket_GetFrameDataSb(FHandle, sb.Handle));
end;

function TWebSocket.SendFrameSb(sbToSend: TChilkatBase; finalFrame: Boolean): Boolean;
begin
  Result := Boolean(CkWebSocket_SendFrameSb(FHandle, sbToSend.Handle, LongBool(finalFrame)));
end;

function TWebSocket.SendFrameBd(bdToSend: TChilkatBase; finalFrame: Boolean): Boolean;
begin
  Result := Boolean(CkWebSocket_SendFrameBd(FHandle, bdToSend.Handle, LongBool(finalFrame)));
end;

function TWebSocket.PollDataAvailable: Boolean;
begin
  Result := Boolean(CkWebSocket_PollDataAvailable(FHandle));
end;

function TWebSocket.SendPing(const pingData: string): Boolean;
begin
  Result := Boolean(CkWebSocket_SendPing(FHandle, PAnsiChar(StrToCk(pingData))));
end;

function TWebSocket.SendPong: Boolean;
begin
  Result := Boolean(CkWebSocket_SendPong(FHandle));
end;

function TWebSocket.SendClose(includeStatus: Boolean; statusCode: Integer; const reason: string): Boolean;
begin
  Result := Boolean(CkWebSocket_SendClose(FHandle, LongBool(includeStatus), statusCode, PAnsiChar(StrToCk(reason))));
end;

function TWebSocket.CloseConnection: Boolean;
begin
  Result := Boolean(CkWebSocket_CloseConnection(FHandle));
end;

function TWebSocket.ShareConnection(ws: TChilkatBase): Boolean;
begin
  Result := Boolean(CkWebSocket_ShareConnection(FHandle, ws.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkWebSocket_Create,  'CkWebSocket_Create');
  Chilkat_GetProcedureAddress(CkWebSocket_Dispose, 'CkWebSocket_Dispose');
  Chilkat_GetProcedureAddress(CkWebSocket_SetAbortCheckCallback, 'CkWebSocket_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkWebSocket_SetPercentDoneCallback, 'CkWebSocket_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkWebSocket_SetProgressInfoCallback, 'CkWebSocket_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkWebSocket_get_LastErrorHtml, 'CkWebSocket_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkWebSocket_get_LastErrorText, 'CkWebSocket_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkWebSocket_get_LastErrorXml, 'CkWebSocket_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkWebSocket_get_Version, 'CkWebSocket_get_Version');
  Chilkat_GetProcedureAddress(CkWebSocket_get_DebugLogFilePath, 'CkWebSocket_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkWebSocket_put_DebugLogFilePath, 'CkWebSocket_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkWebSocket_get_VerboseLogging, 'CkWebSocket_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkWebSocket_put_VerboseLogging, 'CkWebSocket_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkWebSocket_get_LastMethodSuccess, 'CkWebSocket_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkWebSocket_put_LastMethodSuccess, 'CkWebSocket_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkWebSocket_get_IdleTimeoutMs, 'CkWebSocket_get_IdleTimeoutMs');
  Chilkat_GetProcedureAddress(CkWebSocket_put_IdleTimeoutMs, 'CkWebSocket_put_IdleTimeoutMs');
  Chilkat_GetProcedureAddress(CkWebSocket_get_FrameOpcode, 'CkWebSocket_get_FrameOpcode');
  Chilkat_GetProcedureAddress(CkWebSocket_get_FrameDataLen, 'CkWebSocket_get_FrameDataLen');
  Chilkat_GetProcedureAddress(CkWebSocket_get_FinalFrame, 'CkWebSocket_get_FinalFrame');
  Chilkat_GetProcedureAddress(CkWebSocket_get_IsConnected, 'CkWebSocket_get_IsConnected');
  Chilkat_GetProcedureAddress(CkWebSocket_get_CloseAutoRespond, 'CkWebSocket_get_CloseAutoRespond');
  Chilkat_GetProcedureAddress(CkWebSocket_put_CloseAutoRespond, 'CkWebSocket_put_CloseAutoRespond');
  Chilkat_GetProcedureAddress(CkWebSocket_get_PingAutoRespond, 'CkWebSocket_get_PingAutoRespond');
  Chilkat_GetProcedureAddress(CkWebSocket_put_PingAutoRespond, 'CkWebSocket_put_PingAutoRespond');
  Chilkat_GetProcedureAddress(CkWebSocket_get_NeedSendPong, 'CkWebSocket_get_NeedSendPong');
  Chilkat_GetProcedureAddress(CkWebSocket_get_CloseReceived, 'CkWebSocket_get_CloseReceived');
  Chilkat_GetProcedureAddress(CkWebSocket_get_CloseStatusCode, 'CkWebSocket_get_CloseStatusCode');
  Chilkat_GetProcedureAddress(CkWebSocket_get_CloseReason, 'CkWebSocket_get_CloseReason');
  Chilkat_GetProcedureAddress(CkWebSocket_get_PongAutoConsume, 'CkWebSocket_get_PongAutoConsume');
  Chilkat_GetProcedureAddress(CkWebSocket_put_PongAutoConsume, 'CkWebSocket_put_PongAutoConsume');
  Chilkat_GetProcedureAddress(CkWebSocket_get_PongConsumed, 'CkWebSocket_get_PongConsumed');
  Chilkat_GetProcedureAddress(CkWebSocket_get_ReadFrameFailReason, 'CkWebSocket_get_ReadFrameFailReason');
  Chilkat_GetProcedureAddress(CkWebSocket_get_FrameOpcodeInt, 'CkWebSocket_get_FrameOpcodeInt');
  Chilkat_GetProcedureAddress(CkWebSocket_get_UncommonOptions, 'CkWebSocket_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkWebSocket_get_HeartbeatMs, 'CkWebSocket_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkWebSocket_put_HeartbeatMs, 'CkWebSocket_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkWebSocket_UseConnection, 'CkWebSocket_UseConnection');
  Chilkat_GetProcedureAddress(CkWebSocket_AddClientHeaders, 'CkWebSocket_AddClientHeaders');
  Chilkat_GetProcedureAddress(CkWebSocket_ValidateServerHandshake, 'CkWebSocket_ValidateServerHandshake');
  Chilkat_GetProcedureAddress(CkWebSocket_SendFrame, 'CkWebSocket_SendFrame');
  Chilkat_GetProcedureAddress(CkWebSocket_ReadFrame, 'CkWebSocket_ReadFrame');
  Chilkat_GetProcedureAddress(CkWebSocket_GetFrameData, 'CkWebSocket_GetFrameData');
  Chilkat_GetProcedureAddress(CkWebSocket_GetFrameDataBd, 'CkWebSocket_GetFrameDataBd');
  Chilkat_GetProcedureAddress(CkWebSocket_GetFrameDataSb, 'CkWebSocket_GetFrameDataSb');
  Chilkat_GetProcedureAddress(CkWebSocket_SendFrameSb, 'CkWebSocket_SendFrameSb');
  Chilkat_GetProcedureAddress(CkWebSocket_SendFrameBd, 'CkWebSocket_SendFrameBd');
  Chilkat_GetProcedureAddress(CkWebSocket_PollDataAvailable, 'CkWebSocket_PollDataAvailable');
  Chilkat_GetProcedureAddress(CkWebSocket_SendPing, 'CkWebSocket_SendPing');
  Chilkat_GetProcedureAddress(CkWebSocket_SendPong, 'CkWebSocket_SendPong');
  Chilkat_GetProcedureAddress(CkWebSocket_SendClose, 'CkWebSocket_SendClose');
  Chilkat_GetProcedureAddress(CkWebSocket_CloseConnection, 'CkWebSocket_CloseConnection');
  Chilkat_GetProcedureAddress(CkWebSocket_ShareConnection, 'CkWebSocket_ShareConnection');

end.
