javascript - How can I send an http request without needing an answer -
i'm trying make sonos web controller use when our app dont work. found api i'm using state of players using code written firend. https://github.com/jishi/node-sonos-http-api , js below
var title = document.getelementbyid("title"); var artist = document.getelementbyid("artist"); var currentduration = document.getelementbyid("current-duration"); var totalduration = document.getelementbyid("total-duration"); var art = document.getelementbyid("art"); setinterval(update("http://192.168.1.191:5005/vardagsrum/state"), 500); function update(url) { getdata(url, function (data) { var jsondata = json.parse(data); title.innerhtml = jsondata.currenttrack.album; artist.innerhtml = jsondata.currenttrack.artist; currentduration.innerhtml = jsondata.elapsedtimeformatted; totalduration.innerhtml = new string(jsondata.currenttrack.duration).tohhmmss(); art.setattribute("src", jsondata.currenttrack.absolutealbumarturi); console.log(jsondata); }); } function getdata(url, callback) { var xhttp = getxmlhttprequest(); xhttp.onreadystatechange = function () { if (xhttp.readystate == 4) { if (xhttp.status == 200) { var data = xhttp.response; callback(data); } } } xhttp.open("get", url, true); xhttp.send(); } function getxmlhttprequest() { try { return new xmlhttprequest(); } catch (e) {} try { return new activexobject("msxml2.xmlhttp.3.0"); } catch (e) {} try { return new activexobject("msxml3.xmlhttp"); } catch (e) {} try { return new activexobject("msxml2.xmlhttp.6.0"); } catch (e) {} try { return new activexobject("msxml2.xmlhttp.3.0"); } catch (e) {} try { return new activexobject("msxml2.xmlhttp"); } catch (e) {} try { return new activexobject("microsoft.xmlhttp"); } catch (e) {} throw "error xmlhttprequest not supported"; } string.prototype.tohhmmss = function () { var sec_num = parseint(this, 10); // don't forget second param var hours = math.floor(sec_num / 3600); var minutes = math.floor((sec_num - (hours * 3600)) / 60); var seconds = sec_num - (hours * 3600) - (minutes * 60); if (hours < 10) { hours = "0" + hours; } if (minutes < 10) { minutes = "0" + minutes; } if (seconds < 10) { seconds = "0" + seconds; } return hours + ':' + minutes + ':' + seconds; } and code updates current track on screen , prints 4 p tags class song-info
<html> <head> <meta charset="utf-8"> <title>sonos controller</title> <link rel="stylesheet" href="style.css"> </head> <body> <main> <div class="img"> <img id="art" src="https://i.vimeocdn.com/portrait/58832_300x300" alt="ablum art" width="500" height="500"> </div> <div> <p class="song-info" id="title">dark horse</p> <p class="song-info" id="artist">lady gaga</p> <p class="song-info" id="current-duration">1:57</p> <p class="song-info" id="total-duration">3:55</p> </div> <div class="btn"> <button>prev</button> <button>play / pause</button> <button>next</button> </div> <div> <button>change room</button> <input id="vol-control" type="range" min="0" max="100" step="1"> </input> <input list="browsers" name="browser"> <datalist id="browsers"> <option value="vardagsrum"> <option value="bibliotek"> <option value="linus s5"> <option value="kök"> </datalist> </form> </div> </main> </body> <script src="js.js"></script> </html> my question how can send http request player without needing answer. need send "192.168.1.191:5005/[room]/play" when click play/pause button?
greatful answer
Comments
Post a Comment