Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions include/IExternalApplicationHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2024 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#ifndef IEXTERNALAPPLICATION_HANDLER_H
#define IEXTERNALAPPLICATION_HANDLER_H

#include <string>
class IExternalApplicationHandler
{
public:
virtual void runExternalApplication(std::string url, uint32_t id) = 0;
};

#endif
4 changes: 4 additions & 0 deletions include/JavaScriptContextBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <IJavaScriptContext.h>
#include <IJavaScriptEngine.h>
#include <ModuleSettings.h>
#include <IExternalApplicationHandler.h>
#include <memory>

//#include <JavaScriptCore/JavaScript.h>

Expand All @@ -57,6 +59,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
virtual void onKeyPress(struct JavaScriptKeyDetails& details);
virtual void onKeyRelease(struct JavaScriptKeyDetails& details);
ModuleSettings getModuleSettings();
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
protected:
virtual void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress) = 0;
virtual bool evaluateScript(const char* script, const char* name, const char *args, bool module=false) = 0;
Expand All @@ -70,6 +73,7 @@ class JavaScriptContextBase:public IJavaScriptContext, public JavaScriptKeyListe
bool mEmbedWebBridge;
bool mEnableWebSockerServer;
ModuleSettings mModuleSettings;
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
static std::string sModulesPath;
static void populateModulesPath();
};
Expand Down
36 changes: 17 additions & 19 deletions include/NativeJSRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <memory>
#include <IJavaScriptEngine.h>
#include <IJavaScriptContext.h>
#include <IExternalApplicationHandler.h>
#include <ModuleSettings.h>
#include <condition_variable>
#include <list>
Expand Down Expand Up @@ -76,19 +77,19 @@ namespace JsRuntime {
IJavaScriptContext* consoleContext = nullptr;
ModuleSettings moduleSettings{};
};

struct ApplicationDetails{
uint32_t id;
std::string url;
};

enum RequestType{
CREATE=0,
RUN,
TERMINATE,
RUNSCRIPT
};

struct ApplicationRequest
{
ApplicationRequest(uint32_t id, RequestType requestType, std::string url="", bool enableHttp=false, bool enableXHR=false, bool enableWebSocket=false, bool enableWebSocketEnhanced=false, bool enableFetch=false, bool enableJSDOM=false, bool enableWindow=false, bool enablePlayer=false): mId(id), mRequestType(requestType), mUrl(url), mEnableHttp(enableHttp), mEnableXHR(enableXHR), mEnableWebSocket(enableWebSocket), mEnableWebSocketEnhanced(enableWebSocketEnhanced), mEnableFetch(enableFetch), mEnableJSDOM(enableJSDOM), mEnableWindow(enableWindow), mEnablePlayer(enablePlayer)
Expand All @@ -105,7 +106,7 @@ namespace JsRuntime {
bool mEnableJSDOM;
bool mEnableWindow;
bool mEnablePlayer;
};
};
struct ApplicationData{
std::string url;
IJavaScriptContext* context;
Expand All @@ -121,19 +122,20 @@ namespace JsRuntime {
void run();
void setEnvForConsoleMode(ModuleSettings& moduleSettings);
bool runApplication(uint32_t id, std::string url);
bool runJavaScript(uint32_t id, std::string code);
uint32_t createApplication(ModuleSettings& moduleSettings) ;
bool runJavaScript(uint32_t id, std::string code);
uint32_t createApplication(ModuleSettings& moduleSettings) ;
bool terminateApplication(uint32_t id);
std::list<ApplicationDetails> getApplications();
private:
bool downloadFile(std::string& url, MemoryStruct& chunk);
std::list<ApplicationDetails> getApplications();
void setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler);
private:
bool downloadFile(std::string& url, MemoryStruct& chunk);
void processDevConsoleRequests();
void runDeveloperConsole(ModuleSettings moduleSettings);
void createApplicationInternal(ApplicationRequest& appRequest);
void runApplicationInternal(ApplicationRequest& appRequest);
void terminateApplicationInternal(ApplicationRequest& appRequest);
void runJavaScriptInternal(ApplicationRequest& appRequest);
uint32_t createApplicationIdentifier();
void runJavaScriptInternal(ApplicationRequest& appRequest);
uint32_t createApplicationIdentifier();
static size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
IJavaScriptEngine* mEngine;
bool mRunning;
Expand All @@ -145,13 +147,9 @@ namespace JsRuntime {
bool mEnableWebSocketServer;
bool mEssosInitialized;
bool mConsoleMode;
std::mutex mUserMutex;
std::mutex mUserMutex;
std::map<uint32_t, ApplicationData> mContextMap;
std::vector<ApplicationRequest> gPendingRequests;
};
std::vector<ApplicationRequest> gPendingRequests;
std::shared_ptr<IExternalApplicationHandler> mExternalApplicationHandler;
};
};





