diff --git a/cef/src/index.ts b/cef/src/index.ts index 10b2ef5..9e56774 100644 --- a/cef/src/index.ts +++ b/cef/src/index.ts @@ -21,7 +21,9 @@ class Cef { eventName: EventName, callback: RageFW_CefCallback, ): void { - rpc.register(eventName, callback) + if ('mp' in window) { + rpc.register(eventName, callback) + } } public trigger( @@ -30,7 +32,13 @@ class Cef { ? [RageFW_CefArguments] : [] ): Promise> { - return rpc.call(eventName, args) + if ('mp' in window) { + return rpc.call(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } public triggerServer( @@ -39,7 +47,13 @@ class Cef { ? [RageFW_ServerArguments] : [] ): Promise> { - return rpc.callServer(eventName, args) + if ('mp' in window) { + return rpc.callServer(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } public triggerClient( @@ -48,7 +62,13 @@ class Cef { ? [RageFW_ClientArguments] : [] ): Promise> { - return rpc.callClient(eventName, args) + if ('mp' in window) { + return rpc.callClient(eventName, args) + } + + return Promise.reject( + 'RageFW was started in window which not contain global variable MP!', + ) } }