-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
141 lines (106 loc) · 2.98 KB
/
script.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
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
133
134
135
136
137
138
139
140
141
var sp = getSpotifyApi(1);
var m = sp.require("sp://import/scripts/api/models");
var v = sp.require("sp://import/scripts/api/views");
var ui = sp.require('sp://import/scripts/dnd');
var socket;
//exports.init = init;
function init() {
updatePageWithTrackDetails();
sp.trackPlayer.addEventListener("playerStateChanged", function (event) {
// Only update the page if the track changed
if (event.data.curtrack == true) {
updatePageWithTrackDetails();
}
});
}
function updatePageWithTrackDetails() {
var header = document.getElementById("header");
// This will be null if nothing is playing.
var playerTrackInfo = sp.trackPlayer.getNowPlayingTrack();
if (playerTrackInfo == null) {
header.innerText = "Nothing playing right now:)!";
} else {
var track = playerTrackInfo.track;
header.innerText = track.name + " on the album " + track.album.name + " by " + track.album.artist.name + ".";
}
}
function searchGoogleForSpotify() {
var req = new XMLHttpRequest();
req.open("GET", "https://www.googleapis.com/customsearch/v1?q=spotify", true);
req.onreadystatechange = function() {
console.log(req.status);
if (req.readyState == 4) {
if (req.status == 200) {
console.log("Search complete");
}
}
};
req.send();
}
function doConnect(){
socket = io.connect('http://localhost:8000');
socket.on("connect",onConnect)
}
function onConnect(evt){
console.log(evt);
return;
/*
data = new Object();
data.action = "join";
data.room = $("#room").val();
websocket.send(JSON.stringify(data));
*/
}
function onClose(evt){
console.log(evt);
}
function onMessage(evt){
console.log(evt);
try{
data = JSON.parse(evt.data);
console.log(data);
if(data.message){
$("#status").text("Status: "+data.message);
}
if(data.action == "play"){
m.Track.fromURI(data.uri,tplPlayer.play);
}
}catch(e){
console.log(e);
}
}
function onError(evt){
console.log(evt);
}
// Custom fields, playlist with tracks of varying availability.
var tpl = new m.Playlist();
var tplPlayer = new v.Player();
var tempList = new v.List(tpl);
tpl.add(m.Track.fromURI("spotify:track:4z4t4zEn4ElVPGmDWCzRQf"));
tpl.add(m.Track.fromURI("http://open.spotify.com/track/7E8JGVhbwWgAQ1DtfatQEl"));
tpl.add(m.Track.fromURI("spotify:track:40YBc3mR3yyqyYvtesQOMj"));
tpl.add(m.Track.fromURI("spotify:local:Rolling+Stones:A+Bigger+Bang:Rain+Fall+Down:293"));
tplPlayer.track = tpl.get(0);
tplPlayer.context = tpl;
$(document).ready(function(){
init();
$("h2").text("Niggah plz!");
var lib = sp.core.library.getPlaylists();
console.log(sp,sp.core,sp.core.library,sp.desktop);
document.body.appendChild(tplPlayer.node);
document.body.appendChild(tempList.node);
$(".connect").click(function(){
doConnect();
});
$(".playBtn").click(function(){
data = new Object();
data.action = "play";
data.room = $("#room").val();
websocket.send(JSON.stringify(data));
});
/*
for(i in lib){
$("#playlists").append("<li>"+lib[i].name+"</li>");
}
*/
});