14 changes: 8 additions & 6 deletions include/jsc/JavaScriptContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include "rtScriptJSCPrivate.h"
#include <KeyListener.h>
#include <KeyInput.h>

#include <rtHttpRequest.h>
#include <JavaScriptCore/JavaScript.h>
#ifdef ENABLE_JSRUNTIME_PLAYER
Expand All @@ -58,11 +57,11 @@ struct AAMPJSBindings

extern "C" JS_EXPORT void JSSynchronousGarbageCollectForDebugging(JSContextRef);

struct PerformanceMetrics {
struct PerformanceMetrics {
double createApplicationStartTime=0.0;
double createApplicationEndTime=0.0;
double executionStartTime=0.0;
double executionEndTime=0.0;
double executionEndTime=0.0;
double playbackStartTime=0.0;
};

Expand All @@ -75,12 +74,12 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList

JavaScriptContext(JavaScriptContextFeatures& features, std::string url, IJavaScriptEngine* jsEngine);
virtual ~JavaScriptContext();

rtValue get(const char *name);
rtError add(const char *name, rtValue const& val);
bool has(const char *name);
JSGlobalContextRef getContext() { return mContext; }

virtual void onMetricsData (NetworkMetrics *net) override;
rtMapObject* getNetworkMetricsData() const { return mNetworkMetricsData; }
void dumpNetworkMetricData(NetworkMetrics *metrics, std::string appUrl);
Expand All @@ -91,6 +90,8 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
void setAppdata(uint32_t id, const std::string& url);
double getExecutionDuration() const;

void handleExternalApplication(const std::string& url);

private:
bool evaluateScript(const char *script, const char *name, const char *args = nullptr, bool module = false);
void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress);
Expand All @@ -117,6 +118,7 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
rtRef<rtFunctionCallback> m_readBinaryBinding;
rtRef<rtFunctionCallback> m_setVideoStartTimeBinding;
rtRef<rtFunctionCallback> m_JSRuntimeDownloadMetrics;

rtRef<rtFunctionCallback> m_setExternalAppHandlerBinding;
rtRef<rtFunctionCallback> m_getRandomValuesBinding;
};
#endif
2 changes: 2 additions & 0 deletions include/jsc/JavaScriptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ rtError rtHttpGetBinding(int numArgs, const rtValue* args, rtValue* result, void
rtError rtReadBinaryBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
rtError rtSetVideoStartTimeBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
rtError rtJSRuntimeDownloadMetrics(int numArgs, const rtValue* args, rtValue* result, void* context);
rtError rtSetExternalAppHandlerBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
rtError rtGetRandomValuesBinding(int numArgs, const rtValue* args, rtValue* result, void* context);
JSValueRef requireCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);

#endif /* JAVASCRIPTMISC_H */
16 changes: 11 additions & 5 deletions src/JavaScriptContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
#ifdef ENABLE_ESSOS
#include <EssosInstance.h>
#endif
#include <sys/stat.h>
#include <sys/stat.h>
#include <cstdlib>

std::string JavaScriptContextBase::sThunderJSCode = "";
std::string JavaScriptContextBase::sWebBridgeCode = "";
std::string JavaScriptContextBase::sModulesPath = "";
std::string JavaScriptContextBase::sModulesPath = "";

JavaScriptContextFeatures::JavaScriptContextFeatures(bool embedThunderJS, bool embedWebBridge, bool enableWebSockerServer, ModuleSettings& moduleSettings):mEmbedThunderJS(embedThunderJS), mEmbedWebBridge(embedWebBridge), mEnableWebSockerServer(enableWebSockerServer), mModuleSettings(moduleSettings)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ bool JavaScriptContextBase::runScript(const char *script, bool isModule, std::st
}

std::string JavaScriptContextBase::getUrl()
{
{
return mApplicationUrl;
}

Expand All @@ -146,10 +146,11 @@ void JavaScriptContextBase::onKeyRelease(struct JavaScriptKeyDetails& details)

ModuleSettings JavaScriptContextBase::getModuleSettings()
{
return mModuleSettings;
return mModuleSettings;
}

void JavaScriptContextBase::populateModulesPath(){
void JavaScriptContextBase::populateModulesPath()
{
if(getenv("JSRUNTIME_MODULES_PATH"))
{
std::cout<<"JSRUNTIME_MODULES_PATH variable is set"<<std::endl;
Expand All @@ -164,3 +165,8 @@ void JavaScriptContextBase::populateModulesPath(){
std::cout<<"Modules Path:"<<sModulesPath<<std::endl;
return;
}

void JavaScriptContextBase::setExternalApplicationHandler(std::shared_ptr<IExternalApplicationHandler> handler)
{
mExternalApplicationHandler = handler;
}
Loading
Loading