From 9d5f6291ad47379e71da751572887de70f953b90 Mon Sep 17 00:00:00 2001 From: Dawid Juszczak Date: Thu, 31 Oct 2019 16:11:43 +0100 Subject: [PATCH] [6.0][mediacontroller] add playback action enum, listeners to server pbInfo and change iconURI [acr] http://suprem.sec.samsung.net/jira/browse/TWDAPI-245 [description] >> refactor_02 << + change iconURI to NOT readonly + add listeners in serverPlaybackInfo + add playbackAction enum + add onplaybackactionrequest [verification] tested manually in chrome console tct-mediacontroller-tizen-tests fails with 2 TC: - MediaControllerServer_iconURI_attribute.html <- has to be modified, because attribute iconURI is no longer readonly - MediaControllerServerInfo_iconURI_attribute.html <- has to be modified, because attribute iconURI is no longer readonly Change-Id: I1a234adbab71be72ec6c24a7fec4e8b5d7fcc55c Signed-off-by: Dawid Juszczak --- src/mediacontroller/mediacontroller_api.js | 84 +++++++++++++++++++++++++-- src/mediacontroller/mediacontroller_server.cc | 9 ++- src/mediacontroller/mediacontroller_utils.cc | 12 ++-- 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/src/mediacontroller/mediacontroller_api.js b/src/mediacontroller/mediacontroller_api.js index 119378b..5dc8c41 100755 --- a/src/mediacontroller/mediacontroller_api.js +++ b/src/mediacontroller/mediacontroller_api.js @@ -169,6 +169,13 @@ var ServerPlaybackInfoListener = new ListenerManager( '_ServerPlaybackInfoListener', function(msg, listener) { if (msg.action === 'onplaybackstaterequest') { + utils_.printDeprecationWarningFor( + 'onplaybackstaterequest', + 'onplaybackactionrequest' + ); + native_.callIfPossible(listener[msg.action], msg.state, msg.clientName); + } + if (msg.action === 'onplaybackactionrequest') { native_.callIfPossible(listener[msg.action], msg.state, msg.clientName); } if (msg.action === 'onplaybackpositionrequest') { @@ -319,6 +326,17 @@ var MediaControllerPlaybackState = { REWIND: 'REWIND' }; +var MediaControllerPlaybackAction = { + PLAY: 'PLAY', + PAUSE: 'PAUSE', + STOP: 'STOP', + NEXT: 'NEXT', + PREV: 'PREV', + FORWARD: 'FORWARD', + REWIND: 'REWIND', + TOGGLE_PLAY_PAUSE: 'TOGGLE_PLAY_PAUSE' +}; + var MediaControllerRepeatState = { REPEAT_OFF: 'REPEAT_OFF', REPEAT_ONE: 'REPEAT_ONE', @@ -2187,7 +2205,8 @@ function MediaControllerServer(data) { return _iconURI; }, set: function(v) { - _iconURI = edit_.isAllowed ? (v ? v : null) : _iconURI; + updateIconURI(v); + _iconURI = v; }, enumerable: true }, @@ -2241,6 +2260,11 @@ var updatePlaybackState = function(state) { }; MediaControllerServer.prototype.updateIconURI = function(iconURI) { + utils_.printDeprecationWarningFor('updateIconURI()'); + updateIconURI(iconURI); +}; + +var updateIconURI = function(iconURI) { var args = validator_.validateArgs(arguments, [ { name: 'iconURI', type: types_.STRING, nullable: true } ]); @@ -2256,10 +2280,6 @@ MediaControllerServer.prototype.updateIconURI = function(iconURI) { native_.getErrorObject(result).message ); } - - edit_.allow(); - this.iconURI = args.iconURI; - edit_.disallow(); }; MediaControllerServer.prototype.updatePlaybackPosition = function(position) { @@ -2432,12 +2452,18 @@ MediaControllerServer.prototype.updateMetadata = function(metadata) { MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function( listener ) { + utils_.printDeprecationWarningFor( + 'MediaControllerServer.addChangeRequestPlaybackInfoListener()', + 'MediaControllerServerPlaybackInfo.addChangeRequestListener()' + ); + var args = validator_.validateArgs(arguments, [ { name: 'listener', type: types_.LISTENER, values: [ 'onplaybackstaterequest', + 'onplaybackactionrequest', 'onplaybackpositionrequest', 'onshufflemoderequest', 'onrepeatmoderequest', @@ -2465,6 +2491,14 @@ MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function( MediaControllerServer.prototype.removeChangeRequestPlaybackInfoListener = function( watchId ) { + utils_.printDeprecationWarningFor( + 'MediaControllerServer.removeChangeRequestPlaybackInfoListener()', + 'MediaControllerServerPlaybackInfo.removeChangeRequestListener()' + ); + removeChangeRequestPlaybackInfoListener(watchId); +}; + +var removeChangeRequestPlaybackInfoListener = function(watchId) { var args = validator_.validateArgs(arguments, [ { name: 'watchId', type: types_.LONG } ]); @@ -4009,6 +4043,46 @@ MediaControllerServerPlaybackInfo.prototype.updatePlaybackItem = function( edit_.disallow(); }; +MediaControllerServerPlaybackInfo.prototype.addChangeRequestListener = function( + listener +) { + var args = validator_.validateArgs(arguments, [ + { + name: 'listener', + type: types_.LISTENER, + values: [ + 'onplaybackstaterequest', + 'onplaybackactionrequest', + 'onplaybackpositionrequest', + 'onshufflemoderequest', + 'onrepeatmoderequest', + 'onrepeatstaterequest', + 'onplaybackitemrequest' + ] + } + ]); + + if (type_.isEmptyObject(ServerPlaybackInfoListener.listeners)) { + var result = native_.callSync( + 'MediaControllerServerAddChangeRequestPlaybackInfoListener', + { + listenerId: ServerPlaybackInfoListener.listenerName + } + ); + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } + } + + return ServerPlaybackInfoListener.addListener(args.listener); +}; + +MediaControllerServerPlaybackInfo.prototype.removeChangeRequestListener = function( + watchId +) { + removeChangeRequestPlaybackInfoListener(watchId); +}; + function MediaControllerServerInfoPlaybackInfo(serverName, data) { var _serverName = serverName; // this variable will be used in the future diff --git a/src/mediacontroller/mediacontroller_server.cc b/src/mediacontroller/mediacontroller_server.cc index 2e9b1c6..09a22b7 100644 --- a/src/mediacontroller/mediacontroller_server.cc +++ b/src/mediacontroller/mediacontroller_server.cc @@ -1011,7 +1011,6 @@ void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, con MediaControllerServer* server = static_cast(user_data); - // Here, we need to convert mc_playback_action_e enum to mc_playback_states_e enum. std::string action_str; PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str); if (!result) { @@ -1023,11 +1022,17 @@ void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, con picojson::value data = picojson::value(picojson::object()); picojson::object& data_o = data.get(); - data_o[kAction] = picojson::value(std::string("onplaybackstaterequest")); + data_o[kAction] = picojson::value(std::string("onplaybackactionrequest")); data_o[kState] = picojson::value(action_str); data_o[kClientName] = picojson::value(client_name); + data_o[kRequestId] = request_id ? picojson::value(std::string(request_id)) : picojson::value(); server->change_request_playback_info_listener_(&data); + + if ("TOGGLE_PLAY_PAUSE" != action_str) { + data_o[kAction] = picojson::value(std::string("onplaybackstaterequest")); + server->change_request_playback_info_listener_(&data); + } } void MediaControllerServer::OnPlaybackPositionCommand(const char* client_name, diff --git a/src/mediacontroller/mediacontroller_utils.cc b/src/mediacontroller/mediacontroller_utils.cc index 7c6404b..7af3017 100644 --- a/src/mediacontroller/mediacontroller_utils.cc +++ b/src/mediacontroller/mediacontroller_utils.cc @@ -109,10 +109,14 @@ const common::PlatformEnum MediaControllerPlaybackStateEnu {"REWIND", MC_PLAYBACK_STATE_REWINDING}}; const common::PlatformEnum MediaControllerPlaybackActionEnum{ - {"PLAY", MC_PLAYBACK_ACTION_PLAY}, {"PAUSE", MC_PLAYBACK_ACTION_PAUSE}, - {"STOP", MC_PLAYBACK_ACTION_STOP}, {"NEXT", MC_PLAYBACK_ACTION_NEXT}, - {"PREV", MC_PLAYBACK_ACTION_PREV}, {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD}, - {"REWIND", MC_PLAYBACK_ACTION_REWIND}}; + {"PLAY", MC_PLAYBACK_ACTION_PLAY}, + {"PAUSE", MC_PLAYBACK_ACTION_PAUSE}, + {"STOP", MC_PLAYBACK_ACTION_STOP}, + {"NEXT", MC_PLAYBACK_ACTION_NEXT}, + {"PREV", MC_PLAYBACK_ACTION_PREV}, + {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD}, + {"REWIND", MC_PLAYBACK_ACTION_REWIND}, + {"TOGGLE_PLAY_PAUSE", MC_PLAYBACK_ACTION_TOGGLE_PLAY_PAUSE}}; const common::PlatformEnum MediaControllerMetadataAttributeEnum{ {"title", MC_META_MEDIA_TITLE}, -- 2.7.4