forked from Wavestreaming/jquery-shoutcast
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.shoutcast.min.js
2 lines (2 loc) · 2.09 KB
/
jquery.shoutcast.min.js
1
2
/* Wavestreaming.com - https://github.com/Wavestreaming/jquery-shoutcast - MIT licensed */
(function(){function a(a){this._attr={},this.playedInterval=a.playedInterval||a.interval||3e4,this.statsInterval=a.statsInterval||a.interval||5e3,this.host=a.host,this.port=parseInt(a.port,10)||8e3,this.stream=parseInt(a.stream,10)||1,this._statsinterval=null,this._playedinterval=null,this._stats=a.stats||function(){},this._played=a.played||function(){}}"use strict",a.prototype.get=function(a,b){return a?typeof this._attr[a.toLowerCase()]!="undefined"?this._attr[a.toLowerCase()]:b:this._attr},a.prototype.stats=function(a){var b=this,c,d="http://"+this.host+":"+this.port+"/stats?sid="+this.stream+"&json=1";return a=a||function(){},c=$.ajax({url:d,dataType:"jsonp",timeout:"2000"}),c.success(function(c){if(typeof c!="object"||typeof c.streamstatus=="undefined"){b._status=0;return}b._status=c.streamstatus===1?2:1,b._attr=c,b._attr.status=b.getStatusAsText(),a.call(b,b._attr),b._stats(b._attr)}),c.error(function(){b._status=0,b._attr.status=b.getStatusAsText(),a.call(b,b._attr),b.stats(b._attr)}),this},a.prototype.played=function(a){var b=this,c="http://"+this.host+":"+this.port+"/played?sid="+this.stream+"&type=json";return $.ajax({url:c,dataType:"jsonp",timeout:2e3,success:function(c){if(!c instanceof Array)return;a&&a.call(b,c),b._played(c)}}),this},a.prototype.startStats=function(){return this.stopStats(),this.stats(),this._statsinterval=setInterval($.proxy(this.stats,this),this.statsInterval),this},a.prototype.stopStats=function(){return this._statsinterval&&clearInterval(this._statsinterval),this},a.prototype.startPlayed=function(){return this.stopPlayed(),this.played(),this._playedinterval=setInterval($.proxy(this.played,this),this.playedInterval),this},a.prototype.stopPlayed=function(){return this._playedinterval&&clearInterval(this._playedinterval),this},a.prototype.getStatus=function(){return this._status},a.prototype.getStatusAsText=function(){return["Offline","Awaiting Connection","On Air"][this._status]},a.prototype.onAir=function(){return this._status===2},$.SHOUTcast=function(b){return new a(b)}})();