Skip to content
Closed
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [2.0.6](https://github-personal/rdkcentral/rdkNativeScript/compare/2.0.4...2.0.6)

- RDKEMW-18491 : [rdknativescript] add debugger support similar to webkit [`#134`](https://github-personal/rdkcentral/rdkNativeScript/pull/134)
- RDKEMW-18233: Route console logs to sky-message.log for jsruntime [`#132`](https://github-personal/rdkcentral/rdkNativeScript/pull/132)
- Merge tag '2.0.4' into develop [`1c8a075`](https://github-personal/rdkcentral/rdkNativeScript/commit/1c8a0756f20528740dffe0d2e5baee3d637ae69d)

#### [2.0.4](https://github-personal/rdkcentral/rdkNativeScript/compare/2.0.3...2.0.4)

- RDKEMW-14984: VIPA playback is stopping with 2.0.3 nativescript tag [`#128`](https://github-personal/rdkcentral/rdkNativeScript/pull/128)
Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ option(NATIVEJS_L2_BUILD "NATIVEJS_L2_BUILD" OFF)
option(JSRUNTIME_ENGINE_NAME "JSRUNTIME_ENGINE_NAME" "jsc")
option(ENABLE_JSRUNTIME_ESSOS "ENABLE_JSRUNTIME_ESSOS" OFF)
option(ENABLE_WEBSOCKET_SERVER "ENABLE_WEBSOCKET_SERVER" OFF)
option(ENABLE_REMOTE_INSPECTOR "ENABLE_REMOTE_INSPECTOR" OFF)
option(REMOTE_INSPECTOR_ENABLE "REMOTE_INSPECTOR_ENABLE" OFF)
option(ENABLE_AAMP_JSBINDINGS "ENABLE_AAMP_JSBINDINGS" OFF)
option(ENABLE_AAMP_JSBINDINGS_STATIC "ENABLE_AAMP_JSBINDINGS_STATIC" OFF)
option(ENABLE_AAMP_JSBINDINGS_DYNAMIC "ENABLE_AAMP_JSBINDINGS_DYNAMIC" OFF)
Expand Down Expand Up @@ -79,9 +79,9 @@ if (ENABLE_JSRUNTIME_ESSOS)
add_definitions("-DENABLE_ESSOS")
endif (ENABLE_JSRUNTIME_ESSOS)

if ( ENABLE_REMOTE_INSPECTOR )
add_definitions("-DENABLE_REMOTE_INSPECTOR")
endif ( ENABLE_REMOTE_INSPECTOR )
if ( REMOTE_INSPECTOR_ENABLE )
add_definitions("-DREMOTE_INSPECTOR_ENABLE")
endif ( REMOTE_INSPECTOR_ENABLE)

if ( ENABLE_JSRUNTIME_PLAYER )
add_definitions("-DENABLE_JSRUNTIME_PLAYER")
Expand Down Expand Up @@ -154,6 +154,11 @@ if (ENABLE_JSRUNTIME_THUNDER_SECURITYAGENT)
add_definitions("-DENABLE_JSRUNTIME_THUNDER_SECURITYAGENT")
set(JSRUNTIME_LINK_LIBRARIES ${JSRUNTIME_LINK_LIBRARIES} -lsecurityagent)
endif(ENABLE_JSRUNTIME_THUNDER_SECURITYAGENT)

if (REMOTE_INSPECTOR_ENABLE)
set(JSRUNTIME_LINK_LIBRARIES ${JSRUNTIME_LINK_LIBRARIES} -lsoup-3.0 -lgio-2.0)
endif(REMOTE_INSPECTOR_ENABLE)

if (BUILD_JSRUNTIME_DESKTOP)
set(JSRUNTIME_INCLUDE_DIRECTORIES ${JSRUNTIME_INCLUDE_DIRECTORIES} $ENV{PKG_CONFIG_SYSROOT_DIR}/include $ENV{PKG_CONFIG_SYSROOT_DIR}/include/glib-2.0 $ENV{PKG_CONFIG_SYSROOT_DIR}/include/glib-2.0/glib $ENV{PKG_CONFIG_SYSROOT_DIR}/include/WPEFramework $ENV{PKG_CONFIG_SYSROOT_DIR}/include/uwebsockets)
set(JSRUNTIME_LIBRARY_LINK_DIRECTORIES ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -L$ENV{PKG_CONFIG_SYSROOT_DIR}/lib)
Expand All @@ -175,6 +180,9 @@ if (BUILD_JSRUNTIME_DESKTOP)
set(JSRUNTIME_LIBRARY_LINK_DIRECTORIES ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -L${CMAKE_CURRENT_SOURCE_DIR}/build/)
else ()
set(JSRUNTIME_INCLUDE_DIRECTORIES ${JSRUNTIME_INCLUDE_DIRECTORIES} $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/glib-2.0 $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/lib/glib-2.0/include/ $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/rtcore $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/WPEFramework $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/gstreamer-1.0 $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/uwebsockets)
if (REMOTE_INSPECTOR_ENABLE)
set(JSRUNTIME_INCLUDE_DIRECTORIES ${JSRUNTIME_INCLUDE_DIRECTORIES} $ENV{PKG_CONFIG_SYSROOT_DIR}/usr/include/libsoup-3.0)
endif(REMOTE_INSPECTOR_ENABLE)
set(JSRUNTIME_LINK_LIBRARIES ${JSRUNTIME_LINK_LIBRARIES} -lessos)
set(JSRUNTIME_LIBRARY_LINK_DIRECTORIES ${JSRUNTIME_LIBRARY_LINK_DIRECTORIES} -L${CMAKE_CURRENT_SOURCE_DIR}/../build/)
endif (BUILD_JSRUNTIME_DESKTOP)
Expand Down
98 changes: 98 additions & 0 deletions include/InspectorHTTPServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* 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.
**/

#pragma once

#ifdef REMOTE_INSPECTOR_ENABLE

#include <libsoup/soup.h>
#include <JavaScriptCore/JavaScript.h>
#include <string>
#include <map>
#include <mutex>
#include <functional>

class InspectorHTTPServer {
public:
static InspectorHTTPServer& singleton();
~InspectorHTTPServer();

bool start(const char* address, int port);
void stop();

bool isRunning() const { return m_server != nullptr; }

void registerContext(JSGlobalContextRef context, const char* title, const char* url);

void unregisterContext(JSGlobalContextRef context);

void sendConsoleMessage(JSContextRef context, const char* level, const char* text);

void registerScript(const char* url, const char* source);

// Called when frontend sends Page.reload.
void setReloadCallback(std::function<void()> callback);

private:
InspectorHTTPServer();

static void onHTTPRequest(SoupServer* server, SoupServerMessage* msg,
const char* path, GHashTable* query,
gpointer userData);

static void onWebSocketRequest(SoupServer* server, SoupServerMessage* msg,
const char* path, SoupWebsocketConnection* connection,
gpointer userData);

static void onWebSocketMessage(SoupWebsocketConnection* connection,
SoupWebsocketDataType dataType,
GBytes* message, gpointer userData);

static void onWebSocketClosed(SoupWebsocketConnection* connection, gpointer userData);

std::string generateTargetListJSON();

void handleCDPMessage(SoupWebsocketConnection* connection, const char* message);

struct ContextInfo {
JSGlobalContextRef context;
std::string title;
std::string url;
uint64_t id;
};

struct ScriptInfo {
std::string id;
std::string url;
std::string source;
};

SoupServer* m_server;
int m_port;
std::map<JSGlobalContextRef, ContextInfo> m_contexts;
std::map<SoupWebsocketConnection*, JSGlobalContextRef> m_connections;
std::map<std::string, ScriptInfo> m_scripts;
std::mutex m_scriptsMutex;
uint64_t m_nextContextId;
uint64_t m_nextScriptId;
std::function<void()> m_reloadCallback;
};

#endif // REMOTE_INSPECTOR_ENABLE

6 changes: 6 additions & 0 deletions include/jsc/JavaScriptUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,10 @@ rtError rtGetRandomValuesBinding(int numArgs, const rtValue* args, rtValue* resu
rtError rtInstallTimeout(int numArgs, const rtValue* args, rtValue* result, bool repeat);
JSValueRef requireCallback(JSContextRef ctx, JSObjectRef, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception);

JSValueRef consoleLogCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef consoleWarnCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef consoleErrorCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef consoleDebugCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef consoleInfoCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);

#endif /* JAVASCRIPTMISC_H */
Loading