Jump to content

WebWorker and InitAnimationFrameShim


Recommended Posts

Hi,

I'm trying to setup a webworker to send a file to a RO server.
But I've got this error:

Uncaught ReferenceError: window is not defined
=> function InitAnimationFrameShim() {

 

I thought about SmartCL.WebWorker, but it is working without error in the demo projects.
Also other commands from the same server are working just fine in the application...

Here is the code:

uses System, WorkerThreadUploader;
{$IFDEF SMART_INTERNAL_HANDLE_EXCEPTIONS}
try
{$ENDIF}
  var Thread := TThread.Create;
{$IFDEF SMART_INTERNAL_HANDLE_EXCEPTIONS}
except
  on e: Exception do
    asm console.error(e) end;
end;

// ------------------------------------------------------------------------

unit WorkerThreadUploader;
interface
uses
  SmartCL.WebWorker, RemObjectsSDK, CheckLibrary_intf, Commons;
type
  TThread = class(TWebWorkerThread)
  private
    FROServeur : TCheckService;
    FROChannel : TROHTTPClientChannel;
    FROMessage : TROJSONMessage;
    FMyFile  : TMyFile;
    procedure InitializeRemobjects;
  public
    constructor Create;
    procedure ReceiveMessage(data: Variant); override;
  end;
  TMyFile = class (JObject)
    name    : string;
    content : variant;
  end;
const
  SERVER_ADDRESS = 'http://localhost:8823/json';

implementation

constructor TThread.Create;
begin
  inherited Create;
  InitializeRemobjects();
end;

procedure TThread.InitializeRemobjects;
begin
  FROChannel := TROHTTPClientChannel.Create(SERVER_ADDRESS);
  FROMessage := TROJSONMessage.Create();
  FROServeur := TCheckService.Create(FROChannel, FROMessage);
end;

procedure TThread.ReceiveMessage(Data: Variant);
begin
  FMyFile := TMyFile(Data);
  FROServeur.AddPhoto(
    FMyFile.name,
    FMyFile.content,
    procedure (aResult: AnsiString)
    begin
      PostMessage(Format('File sent: %s ', [FMyFile.name]));
    end,
    procedure (aMessage: TROMessage; aError: JError)
    begin
      PostMessage(Format('Send error: %s ', [FMyFile.name]));
    end
    );
end;

end.

 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...