How call UFUNCTION (BlueprintImplementableEvent) from JS with EMSCRIPTEN and error: Module.ccall is not function?

I am making a game for HTML5. At a certain moment I call the ad block, before that I put the game on pause. When the player closes the ad block, I need to unpause the game (I use Blueprints). I need to call UFUNCTION (BlueprintImplemetableEvent) from JS, but I didn’t find how.

I use this code in cpp:

#ifdef __EMSCRIPTEN__ 
#include "SDL/SDL.h"
#include "emscripten/emscripten.h"
#include "emscripten/html5.h"
#else
#define EMSCRIPTEN_KEEPALIVE
#endif 

#include "string"
#include "iostream"
#include "sstream"

//'"FString Text" I assign to test in Blueprints

void AChristmasMole4_23CPPGameModeBase::Test()
{


	

	std::string OutboundSendString(TCHAR_TO_UTF8(*Text));




#ifdef __EMSCRIPTEN__ 
	EM_ASM_ARGS({
		var theText = UTF8ToString($0);

		console.log('Hello' + theText);
		}
		
		, OutboundSendString.c_str()
		);
	
	emscripten_run_script("testJS();");


#endif
}


extern "C" void EMSCRIPTEN_KEEPALIVE CallTest(char *str)
	{
	
//I don't know how to call UFUNCTION(BlueprintImplementableEvent) here
//I used (char *str) because I don't know how to use Module.ccall to call a function with no arguments

	}

In [ProjectName] -Shipping.UE4.js file:

function testJS()
 {
    var str = "Hi from JS!";
    var lenUTF8 = Module.lengthBytesUTF8(str) + 1;
    var ptr = Module._malloc(lenUTF8);
    Module.stringToUTF8(str, ptr, lenUTF8);
    Module.ccall('CallTest', 'null', ['string'], [str]);
    Module._free(ptr);
}

When I call the testJS() function, it shows that Module.lengthBytesUTF8 is not a function and Module.ccall too.

I’ve looked at a lot of threads on this topic but couldn’t find an answer to my question.

And my code knowledge is very noob.

I DID IT!!!

I didn’t call Module.ccall, but I was able to do without it.
I created an integer in an HTML file and placed it in the “HEAD”

<script>
        var numTest = 0;
    </script>

When the player presses the START button, the testJS() function is called.

in cpp:

#ifdef __EMSCRIPTEN__ 
	emscripten_run_script("testJS()");
#endif

in HTML:

<script>
function testJS(){
numTest = 1;
}
</script>

Each tick checks to see if numTest has changed to 1.
If numTest=1 then EventUnpause is activated and numTest returns to 0.

in cpp:

#ifdef __EMSCRIPTEN__ 
	int CallUnpause = EM_ASM_INT({
		return numTest;
		});


#else
	int CallUnpause = 0;
#endif



	if (CallUnpause >= 1)
	{
		Unpause();


#ifdef __EMSCRIPTEN__ 
		emscripten_run_script("numTest = 0");
#endif
	};

I don’t really like working with global variables, I would like to have a callback in JavaScript that would trigger events in the drawings, I do it like this

.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"

UCLASS()
class MYPROJECT_API AMyActor : public AActor
{
	GENERATED_BODY()

public:
	AMyActor();

protected:
	virtual void BeginPlay() override;

public:
	virtual void Tick(float DeltaTime) override;

	UFUNCTION(BlueprintImplementableEvent)
	void SetLocation(int32 Value);
};

static int32 Location;

.cpp

#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif

#include "MyActor.h"
#define EXTERN extern "C"

AMyActor::AMyActor()
{
	PrimaryActorTick.bCanEverTick = true;
}

void AMyActor::BeginPlay() { Super::BeginPlay(); }


void AMyActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (Location)
	{
		SetLocation(Location);
		Location = 0;
	}
}

#ifdef __EMSCRIPTEN__
EXTERN	EMSCRIPTEN_KEEPALIVE
#endif
void SetLocation(int32 value) { Location = value; };

.ts

const engineApi = {
    setLocation(value: number) {
        Module['_SetLocation'](value);
    },
};

export default engineApi;

then i can import this api into any file and call an event

To work Module.ccall you need to export ccall function (add it to exported methods array) in Engine\Platforms\HTML5\Source\Programs\UnrealBuildTool\HTML5ToolChain.cs (~473 line):

Result += " -s EXPORTED_RUNTIME_METHODS=\"['stringToAscii', 'ccall']\"";