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
11 changes: 11 additions & 0 deletions include/JSRuntimeClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,23 @@ class JSRuntimeClient : public CommandInterface<JSRuntimeClient>

std::string getState();

#ifdef UNIT_TEST_BUILD
protected:
void onMessage(websocketpp::connection_hdl hdl, message_ptr msg);
void setState(const std::string &state);
void onOpen(websocketpp::connection_hdl hdl);
void onFail(websocketpp::connection_hdl hdl);
void onClose(websocketpp::connection_hdl hdl);
#endif

#ifndef UNIT_TEST_BUILD
private:
void onMessage(websocketpp::connection_hdl hdl, message_ptr msg);
void setState(const std::string &state);
void onOpen(websocketpp::connection_hdl hdl);
void onFail(websocketpp::connection_hdl hdl);
void onClose(websocketpp::connection_hdl hdl);
#endif

private:
JSRuntimeClient();
Expand Down
15 changes: 15 additions & 0 deletions include/JSRuntimeServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,25 @@ class JSRuntimeServer
bool stop();

private:
#ifdef UNIT_TEST_BUILD
public:
// Expose private methods for testing
void send(websocketpp::connection_hdl hdl, const std::string &msg);
void onMessage(websocketpp::connection_hdl hdl, message_ptr msg);
void onOpen(websocketpp::connection_hdl hdl);
void onClose(websocketpp::connection_hdl hdl);

const std::set<websocketpp::connection_hdl, std::owner_less<websocketpp::connection_hdl>>& getConnections() const { return mConnections; }
WsServer& getServer() { return mServer; }
#endif

#ifndef UNIT_TEST_BUILD
private:
void send(websocketpp::connection_hdl hdl, const std::string &msg);
void onMessage(websocketpp::connection_hdl hdl, message_ptr msg);
void onOpen(websocketpp::connection_hdl hdl);
void onClose(websocketpp::connection_hdl hdl);
#endif

private:
typedef std::set<websocketpp::connection_hdl, std::owner_less<websocketpp::connection_hdl>> ConnectionSet;
Expand Down
9 changes: 9 additions & 0 deletions include/jsc/JavaScriptContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,16 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
double getExecutionDuration() const;

void handleExternalApplication(const std::string& url);
#ifdef UNIT_TEST_BUILD
bool evaluateScript(const char *script, const char *name, const char *args = nullptr, bool module = false);
void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress);
void registerUtils();
void loadAAMPJSBindingsLib();
void unloadAAMPJSBindingsLib();
#endif

private:
#ifndef UNIT_TEST_BUILD
bool evaluateScript(const char *script, const char *name, const char *args = nullptr, bool module = false);
void processKeyEvent(struct JavaScriptKeyDetails& details, bool keyPress);
void registerUtils();
Expand All @@ -102,6 +110,7 @@ class JavaScriptContext: public JavaScriptContextBase, public NetworkMetricsList
void unloadAAMPJSBindingsLib();
void *jscLibHandle = nullptr;
#endif
#endif
#endif
JSContextGroupRef mContextGroup;
JSGlobalContextRef mContext;
Expand Down
4 changes: 4 additions & 0 deletions include/jsc/JavaScriptWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

rtError jsToRt(JSContextRef context, JSValueRef value, rtValue &result, JSValueRef *exception);
JSValueRef rtToJs(JSContextRef context, const rtValue &rtval);
#ifdef UNIT_TEST_BUILD
void clearGlobalWrapperCacheForTests();
#endif

