-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowsifyAPI.cpp
More file actions
133 lines (110 loc) · 3.49 KB
/
BrowsifyAPI.cpp
File metadata and controls
133 lines (110 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**********************************************************\
Auto-generated BrowsifyAPI.cpp
\**********************************************************/
#include "JSObject.h"
#include "variant_list.h"
#include "DOM/Document.h"
#include "global/config.h"
#include "BrowsifyAPI.h"
#include "SpotifyController.h"
BrowsifyAPI::BrowsifyAPI(const BrowsifyPluginPtr& plugin, const FB::BrowserHostPtr& host) :
m_plugin(plugin), m_host(host)
{
try
{
m_player = SpotifyControllerPtr(new SpotifyController);
m_valid = true;
}
catch(const SpotifyController::InitializationException&)
{
m_host->htmlLog("failed to initialize spotify controller");
}
registerMethod("playOrPause", make_method(this, &BrowsifyAPI::playOrPause));
registerMethod("goToPreviousTrack", make_method(this, &BrowsifyAPI::goToPreviousTrack));
registerMethod("goToNextTrack", make_method(this, &BrowsifyAPI::goToNextTrack));
// Read-write property
registerProperty("shuffling",
make_property(this,
&BrowsifyAPI::isShuffling,
&BrowsifyAPI::setShuffling));
registerProperty("repeating",
make_property(this,
&BrowsifyAPI::isRepeating,
&BrowsifyAPI::setRepeating));
// Read-only property
registerProperty("version",
make_property(this,
&BrowsifyAPI::get_version));
registerProperty("spotifyPlaying",
make_property(this,
&BrowsifyAPI::isSpotifyPlaying));
}
///////////////////////////////////////////////////////////////////////////////
/// @fn BrowsifyAPI::~BrowsifyAPI()
///
/// @brief Destructor. Remember that this object will not be released until
/// the browser is done with it; this will almost definitely be after
/// the plugin is released.
///////////////////////////////////////////////////////////////////////////////
BrowsifyAPI::~BrowsifyAPI() {};
///////////////////////////////////////////////////////////////////////////////
/// @fn BrowsifyPtr BrowsifyAPI::getPlugin()
///
/// @brief Gets a reference to the plugin that was passed in when the object
/// was created. If the plugin has already been released then this
/// will throw a FB::script_error that will be translated into a
/// javascript exception in the page.
///////////////////////////////////////////////////////////////////////////////
BrowsifyPluginPtr BrowsifyAPI::getPlugin()
{
BrowsifyPluginPtr plugin(m_plugin.lock());
if (!plugin) {
throw FB::script_error("The plugin is invalid");
}
return plugin;
}
void
BrowsifyAPI::playOrPause()
{
m_player->playOrPause();
}
void
BrowsifyAPI::goToPreviousTrack()
{
m_player->goToPreviousTrack();
}
void
BrowsifyAPI::goToNextTrack()
{
m_player->goToNextTrack();
}
bool
BrowsifyAPI::isShuffling()
{
return m_player->isShuffling();
}
void
BrowsifyAPI::setShuffling(bool shuffling)
{
m_player->setShuffling(shuffling);
}
bool
BrowsifyAPI::isRepeating()
{
return m_player->isRepeating();
}
void
BrowsifyAPI::setRepeating(bool repeating)
{
m_player->setRepeating(repeating);
}
// Read-only property version
bool
BrowsifyAPI::isSpotifyPlaying()
{
return m_player->isSpotifyPlaying();
}
std::string BrowsifyAPI::get_version()
{
return FBSTRING_PLUGIN_VERSION;
}