-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsoundcloud_client.js
62 lines (51 loc) · 1.79 KB
/
soundcloud_client.js
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
Soundcloud = {};
// Request Soundcloud credentials for the user
// @param options {optional}
// @param credentialRequestCompleteCallback {Function} Callback function to call on
// completion. Takes one argument, credentialToken on success, or Error on
// error.
Soundcloud.requestCredential = function (options, credentialRequestCompleteCallback) {
// support both (options, callback) and (callback).
if (!credentialRequestCompleteCallback && typeof options === 'function') {
credentialRequestCompleteCallback = options;
options = {};
} else if (!options) {
options = {};
}
var config = ServiceConfiguration.configurations.findOne({service: 'soundcloud'});
if (!config) {
credentialRequestCompleteCallback && credentialRequestCompleteCallback(new ServiceConfiguration.ConfigError("Service not configured"));
return;
}
var credentialToken = Random.id();
var loginUrl =
'https://soundcloud.com/connect' +
'?client_id=' + config.clientId +
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/soundcloud?close') +
'&scope=non-expiring' +
'&response_type=code_and_token' +
'&display=popup' +
'&state=' + credentialToken;
Oauth.initiateLogin(credentialToken, loginUrl, credentialRequestCompleteCallback);
};
var ready = false;
var readyDep = new Deps.Dependency;
Soundcloud.ready = function (){
readyDep.depend();
return ready;
};
Meteor.startup(function() {
Deps.autorun(function() {
if (Accounts.loginServicesConfigured()) {
var config = ServiceConfiguration.configurations.findOne({service: 'soundcloud'});
if (!config) {
throw new Error("Soundcloud service is not configured");
}
SC.initialize({
client_id: config.clientId
});
ready = true;
readyDep.changed();
}
});
});