class JSObjectWrapper: public jsruntime::RefCounted<rtIObject>, public rtJSCWrapperBase
{
Expand All @@ -50,6 +53,7 @@ class JSObjectWrapper: public jsruntime::RefCounted<rtIObject>, public rtJSCWrap

class JSFunctionWrapper: public jsruntime::RefCounted<rtIFunction>, public rtJSCWrapperBase
{
private:
size_t hash() override { return mHash; }
void setHash(size_t hash) override { UNUSED_PARAM(hash); }
rtError Send(int numArgs, const rtValue* args, rtValue* result) override;
Expand Down
5 changes: 5 additions & 0 deletions include/jsc/PlayerEventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ class PlayerEventHandler : public AAMPEventObjectListener
void removeEventListener(AAMPEventType type, JSObjectRef callback);
void removeAllEventListeners();
void Event(const AAMPEventPtr& e);
#ifdef UNIT_TEST_BUILD
void sendEvent(AAMPEventType type, JSObjectRef event);
#endif
private:
#ifndef UNIT_TEST_BUILD
void sendEvent(AAMPEventType type, JSObjectRef event);
#endif
JSContextRef mContext;
PlayerInstanceAAMP* mPlayer;
std::map<AAMPEventType, std::vector<EventHandlerData>> mEventListeners;
Expand Down
51 changes: 51 additions & 0 deletions include/jsc/PlayerWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,63 @@ struct PlayerWrapper

JSGlobalContextRef ctx;
PlayerInstanceAAMP* mPlayer;
#ifdef UNIT_TEST_BUILD
PlayerEventHandler* mPlayerEventHandler;
#endif

private:
JSObjectRef getCallbackForAdId(std::string id);
std::map<std::string, JSObjectRef> mPromiseCallbacks;
#ifndef UNIT_TEST_BUILD
PlayerEventHandler* mPlayerEventHandler;
#endif
};

void initializePlayer(JSGlobalContextRef context);
void deinitializePlayer(JSGlobalContextRef context);

#ifdef UNIT_TEST_BUILD
std::vector<std::string> JSStringArrayToCStringArray(JSContextRef context, JSValueRef arrayRef);

JSValueRef AAMPMediaPlayerJS_initConfig(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_load(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setVolume(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_addEventListener(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_removeEventListener(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_subscribeResponseHeaders(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setSubscribedTags(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_addCustomHTTPHeader(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_removeCustomHTTPHeader(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setClosedCaptionStatus(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setVideoMute(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_play(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_detach(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_pause(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_release(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_stop(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_seek(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getAudioTrackInfo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getTextTrackInfo(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getDurationSec(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getCurrentPosition(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getAudioTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getTextTrack(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getVolume(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setAudioLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setPlaybackRate(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setVideoRect(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setVideoZoom(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setPreferredAudioLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setPreferredTextLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setTextStyleOptions(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setAuxiliaryLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_xreSupportedTune(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);

JSValueRef AAMPMediaPlayerJS_getAvailableAudioTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getAvailableTextTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
JSValueRef AAMPMediaPlayerJS_notifyReservationCompletion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
#endif

#endif
1 change: 1 addition & 0 deletions include/rtWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ class rtWebSocket : public rtObject
};

#endif //RT_WEB_SOCKET_H

9 changes: 9 additions & 0 deletions src/jsc/JavaScriptWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,3 +969,12 @@ rtError JSFunctionWrapper::Send(int numArgs, const rtValue* args, rtValue* resul
return RT_OK;
}
}

#ifdef UNIT_TEST_BUILD

void clearGlobalWrapperCacheForTests()
{
assertIsMainThread();
globalWrapperCache.clear();
}
#endif
26 changes: 25 additions & 1 deletion src/jsc/PlayerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@
if (!privObj || !privObj->mPlayer)
{
*exception = GetException(ctx, "Can only call load() on instances of AAMPPlayer");
return JSValueMakeUndefined(ctx);

Check failure on line 370 in src/jsc/PlayerWrapper.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/jsc/PlayerWrapper.cpp' (Match: rdk/components/generic/aamp/rdk/components/generic/aamp/2.10.1.0, 1332 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/aamp/+archive/2.10.1.0.tar.gz, file: jsbindings/jsmediaplayer.cpp)
}
bool autoPlay = true;
bool bFinalAttempt = false;
Expand Down Expand Up @@ -743,7 +743,7 @@
if (!privObj || !privObj->mPlayer)
{
*exception = GetException(ctx, "Can only call play() on instances of AAMPPlayer");
return JSValueMakeUndefined(ctx);

Check failure on line 746 in src/jsc/PlayerWrapper.cpp

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'src/jsc/PlayerWrapper.cpp' (Match: rdk/components/generic/aamp/rdk/components/generic/aamp/stable2, 956 lines, url: https://code.rdkcentral.com/r/plugins/gitiles/rdk/components/generic/aamp/+archive/stable2.tar.gz, file: jsbindings/jsmediaplayer.cpp)
}
{
privObj->mPlayer->SetRate(AAMP_NORMAL_PLAY_RATE);
Expand Down Expand Up @@ -1128,7 +1128,11 @@
return JSValueMakeUndefined(ctx);
}

#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_getAvailableAudioTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_getAvailableAudioTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand Down Expand Up @@ -1163,7 +1167,11 @@
* @param[out] exception pointer to a JSValueRef in which to return an exception, if any
* @retval JSValue that is the function's return value
*/
#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_getAvailableTextTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_getAvailableTextTracks(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand Down Expand Up @@ -1198,7 +1206,11 @@
* @param[out] exception pointer to a JSValueRef in which to return an exception, if any
* @retval JSValue that is the function's return value
*/
#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_getVideoRectangle(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand All @@ -1221,7 +1233,11 @@
* @param[out] exception pointer to a JSValueRef in which to return an exception, if any
* @retval JSValue that is the function's return value
*/
static JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_setAlternateContent(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand Down Expand Up @@ -1405,7 +1421,11 @@
return JSValueMakeUndefined(ctx);
}

#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_notifyReservationCompletion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_notifyReservationCompletion(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand Down Expand Up @@ -1458,7 +1478,11 @@
return JSValueMakeUndefined(ctx);
}

#ifdef UNIT_TEST_BUILD
JSValueRef AAMPMediaPlayerJS_setAuxiliaryLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#else
static JSValueRef AAMPMediaPlayerJS_setAuxiliaryLanguage(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef *exception)
#endif
{
PlayerWrapper* privObj = (PlayerWrapper*)JSObjectGetPrivate(thisObject);
if (!privObj || !privObj->mPlayer)
Expand Down
Loading
Loading