Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webserver: decouple different webserver capabilities into handlers #706

Merged
merged 13 commits into from
Mar 27, 2012
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
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ DIRECTORY_ARCHIVES=$(DVDPLAYER_ARCHIVES) \
xbmc/music/tags/musictags.a \
xbmc/music/windows/musicwindows.a \
xbmc/network/libscrobbler/scrobbler.a \
xbmc/network/httprequesthandler/httprequesthandlers.a \
xbmc/network/websocket/websocket.a \
xbmc/network/network.a \
xbmc/peripherals/bus/peripheral-bus.a \
Expand Down
872 changes: 567 additions & 305 deletions addons/webinterface.default/js/MediaLibrary.js

Large diffs are not rendered by default.

107 changes: 73 additions & 34 deletions addons/webinterface.default/js/NowPlayingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ NowPlayingManager.prototype = {
updateState: function() {
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?UpdateState',
data: '{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}',
timeout: 3000,
Expand Down Expand Up @@ -99,9 +100,12 @@ NowPlayingManager.prototype = {
dataType: 'json'});
},
updatePlayer: function() {
jQuery.post(JSON_RPC + '?UpdatePlayer',
'{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": ' + this.activePlayerId + ', "properties": [ "playlistid", "speed", "position", "totaltime", "time" ] }, "id": 1}',
jQuery.proxy(function(data) {
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?UpdatePlayer',
data: '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": { "playerid": ' + this.activePlayerId + ', "properties": [ "playlistid", "speed", "position", "totaltime", "time" ] }, "id": 1}',
success: jQuery.proxy(function(data) {
if (data && data.result)
{
this.playlistid = data.result.playlistid;
Expand All @@ -124,7 +128,8 @@ NowPlayingManager.prototype = {
this.activeItemTimer = 1;
setTimeout(jQuery.proxy(this.updateActiveItemDurationLoop, this), 1000);
}
}, this), 'json');
}, this),
dataType: 'json'});
},
bindPlaybackControls: function() {
$('#pbNext').bind('click', jQuery.proxy(this.nextTrack, this));
Expand Down Expand Up @@ -153,49 +158,73 @@ NowPlayingManager.prototype = {
},
nextTrack: function() {
if (this.activePlayer) {
jQuery.post(JSON_RPC + '?SkipNext', '{"jsonrpc": "2.0", "method": "Player.GoNext", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
//this.updateAudioPlaylist(true);
}
}, this), 'json');
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?SkipNext',
data: '{"jsonrpc": "2.0", "method": "Player.GoNext", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}',
success: jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
//this.updateAudioPlaylist(true);
}
}, this),
dataType: 'json'});
}
},
prevTrack: function() {
if (this.activePlayer) {
jQuery.post(JSON_RPC + '?SkipPrevious', '{"jsonrpc": "2.0", "method": "Player.GoPrevious", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
//this.updateAudioPlaylist(true);
}
}, this), 'json');
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?SkipPrevious',
data: '{"jsonrpc": "2.0", "method": "Player.GoPrevious", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}',
success: jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
//this.updateAudioPlaylist(true);
}
}, this),
dataType: 'json'});
}
},
stopTrack: function() {
if (this.activePlayer) {
jQuery.post(JSON_RPC + '?Stop', '{"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
this.playing = false;
this.paused = false;
this.trackBaseTime = 0;
this.trackDurationTime = 0;
this.showPlayButton();
}
}, this), 'json');
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?Stop',
data: '{"jsonrpc": "2.0", "method": "Player.Stop", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}',
success: jQuery.proxy(function(data) {
if (data && data.result == 'OK') {
this.playing = false;
this.paused = false;
this.trackBaseTime = 0;
this.trackDurationTime = 0;
this.showPlayButton();
}
}, this),
dataType: 'json'});
}
},
playPauseTrack: function() {
if (this.activePlayer) {
var method = ((this.playing || this.paused) ? 'Player.PlayPause' : 'Playlist.Play');
jQuery.post(JSON_RPC + '?PlayPause', '{"jsonrpc": "2.0", "method": "' + method + '", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}', jQuery.proxy(function(data) {
if (data && data.result) {
this.playing = data.result.speed != 0;
this.paused = data.result.speed == 0;
if (this.playing) {
this.showPauseButton();
} else {
this.showPlayButton();
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?PlayPause',
data: '{"jsonrpc": "2.0", "method": "' + method + '", "params": { "playerid": ' + this.activePlayerId + ' }, "id": 1}',
success: jQuery.proxy(function(data) {
if (data && data.result) {
this.playing = data.result.speed != 0;
this.paused = data.result.speed == 0;
if (this.playing) {
this.showPauseButton();
} else {
this.showPlayButton();
}
}
}
}, this), 'json');
}, this),
dataType: 'json'});
}
},
showPauseButton: function() {
Expand All @@ -221,7 +250,15 @@ NowPlayingManager.prototype = {
playPlaylistItem: function(sender) {
var sequenceId = $(sender.currentTarget).attr('seq');
if (!this.activePlaylistItem || (this.activePlaylistItem !== undefined && sequenceId != this.activePlaylistItem.seq)) {
jQuery.post(JSON_RPC + '?PlaylistItemPlay', '{"jsonrpc": "2.0", "method": "Player.GoTo", "params": { "playerid": ' + this.activePlayerId + ', "item": ' + sequenceId + '}, "id": 1}', function() {}, 'json');
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?PlaylistItemPlay',
data: '{"jsonrpc": "2.0", "method": "Player.GoTo", "params": { "playerid": ' + this.activePlayerId + ', "item": ' + sequenceId + '}, "id": 1}',
success: jQuery.proxy(function(data) {

}, this),
dataType: 'json'});
}
this.hidePlaylist();
},
Expand All @@ -245,6 +282,7 @@ NowPlayingManager.prototype = {
updateAudioPlaylist: function() {
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?updateAudioPlaylist',
data: '{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "playlistid": ' + this.playlistid + ', "properties": [ "title", "album", "artist", "duration", "thumbnail" ] }, "id": 1}',
success: jQuery.proxy(function(data) {
Expand Down Expand Up @@ -452,6 +490,7 @@ NowPlayingManager.prototype = {
updateVideoPlaylist: function() {
jQuery.ajax({
type: 'POST',
contentType: 'application/json',
url: JSON_RPC + '?updateVideoPlaylist',
data: '{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "playlistid": ' + this.playlistid + ', "properties": ["title", "season", "episode", "plot", "runtime", "showtitle","thumbnail"] }, "id": 1}',
success: jQuery.proxy(function(data) {
Expand Down
12 changes: 12 additions & 0 deletions project/VS2010Express/XBMC.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,12 @@
<ClCompile Include="..\..\xbmc\network\EventServer.cpp" />
<ClCompile Include="..\..\xbmc\network\GUIDialogAccessPoints.cpp" />
<ClCompile Include="..\..\xbmc\network\GUIDialogNetworkSetup.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPApiHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPJsonRpcHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPVfsHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceAddonsHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\httprequesthandler\IHTTPRequestHandler.cpp" />
<ClCompile Include="..\..\xbmc\network\libscrobbler\lastfmscrobbler.cpp" />
<ClCompile Include="..\..\xbmc\network\libscrobbler\librefmscrobbler.cpp" />
<ClCompile Include="..\..\xbmc\network\libscrobbler\scrobbler.cpp" />
Expand Down Expand Up @@ -799,6 +805,12 @@
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\IJSONRPCAnnouncer.h" />
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\JSONRPCUtils.h" />
<ClInclude Include="..\..\xbmc\interfaces\json-rpc\GUIOperations.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPApiHandler.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPJsonRpcHandler.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPVfsHandler.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceAddonsHandler.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceHandler.h" />
<ClInclude Include="..\..\xbmc\network\httprequesthandler\IHTTPRequestHandler.h" />
<ClInclude Include="..\..\xbmc\threads\platform\win\Implementation.cpp" />
<ClCompile Include="..\..\xbmc\threads\SystemClock.cpp" />
<ClCompile Include="..\..\xbmc\threads\Thread.cpp" />
Expand Down
39 changes: 39 additions & 0 deletions project/VS2010Express/XBMC.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@
<Filter Include="filesystem\windows">
<UniqueIdentifier>{1cc693eb-11ad-4f53-8640-198d5ab9bcc8}</UniqueIdentifier>
</Filter>
<Filter Include="network\httprequesthandler">
<UniqueIdentifier>{9029e610-aa5a-4414-9e96-1d69f03b3bd8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\xbmc\win32\pch.cpp">
Expand Down Expand Up @@ -2568,6 +2571,12 @@
<ClCompile Include="..\..\xbmc\cores\paplayer\PCMCodec.cpp">
<Filter>cores\paplayer</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPApiHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPVfsHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\utils\Base64.cpp">
<Filter>utils</Filter>
</ClCompile>
Expand Down Expand Up @@ -2598,6 +2607,18 @@
<ClCompile Include="..\..\xbmc\utils\Mime.cpp">
<Filter>utils</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceAddonsHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\HTTPJsonRpcHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
<ClCompile Include="..\..\xbmc\network\httprequesthandler\IHTTPRequestHandler.cpp">
<Filter>network\httprequesthandler</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
Expand Down Expand Up @@ -5220,6 +5241,24 @@
<ClInclude Include="..\..\xbmc\utils\Mime.h">
<Filter>utils</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\IHTTPRequestHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPApiHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPVfsHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPWebinterfaceAddonsHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
<ClInclude Include="..\..\xbmc\network\httprequesthandler\HTTPJsonRpcHandler.h">
<Filter>network\httprequesthandler</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
Expand Down
61 changes: 61 additions & 0 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
#include "video/Bookmark.h"
#ifdef HAS_WEB_SERVER
#include "network/WebServer.h"
#include "network/httprequesthandler/HTTPVfsHandler.h"
#ifdef HAS_HTTPAPI
#include "network/httprequesthandler/HTTPApiHandler.h"
#endif
#ifdef HAS_JSONRPC
#include "network/httprequesthandler/HTTPJsonRpcHandler.h"
#endif
#ifdef HAS_WEB_INTERFACE
#include "network/httprequesthandler/HTTPWebinterfaceHandler.h"
#include "network/httprequesthandler/HTTPWebinterfaceAddonsHandler.h"
#endif
#endif
#ifdef HAS_LCD
#include "utils/LCDFactory.h"
Expand Down Expand Up @@ -335,6 +346,17 @@ CApplication::CApplication(void)
: m_pPlayer(NULL)
#ifdef HAS_WEB_SERVER
, m_WebServer(*new CWebServer)
, m_httpVfsHandler(*new CHTTPVfsHandler)
#ifdef HAS_HTTPAPI
, m_httpApiHandler(*new CHTTPApiHandler)
#endif
#ifdef HAS_JSONRPC
, m_httpJsonRpcHandler(*new CHTTPJsonRpcHandler)
#endif
#ifdef HAS_WEB_INTERFACE
, m_httpWebinterfaceHandler(*new CHTTPWebinterfaceHandler)
, m_httpWebinterfaceAddonsHandler(*new CHTTPWebinterfaceAddonsHandler)
#endif
#endif
, m_itemCurrentFile(new CFileItem)
, m_progressTrackingVideoResumeBookmark(*new CBookmark)
Expand Down Expand Up @@ -384,6 +406,17 @@ CApplication::~CApplication(void)
{
#ifdef HAS_WEB_SERVER
delete &m_WebServer;
delete &m_httpVfsHandler;
#ifdef HAS_HTTPAPI
delete &m_httpApiHandler;
#endif
#ifdef HAS_JSONRPC
delete &m_httpJsonRpcHandler;
#endif
#ifdef HAS_WEB_INTERFACE
delete &m_httpWebinterfaceHandler;
delete &m_httpWebinterfaceAddonsHandler;
#endif
#endif
delete &m_progressTrackingVideoResumeBookmark;
#ifdef HAS_DVD_DRIVE
Expand Down Expand Up @@ -1068,6 +1101,20 @@ bool CApplication::Initialize()
g_curlInterface.Load();
g_curlInterface.Unload();

#ifdef HAS_WEB_SERVER
CWebServer::RegisterRequestHandler(&m_httpVfsHandler);
#ifdef HAS_JSONRPC
CWebServer::RegisterRequestHandler(&m_httpJsonRpcHandler);
#endif
#ifdef HAS_HTTPAPI
CWebServer::RegisterRequestHandler(&m_httpApiHandler);
#endif
#ifdef HAS_WEB_INTERFACE
CWebServer::RegisterRequestHandler(&m_httpWebinterfaceAddonsHandler);
CWebServer::RegisterRequestHandler(&m_httpWebinterfaceHandler);
#endif
#endif

StartServices();

// Init DPMS, before creating the corresponding setting control.
Expand Down Expand Up @@ -3328,6 +3375,20 @@ void CApplication::Stop(int exitCode)
StopServices();
//Sleep(5000);

#ifdef HAS_WEB_SERVER
CWebServer::UnregisterRequestHandler(&m_httpVfsHandler);
#ifdef HAS_JSONRPC
CWebServer::UnregisterRequestHandler(&m_httpJsonRpcHandler);
#endif
#ifdef HAS_HTTPAPI
CWebServer::UnregisterRequestHandler(&m_httpApiHandler);
#endif
#ifdef HAS_WEB_INTERFACE
CWebServer::UnregisterRequestHandler(&m_httpWebinterfaceAddonsHandler);
CWebServer::UnregisterRequestHandler(&m_httpWebinterfaceHandler);
#endif
#endif

#if defined(__APPLE__) && !defined(__arm__)
XBMCHelper::GetInstance().ReleaseAllInput();
#endif
Expand Down
Loading