discord-rich-presence
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DiscordRichPresence=t():e.DiscordRichPresence=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function s(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=3)}([function(e,t){function s(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"object"==typeof e&&null!==e}function r(e){return void 0===e}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0,s.defaultMaxListeners=10,s.prototype.setMaxListeners=function(e){if(!function(e){return"number"==typeof e}(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},s.prototype.emit=function(e){var t,s,o,c,a,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(r(s=this._events[e]))return!1;if(n(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:c=Array.prototype.slice.call(arguments,1),s.apply(this,c)}else if(i(s))for(c=Array.prototype.slice.call(arguments,1),o=(u=s.slice()).length,a=0;a<o;a++)u[a].apply(this,c);return!0},s.prototype.addListener=function(e,t){var o;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(o=r(this._maxListeners)?s.defaultMaxListeners:this._maxListeners)&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},s.prototype.on=s.prototype.addListener,s.prototype.once=function(e,t){if(!n(t))throw TypeError("listener must be a function");var s=!1;function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}return i.listener=t,this.on(e,i),this},s.prototype.removeListener=function(e,t){var s,r,o,c;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(s=this._events[e]).length,r=-1,s===t||n(s.listener)&&s.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(s)){for(c=o;c-- >0;)if(s[c]===t||s[c].listener&&s[c].listener===t){r=c;break}if(r<0)return this;1===s.length?(s.length=0,delete this._events[e]):s.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},s.prototype.removeAllListeners=function(e){var t,s;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n(s=this._events[e]))this.removeListener(e,s);else if(s)for(;s.length;)this.removeListener(e,s[s.length-1]);return delete this._events[e],this},s.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},s.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},s.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,s){"use strict";let n;try{const{app:e}=s(5);n=e.setAsDefaultProtocolClient.bind(e)}catch(e){try{n=s(6)}catch(e){}}"function"!=typeof n&&(n=(()=>!1));e.exports={pid:function(){return"undefined"!=typeof process?process.pid:null},register:n,uuid:()=>{let e="";for(let t=0;t<32;t+=1){let s;if(8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),12===t)s=4;else{const e=16*Math.random()|0;s=16===t?3&e|0:e}e+=s.toString(16)}return e}}},function(e,t){var s;s=function(){return this}();try{s=s||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(s=window)}e.exports=s},function(e,t,s){"use strict";const n=s(4),i=s(0),r="undefined"!=typeof window;e.exports=function(e){const t=new n.Client({transport:r?"websocket":"ipc"});let s=!1,o=null;const c=new class extends i{updatePresence(e){s?t.setActivity(e).catch(e=>this.emit("error",e)):o=e}reply(e,s){const n=e=>this.emit("error",e);switch(s){case"YES":t.sendJoinInvite(e).catch(n);break;case"NO":case"IGNORE":t.closeJoinRequest(e).catch(n);break;default:throw new RangeError("unknown response")}}disconnect(){t.destroy().catch(e=>this.emit("error",e))}};return t.login({clientId:e}).then(()=>{c.emit("connected"),s=!0,t.subscribe("ACTIVITY_JOIN",({secret:e})=>{c.emit("join",e)}),t.subscribe("ACTIVITY_SPECTATE",({secret:e})=>{c.emit("spectate",e)}),t.subscribe("ACTIVITY_JOIN_REQUEST",e=>{c.emit("joinRequest",e)}),o&&(t.setActivity(o).catch(e=>c.emit("error",e)),o=null)}).catch(e=>c.emit("error",e)),c}},function(e,t,s){"use strict";const n=s(1);e.exports={Client:s(7),register:e=>n.register(`discord-${e}`)}},function(e,t){},function(e,t){},function(e,t,s){"use strict";const n=s(0),{setTimeout:i,clearTimeout:r}=s(8),o=s(10),c=s(11),{RPCCommands:a,RPCEvents:u}=s(15),{pid:h,uuid:l}=s(1);function d(e,t){return`${e}${JSON.stringify(t)}`}e.exports=class extends n{constructor(e={}){super(),this.options=e,this.accessToken=null,this.clientId=null,this.application=null,this.user=null;const t=c[e.transport];if(!t)throw new TypeError("RPC_INVALID_TRANSPORT",e.transport);this.fetch=((e,t,{data:s,query:n}={})=>o(`${this.fetch.endpoint}${t}${n?new URLSearchParams(n):""}`,{method:e,body:s,headers:{Authorzation:`Bearer ${this.accessToken}`}}).then(e=>e.json())),this.fetch.endpoint="https://discordapp.com/api",this.transport=new t(this),this.transport.on("message",this._onRpcMessage.bind(this)),this._expecting=new Map,this._subscriptions=new Map,this._connectPromise=void 0}connect(e){return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise((t,s)=>{this.clientId=e;const n=i(()=>s(new Error("RPC_CONNECTION_TIMEOUT")),1e4);n.unref(),this.once("connected",()=>{r(n),t(this)}),this.transport.once("close",s),this.transport.connect().catch(s)}),this._connectPromise)}async login(e={}){let{clientId:t,accessToken:s}=e;return await this.connect(t),e.scopes?(s||(s=await this.authorize(e)),this.authenticate(s)):(this.emit("ready"),this)}request(e,t,s){return new Promise((n,i)=>{const r=l();this.transport.send({cmd:e,args:t,evt:s,nonce:r}),this._expecting.set(r,{resolve:n,reject:i})})}_onRpcMessage(e){if(e.cmd===a.DISPATCH&&e.evt===u.READY)e.data.user&&(this.user=e.data.user),this.emit("connected");else if(this._expecting.has(e.nonce)){const{resolve:t,reject:s}=this._expecting.get(e.nonce);if("ERROR"===e.evt){const t=new Error(e.data.message);t.code=e.data.code,t.data=e.data,s(t)}else t(e.data);this._expecting.delete(e.nonce)}else{const t=d(e.evt,e.args);if(!this._subscriptions.has(t))return;this._subscriptions.get(t)(e.data)}}async authorize({scopes:e,clientSecret:t,rpcToken:s,redirectUri:n}={}){t&&!0===s&&(s=(await this.fetch("POST","/oauth2/token/rpc",{data:new URLSearchParams({client_id:this.clientId,client_secret:t})})).rpc_token);const{code:i}=await this.request("AUTHORIZE",{scopes:e,client_id:this.clientId,rpc_token:s,redirect_uri:n});return(await this.fetch("POST","/oauth2/token",{data:new URLSearchParams({client_id:this.clientId,code:i,grant_type:"authorization_code",redirect_uri:n})})).access_token}authenticate(e){return this.request("AUTHENTICATE",{access_token:e}).then(({application:t,user:s})=>(this.accessToken=e,this.application=t,this.user=s,this.emit("ready"),this))}getGuild(e,t){return this.request(a.GET_GUILD,{guild_id:e,timeout:t})}getGuilds(e){return this.request(a.GET_GUILDS,{timeout:e})}getChannel(e,t){return this.request(a.GET_CHANNEL,{channel_id:e,timeout:t})}async getChannels(e,t){const{channels:s}=await this.request(a.GET_CHANNELS,{timeout:t,guild_id:e});return s}setCertifiedDevices(e){return this.request(a.SET_CERTIFIED_DEVICES,{devices:e.map(e=>({type:e.type,id:e.uuid,vendor:e.vendor,model:e.model,related:e.related,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,automatic_gain_control:e.automaticGainControl,hardware_mute:e.hardwareMute}))})}setUserVoiceSettings(e,t){return this.request(a.SET_USER_VOICE_SETTINGS,{user_id:e,pan:t.pan,mute:t.mute,volume:t.volume})}selectVoiceChannel(e,{timeout:t,force:s=!1}={}){return this.request(a.SELECT_VOICE_CHANNEL,{channel_id:e,timeout:t,force:s})}selectTextChannel(e,{timeout:t,force:s=!1}={}){return this.request(a.SELECT_TEXT_CHANNEL,{channel_id:e,timeout:t,force:s})}getVoiceSettings(){return this.request(a.GET_VOICE_SETTINGS).then(e=>({automaticGainControl:e.automatic_gain_control,echoCancellation:e.echo_cancellation,noiseSuppression:e.noise_suppression,qos:e.qos,silenceWarning:e.silence_warning,deaf:e.deaf,mute:e.mute,input:{availableDevices:e.input.available_devices,device:e.input.device_id,volume:e.input.volume},output:{availableDevices:e.output.available_devices,device:e.output.device_id,volume:e.output.volume},mode:{type:e.mode.type,autoThreshold:e.mode.auto_threshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}}))}setVoiceSettings(e){return this.request(a.SET_VOICE_SETTINGS,{automatic_gain_control:e.automaticGainControl,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,qos:e.qos,silence_warning:e.silenceWarning,deaf:e.deaf,mute:e.mute,input:e.input?{device_id:e.input.device,volume:e.input.volume}:void 0,output:e.output?{device_id:e.output.device,volume:e.output.volume}:void 0,mode:e.mode?{mode:e.mode.type,auto_threshold:e.mode.autoThreshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}:void 0})}captureShortcut(e){const t=d(u.CAPTURE_SHORTCUT_CHANGE),s=()=>(this._subscriptions.delete(t),this.request(a.CAPTURE_SHORTCUT,{action:"STOP"}));return this._subscriptions.set(t,({shortcut:t})=>{e(t,s)}),this.request(a.CAPTURE_SHORTCUT,{action:"START"}).then(()=>s)}setActivity(e={},t=h()){let s,n,i,r;if(e.startTimestamp||e.endTimestamp){if((s={start:e.startTimestamp,end:e.endTimestamp}).start instanceof Date&&(s.start=Math.round(s.start.getTime()/1e3)),s.end instanceof Date&&(s.end=Math.round(s.end.getTime()/1e3)),s.start>2147483647)throw new RangeError("timestamps.start must fit into a unix timestamp");if(s.end>2147483647)throw new RangeError("timestamps.end must fit into a unix timestamp")}return(e.largeImageKey||e.largeImageText||e.smallImageKey||e.smallImageText)&&(n={large_image:e.largeImageKey,large_text:e.largeImageText,small_image:e.smallImageKey,small_text:e.smallImageText}),(e.partySize||e.partyId||e.partyMax)&&(i={id:e.partyId},(e.partySize||e.partyMax)&&(i.size=[e.partySize,e.partyMax])),(e.matchSecret||e.joinSecret||e.spectateSecret)&&(r={match:e.matchSecret,join:e.joinSecret,spectate:e.spectateSecret}),this.request(a.SET_ACTIVITY,{pid:t,activity:{state:e.state,details:e.details,timestamps:s,assets:n,party:i,secrets:r,instance:!!e.instance}})}clearActivity(e=h()){return this.request(a.SET_ACTIVITY,{pid:e})}sendJoinInvite(e){return this.request(a.SEND_ACTIVITY_JOIN_INVITE,{user_id:e.id||e})}sendJoinRequest(e){return this.request(a.SEND_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}closeJoinRequest(e){return this.request(a.CLOSE_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}async createLobby(e,t,s){return this.request(a.CREATE_LOBBY,{type:e,capacity:t,metadata:s})}async updateLobby(e,{type:t,owner:s,capacity:n,metadata:i}={}){return this.request(a.UPDATE_LOBBY,{id:e.id||e,type:t,owner_id:s&&s.id||s,capacity:n,metadata:i})}deleteLobby(e){return this.request(a.DELETE_LOBBY,{id:e.id||e})}async connectToLobby(e,t){return this.request(a.CONNECT_TO_LOBBY,{id:e,secret:t})}sendToLobby(e,t){return this.request(a.SEND_TO_LOBBY,{id:e.id||e,data:t})}disconnectFromLobby(e){return this.request(a.DISCONNECT_FROM_LOBBY,{id:e.id||e})}updateLobbyMember(e,t,s){return this.request(a.UPDATE_LOBBY_MEMBER,{lobby_id:e.id||e,user_id:t.id||t,metadata:s})}subscribe(e,t,s){return s||"function"!=typeof t||(s=t,t=void 0),this.request(a.SUBSCRIBE,t,e).then(()=>{const n=d(e,t);return this._subscriptions.set(n,s),{unsubscribe:()=>this.request(a.UNSUBSCRIBE,t,e).then(()=>this._subscriptions.delete(n))}})}async destroy(){this.transport.close()}}},function(e,t,s){(function(e){var n=void 0!==e&&e||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function r(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new r(i.call(setTimeout,n,arguments),clearTimeout)},t.setInterval=function(){return new r(i.call(setInterval,n,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},r.prototype.unref=r.prototype.ref=function(){},r.prototype.close=function(){this._clearFn.call(n,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},s(9),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(t,s(2))},function(e,t,s){(function(e){!function(e,t){"use strict";if(!e.setImmediate){var s,n=1,i={},r=!1,o=e.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(e);c=c&&c.setTimeout?c:e,"[object process]"==={}.toString.call(e.process)?s=function(e){process.nextTick(function(){u(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,s=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=s,t}}()?function(){var t="setImmediate$"+Math.random()+"$",n=function(s){s.source===e&&"string"==typeof s.data&&0===s.data.indexOf(t)&&u(+s.data.slice(t.length))};e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),s=function(s){e.postMessage(t+s,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){u(e.data)},s=function(t){e.port2.postMessage(t)}}():o&&"onreadystatechange"in o.createElement("script")?function(){var e=o.documentElement;s=function(t){var s=o.createElement("script");s.onreadystatechange=function(){u(t),s.onreadystatechange=null,e.removeChild(s),s=null},e.appendChild(s)}}():s=function(e){setTimeout(u,0,e)},c.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r<t.length;r++)t[r]=arguments[r+1];var o={callback:e,args:t};return i[n]=o,s(n),n++},c.clearImmediate=a}function a(e){delete i[e]}function u(e){if(r)setTimeout(u,0,e);else{var s=i[e];if(s){r=!0;try{!function(e){var s=e.callback,n=e.args;switch(n.length){case 0:s();break;case 1:s(n[0]);break;case 2:s(n[0],n[1]);break;case 3:s(n[0],n[1],n[2]);break;default:s.apply(t,n)}}(s)}finally{a(e),r=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(t,s(2))},function(e,t){e.exports=t=window.fetch,t.default=window.fetch.bind(window),t.Headers=window.Headers,t.Request=window.Request,t.Response=window.Response},function(e,t,s){"use strict";e.exports={ipc:s(12),websocket:s(13)}},function(e,t){},function(e,t,s){"use strict";const n=s(0),i=s(14),r=e=>JSON.stringify(e),o=e=>JSON.parse(e);e.exports=class extends n{constructor(e){super(),this.client=e,this.ws=null,this.tries=0}async connect(e,t=this.tries){if(this.connected)return;const s=6463+t%10;this.hostAndPort=`127.0.0.1:${s}`;const n=this.ws=new i(`ws://${this.hostAndPort}/?v=1&client_id=${this.client.clientId}`);n.onopen=this.onOpen.bind(this),n.onclose=n.onerror=this.onClose.bind(this),n.onmessage=this.onMessage.bind(this)}send(e){this.ws&&this.ws.send(r(e))}close(){this.ws&&this.ws.close()}ping(){}onMessage(e){this.emit("message",o(e.data))}onOpen(){this.client.rest.endpoint=`http://${this.hostAndPort}`,this.client.rest.versioned=!1,this.emit("open")}onClose(e){try{this.ws.close()}catch(e){}const t=e.code>=4e3&&e.code<5e3;e.code&&!t||this.emit("close",e),t||setTimeout(()=>this.connect(void 0,1006===e.code?++this.tries:0),250)}}},function(e,t){},function(e,t,s){"use strict";function n(e){const t={};for(const s of e)t[s]=s;return t}t.RPCCommands=n(["DISPATCH","AUTHORIZE","AUTHENTICATE","GET_GUILD","GET_GUILDS","GET_CHANNEL","GET_CHANNELS","SUBSCRIBE","UNSUBSCRIBE","SET_USER_VOICE_SETTINGS","SELECT_VOICE_CHANNEL","GET_SELECTED_VOICE_CHANNEL","SELECT_TEXT_CHANNEL","GET_VOICE_SETTINGS","SET_VOICE_SETTINGS","CAPTURE_SHORTCUT","SET_CERTIFIED_DEVICES","SET_ACTIVITY","SEND_ACTIVITY_JOIN_INVITE","SEND_ACTIVITY_JOIN_REQUEST","CLOSE_ACTIVITY_JOIN_REQUEST","CREATE_LOBBY","UPDATE_LOBBY","DELETE_LOBBY","UPDATE_LOBBY_MEMBER","CONNECT_TO_LOBBY","DISCONNECT_FROM_LOBBY","SEND_TO_LOBBY","INVITE_BROWSER","DEEP_LINK","CONNECTIONS_CALLBACK","OVERLAY","BROWSER_HANDOFF"]),t.RPCEvents=n(["GUILD_STATUS","GUILD_CREATE","CHANNEL_CREATE","VOICE_CHANNEL_SELECT","VOICE_STATE_CREATE","VOICE_STATE_DELETE","VOICE_STATE_UPDATE","VOICE_SETTINGS_UPDATE","VOICE_CONNECTION_STATUS","SPEAKING_START","SPEAKING_STOP","GAME_JOIN","GAME_SPECTATE","ACTIVITY_JOIN","ACTIVITY_JOIN_REQUEST","ACTIVITY_SPECTATE","NOTIFICATION_CREATE","MESSAGE_CREATE","MESSAGE_UPDATE","MESSAGE_DELETE","CAPTURE_SHORTCUT_CHANGE","LOBBY_DELETE","LOBBY_UPDATE","LOBBY_MEMBER_CONNECT","LOBBY_MEMBER_DISCONNECT","LOBBY_MEMBER_UPDATE","LOBBY_MESSAGE","OVERLAY","READY","ERROR"]),t.RPCErrors={UNKNOWN_ERROR:1e3,INVALID_PAYLOAD:4e3,INVALID_VERSION:4001,INVALID_COMMAND:4002,INVALID_GUILD:4003,INVALID_EVENT:4004,INVALID_CHANNEL:4005,INVALID_PERMISSIONS:4006,INVALID_CLIENTID:4007,INVALID_ORIGIN:4008,INVALID_TOKEN:4009,INVALID_USER:4010,INVALID_INVITE:4011,INVALID_ACTIVITY_JOIN_REQUEST:4012,INVALID_LOBBY:4013,INVALID_LOBBY_SECRET:4014,OAUTH2_ERROR:5e3,SELECT_CHANNEL_TIMED_OUT:5001,GET_GUILD_TIMED_OUT:5002,SELECT_VOICE_FORCE_REQUIRED:5003,CAPTURE_SHORTCUT_ALREADY_LISTENING:5004,INVALID_ACTIVITY_SECRET:5005,NO_ELIGIBLE_ACTIVITY:5006,LOBBY_FULL:5007},t.RPCCloseCodes={CLOSE_NORMAL:1e3,CLOSE_UNSUPPORTED:1003,CLOSE_ABNORMAL:1006,INVALID_CLIENTID:4e3,INVALID_ORIGIN:4001,RATELIMITED:4002,TOKEN_REVOKED:4003,INVALID_VERSION:4004,INVALID_ENCODING:4005},t.LobbyTypes={PRIVATE:1,PUBLIC:2}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DiscordRichPresence=t():e.DiscordRichPresence=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function s(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,n){s.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:n})},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=3)}([function(e,t){function s(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"object"==typeof e&&null!==e}function r(e){return void 0===e}e.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0,s.defaultMaxListeners=10,s.prototype.setMaxListeners=function(e){if(!function(e){return"number"==typeof e}(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},s.prototype.emit=function(e){var t,s,o,c,a,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(r(s=this._events[e]))return!1;if(n(s))switch(arguments.length){case 1:s.call(this);break;case 2:s.call(this,arguments[1]);break;case 3:s.call(this,arguments[1],arguments[2]);break;default:c=Array.prototype.slice.call(arguments,1),s.apply(this,c)}else if(i(s))for(c=Array.prototype.slice.call(arguments,1),o=(u=s.slice()).length,a=0;a<o;a++)u[a].apply(this,c);return!0},s.prototype.addListener=function(e,t){var o;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(o=r(this._maxListeners)?s.defaultMaxListeners:this._maxListeners)&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},s.prototype.on=s.prototype.addListener,s.prototype.once=function(e,t){if(!n(t))throw TypeError("listener must be a function");var s=!1;function i(){this.removeListener(e,i),s||(s=!0,t.apply(this,arguments))}return i.listener=t,this.on(e,i),this},s.prototype.removeListener=function(e,t){var s,r,o,c;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(o=(s=this._events[e]).length,r=-1,s===t||n(s.listener)&&s.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(s)){for(c=o;c-- >0;)if(s[c]===t||s[c].listener&&s[c].listener===t){r=c;break}if(r<0)return this;1===s.length?(s.length=0,delete this._events[e]):s.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},s.prototype.removeAllListeners=function(e){var t,s;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n(s=this._events[e]))this.removeListener(e,s);else if(s)for(;s.length;)this.removeListener(e,s[s.length-1]);return delete this._events[e],this},s.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},s.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},s.listenerCount=function(e,t){return e.listenerCount(t)}},function(e,t,s){"use strict";let n;try{const{app:e}=s(5);n=e.setAsDefaultProtocolClient.bind(e)}catch(e){try{n=s(6)}catch(e){}}"function"!=typeof n&&(n=(()=>!1));e.exports={pid:function(){return"undefined"!=typeof process?process.pid:null},register:n,uuid:()=>{let e="";for(let t=0;t<32;t+=1){let s;if(8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),12===t)s=4;else{const e=16*Math.random()|0;s=16===t?3&e|0:e}e+=s.toString(16)}return e}}},function(e,t){var s;s=function(){return this}();try{s=s||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(s=window)}e.exports=s},function(e,t,s){"use strict";const n=s(4),i=s(0),r="undefined"!=typeof window;e.exports=function(e){const t=new n.Client({transport:r?"websocket":"ipc"});let s=!1,o=null;const c=new class extends i{updatePresence(e){s?t.setActivity(e).catch(e=>this.emit("error",e)):o=e}reply(e,s){const n=e=>this.emit("error",e);switch(s){case"YES":t.sendJoinInvite(e).catch(n);break;case"NO":case"IGNORE":t.closeJoinRequest(e).catch(n);break;default:throw new RangeError("unknown response")}}disconnect(){t.destroy().catch(e=>this.emit("error",e))}};return t.on("error",e=>c.emit("error",e)),t.login({clientId:e}).then(()=>{c.emit("connected"),s=!0,t.subscribe("ACTIVITY_JOIN",({secret:e})=>{c.emit("join",e)}),t.subscribe("ACTIVITY_SPECTATE",({secret:e})=>{c.emit("spectate",e)}),t.subscribe("ACTIVITY_JOIN_REQUEST",e=>{c.emit("joinRequest",e)}),o&&(t.setActivity(o).catch(e=>c.emit("error",e)),o=null)}).catch(e=>c.emit("error",e)),c}},function(e,t,s){"use strict";const n=s(1);e.exports={Client:s(7),register:e=>n.register(`discord-${e}`)}},function(e,t){},function(e,t){},function(e,t,s){"use strict";const n=s(0),{setTimeout:i,clearTimeout:r}=s(8),o=s(10),c=s(11),{RPCCommands:a,RPCEvents:u}=s(15),{pid:h,uuid:l}=s(1);function d(e,t){return`${e}${JSON.stringify(t)}`}e.exports=class extends n{constructor(e={}){super(),this.options=e,this.accessToken=null,this.clientId=null,this.application=null,this.user=null;const t=c[e.transport];if(!t)throw new TypeError("RPC_INVALID_TRANSPORT",e.transport);this.fetch=((e,t,{data:s,query:n}={})=>o(`${this.fetch.endpoint}${t}${n?new URLSearchParams(n):""}`,{method:e,body:s,headers:{Authorzation:`Bearer ${this.accessToken}`}}).then(e=>e.json())),this.fetch.endpoint="https://discordapp.com/api",this.transport=new t(this),this.transport.on("message",this._onRpcMessage.bind(this)),this._expecting=new Map,this._subscriptions=new Map,this._connectPromise=void 0}connect(e){return this._connectPromise?this._connectPromise:(this._connectPromise=new Promise((t,s)=>{this.clientId=e;const n=i(()=>s(new Error("RPC_CONNECTION_TIMEOUT")),1e4);n.unref(),this.once("connected",()=>{r(n),t(this)}),this.transport.once("close",s),this.transport.connect().catch(s)}),this._connectPromise)}async login(e={}){let{clientId:t,accessToken:s}=e;return await this.connect(t),e.scopes?(s||(s=await this.authorize(e)),this.authenticate(s)):(this.emit("ready"),this)}request(e,t,s){return new Promise((n,i)=>{const r=l();this.transport.send({cmd:e,args:t,evt:s,nonce:r}),this._expecting.set(r,{resolve:n,reject:i})})}_onRpcMessage(e){if(e.cmd===a.DISPATCH&&e.evt===u.READY)e.data.user&&(this.user=e.data.user),this.emit("connected");else if(this._expecting.has(e.nonce)){const{resolve:t,reject:s}=this._expecting.get(e.nonce);if("ERROR"===e.evt){const t=new Error(e.data.message);t.code=e.data.code,t.data=e.data,s(t)}else t(e.data);this._expecting.delete(e.nonce)}else{const t=d(e.evt,e.args);if(!this._subscriptions.has(t))return;this._subscriptions.get(t)(e.data)}}async authorize({scopes:e,clientSecret:t,rpcToken:s,redirectUri:n}={}){t&&!0===s&&(s=(await this.fetch("POST","/oauth2/token/rpc",{data:new URLSearchParams({client_id:this.clientId,client_secret:t})})).rpc_token);const{code:i}=await this.request("AUTHORIZE",{scopes:e,client_id:this.clientId,rpc_token:s,redirect_uri:n});return(await this.fetch("POST","/oauth2/token",{data:new URLSearchParams({client_id:this.clientId,code:i,grant_type:"authorization_code",redirect_uri:n})})).access_token}authenticate(e){return this.request("AUTHENTICATE",{access_token:e}).then(({application:t,user:s})=>(this.accessToken=e,this.application=t,this.user=s,this.emit("ready"),this))}getGuild(e,t){return this.request(a.GET_GUILD,{guild_id:e,timeout:t})}getGuilds(e){return this.request(a.GET_GUILDS,{timeout:e})}getChannel(e,t){return this.request(a.GET_CHANNEL,{channel_id:e,timeout:t})}async getChannels(e,t){const{channels:s}=await this.request(a.GET_CHANNELS,{timeout:t,guild_id:e});return s}setCertifiedDevices(e){return this.request(a.SET_CERTIFIED_DEVICES,{devices:e.map(e=>({type:e.type,id:e.uuid,vendor:e.vendor,model:e.model,related:e.related,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,automatic_gain_control:e.automaticGainControl,hardware_mute:e.hardwareMute}))})}setUserVoiceSettings(e,t){return this.request(a.SET_USER_VOICE_SETTINGS,{user_id:e,pan:t.pan,mute:t.mute,volume:t.volume})}selectVoiceChannel(e,{timeout:t,force:s=!1}={}){return this.request(a.SELECT_VOICE_CHANNEL,{channel_id:e,timeout:t,force:s})}selectTextChannel(e,{timeout:t,force:s=!1}={}){return this.request(a.SELECT_TEXT_CHANNEL,{channel_id:e,timeout:t,force:s})}getVoiceSettings(){return this.request(a.GET_VOICE_SETTINGS).then(e=>({automaticGainControl:e.automatic_gain_control,echoCancellation:e.echo_cancellation,noiseSuppression:e.noise_suppression,qos:e.qos,silenceWarning:e.silence_warning,deaf:e.deaf,mute:e.mute,input:{availableDevices:e.input.available_devices,device:e.input.device_id,volume:e.input.volume},output:{availableDevices:e.output.available_devices,device:e.output.device_id,volume:e.output.volume},mode:{type:e.mode.type,autoThreshold:e.mode.auto_threshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}}))}setVoiceSettings(e){return this.request(a.SET_VOICE_SETTINGS,{automatic_gain_control:e.automaticGainControl,echo_cancellation:e.echoCancellation,noise_suppression:e.noiseSuppression,qos:e.qos,silence_warning:e.silenceWarning,deaf:e.deaf,mute:e.mute,input:e.input?{device_id:e.input.device,volume:e.input.volume}:void 0,output:e.output?{device_id:e.output.device,volume:e.output.volume}:void 0,mode:e.mode?{mode:e.mode.type,auto_threshold:e.mode.autoThreshold,threshold:e.mode.threshold,shortcut:e.mode.shortcut,delay:e.mode.delay}:void 0})}captureShortcut(e){const t=d(u.CAPTURE_SHORTCUT_CHANGE),s=()=>(this._subscriptions.delete(t),this.request(a.CAPTURE_SHORTCUT,{action:"STOP"}));return this._subscriptions.set(t,({shortcut:t})=>{e(t,s)}),this.request(a.CAPTURE_SHORTCUT,{action:"START"}).then(()=>s)}setActivity(e={},t=h()){let s,n,i,r;if(e.startTimestamp||e.endTimestamp){if((s={start:e.startTimestamp,end:e.endTimestamp}).start instanceof Date&&(s.start=Math.round(s.start.getTime()/1e3)),s.end instanceof Date&&(s.end=Math.round(s.end.getTime()/1e3)),s.start>2147483647)throw new RangeError("timestamps.start must fit into a unix timestamp");if(s.end>2147483647)throw new RangeError("timestamps.end must fit into a unix timestamp")}return(e.largeImageKey||e.largeImageText||e.smallImageKey||e.smallImageText)&&(n={large_image:e.largeImageKey,large_text:e.largeImageText,small_image:e.smallImageKey,small_text:e.smallImageText}),(e.partySize||e.partyId||e.partyMax)&&(i={id:e.partyId},(e.partySize||e.partyMax)&&(i.size=[e.partySize,e.partyMax])),(e.matchSecret||e.joinSecret||e.spectateSecret)&&(r={match:e.matchSecret,join:e.joinSecret,spectate:e.spectateSecret}),this.request(a.SET_ACTIVITY,{pid:t,activity:{state:e.state,details:e.details,timestamps:s,assets:n,party:i,secrets:r,instance:!!e.instance}})}clearActivity(e=h()){return this.request(a.SET_ACTIVITY,{pid:e})}sendJoinInvite(e){return this.request(a.SEND_ACTIVITY_JOIN_INVITE,{user_id:e.id||e})}sendJoinRequest(e){return this.request(a.SEND_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}closeJoinRequest(e){return this.request(a.CLOSE_ACTIVITY_JOIN_REQUEST,{user_id:e.id||e})}async createLobby(e,t,s){return this.request(a.CREATE_LOBBY,{type:e,capacity:t,metadata:s})}async updateLobby(e,{type:t,owner:s,capacity:n,metadata:i}={}){return this.request(a.UPDATE_LOBBY,{id:e.id||e,type:t,owner_id:s&&s.id||s,capacity:n,metadata:i})}deleteLobby(e){return this.request(a.DELETE_LOBBY,{id:e.id||e})}async connectToLobby(e,t){return this.request(a.CONNECT_TO_LOBBY,{id:e,secret:t})}sendToLobby(e,t){return this.request(a.SEND_TO_LOBBY,{id:e.id||e,data:t})}disconnectFromLobby(e){return this.request(a.DISCONNECT_FROM_LOBBY,{id:e.id||e})}updateLobbyMember(e,t,s){return this.request(a.UPDATE_LOBBY_MEMBER,{lobby_id:e.id||e,user_id:t.id||t,metadata:s})}subscribe(e,t,s){return s||"function"!=typeof t||(s=t,t=void 0),this.request(a.SUBSCRIBE,t,e).then(()=>{const n=d(e,t);return this._subscriptions.set(n,s),{unsubscribe:()=>this.request(a.UNSUBSCRIBE,t,e).then(()=>this._subscriptions.delete(n))}})}async destroy(){this.transport.close()}}},function(e,t,s){(function(e){var n=void 0!==e&&e||"undefined"!=typeof self&&self||window,i=Function.prototype.apply;function r(e,t){this._id=e,this._clearFn=t}t.setTimeout=function(){return new r(i.call(setTimeout,n,arguments),clearTimeout)},t.setInterval=function(){return new r(i.call(setInterval,n,arguments),clearInterval)},t.clearTimeout=t.clearInterval=function(e){e&&e.close()},r.prototype.unref=r.prototype.ref=function(){},r.prototype.close=function(){this._clearFn.call(n,this._id)},t.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},t.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},t._unrefActive=t.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;t>=0&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},s(9),t.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==e&&e.setImmediate||this&&this.setImmediate,t.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==e&&e.clearImmediate||this&&this.clearImmediate}).call(t,s(2))},function(e,t,s){(function(e){!function(e,t){"use strict";if(!e.setImmediate){var s,n=1,i={},r=!1,o=e.document,c=Object.getPrototypeOf&&Object.getPrototypeOf(e);c=c&&c.setTimeout?c:e,"[object process]"==={}.toString.call(e.process)?s=function(e){process.nextTick(function(){u(e)})}:function(){if(e.postMessage&&!e.importScripts){var t=!0,s=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=s,t}}()?function(){var t="setImmediate$"+Math.random()+"$",n=function(s){s.source===e&&"string"==typeof s.data&&0===s.data.indexOf(t)&&u(+s.data.slice(t.length))};e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),s=function(s){e.postMessage(t+s,"*")}}():e.MessageChannel?function(){var e=new MessageChannel;e.port1.onmessage=function(e){u(e.data)},s=function(t){e.port2.postMessage(t)}}():o&&"onreadystatechange"in o.createElement("script")?function(){var e=o.documentElement;s=function(t){var s=o.createElement("script");s.onreadystatechange=function(){u(t),s.onreadystatechange=null,e.removeChild(s),s=null},e.appendChild(s)}}():s=function(e){setTimeout(u,0,e)},c.setImmediate=function(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),r=0;r<t.length;r++)t[r]=arguments[r+1];var o={callback:e,args:t};return i[n]=o,s(n),n++},c.clearImmediate=a}function a(e){delete i[e]}function u(e){if(r)setTimeout(u,0,e);else{var s=i[e];if(s){r=!0;try{!function(e){var s=e.callback,n=e.args;switch(n.length){case 0:s();break;case 1:s(n[0]);break;case 2:s(n[0],n[1]);break;case 3:s(n[0],n[1],n[2]);break;default:s.apply(t,n)}}(s)}finally{a(e),r=!1}}}}}("undefined"==typeof self?void 0===e?this:e:self)}).call(t,s(2))},function(e,t){e.exports=t=window.fetch,t.default=window.fetch.bind(window),t.Headers=window.Headers,t.Request=window.Request,t.Response=window.Response},function(e,t,s){"use strict";e.exports={ipc:s(12),websocket:s(13)}},function(e,t){},function(e,t,s){"use strict";const n=s(0),i=s(14),r=e=>JSON.stringify(e),o=e=>JSON.parse(e);e.exports=class extends n{constructor(e){super(),this.client=e,this.ws=null,this.tries=0}async connect(e,t=this.tries){if(this.connected)return;const s=6463+t%10;this.hostAndPort=`127.0.0.1:${s}`;const n=this.ws=new i(`ws://${this.hostAndPort}/?v=1&client_id=${this.client.clientId}`);n.onopen=this.onOpen.bind(this),n.onclose=n.onerror=this.onClose.bind(this),n.onmessage=this.onMessage.bind(this)}send(e){this.ws&&this.ws.send(r(e))}close(){this.ws&&this.ws.close()}ping(){}onMessage(e){this.emit("message",o(e.data))}onOpen(){this.client.rest.endpoint=`http://${this.hostAndPort}`,this.client.rest.versioned=!1,this.emit("open")}onClose(e){try{this.ws.close()}catch(e){}const t=e.code>=4e3&&e.code<5e3;e.code&&!t||this.emit("close",e),t||setTimeout(()=>this.connect(void 0,1006===e.code?++this.tries:0),250)}}},function(e,t){},function(e,t,s){"use strict";function n(e){const t={};for(const s of e)t[s]=s;return t}t.RPCCommands=n(["DISPATCH","AUTHORIZE","AUTHENTICATE","GET_GUILD","GET_GUILDS","GET_CHANNEL","GET_CHANNELS","SUBSCRIBE","UNSUBSCRIBE","SET_USER_VOICE_SETTINGS","SELECT_VOICE_CHANNEL","GET_SELECTED_VOICE_CHANNEL","SELECT_TEXT_CHANNEL","GET_VOICE_SETTINGS","SET_VOICE_SETTINGS","CAPTURE_SHORTCUT","SET_CERTIFIED_DEVICES","SET_ACTIVITY","SEND_ACTIVITY_JOIN_INVITE","SEND_ACTIVITY_JOIN_REQUEST","CLOSE_ACTIVITY_JOIN_REQUEST","CREATE_LOBBY","UPDATE_LOBBY","DELETE_LOBBY","UPDATE_LOBBY_MEMBER","CONNECT_TO_LOBBY","DISCONNECT_FROM_LOBBY","SEND_TO_LOBBY","INVITE_BROWSER","DEEP_LINK","CONNECTIONS_CALLBACK","OVERLAY","BROWSER_HANDOFF"]),t.RPCEvents=n(["GUILD_STATUS","GUILD_CREATE","CHANNEL_CREATE","VOICE_CHANNEL_SELECT","VOICE_STATE_CREATE","VOICE_STATE_DELETE","VOICE_STATE_UPDATE","VOICE_SETTINGS_UPDATE","VOICE_CONNECTION_STATUS","SPEAKING_START","SPEAKING_STOP","GAME_JOIN","GAME_SPECTATE","ACTIVITY_JOIN","ACTIVITY_JOIN_REQUEST","ACTIVITY_SPECTATE","NOTIFICATION_CREATE","MESSAGE_CREATE","MESSAGE_UPDATE","MESSAGE_DELETE","CAPTURE_SHORTCUT_CHANGE","LOBBY_DELETE","LOBBY_UPDATE","LOBBY_MEMBER_CONNECT","LOBBY_MEMBER_DISCONNECT","LOBBY_MEMBER_UPDATE","LOBBY_MESSAGE","OVERLAY","READY","ERROR"]),t.RPCErrors={UNKNOWN_ERROR:1e3,INVALID_PAYLOAD:4e3,INVALID_VERSION:4001,INVALID_COMMAND:4002,INVALID_GUILD:4003,INVALID_EVENT:4004,INVALID_CHANNEL:4005,INVALID_PERMISSIONS:4006,INVALID_CLIENTID:4007,INVALID_ORIGIN:4008,INVALID_TOKEN:4009,INVALID_USER:4010,INVALID_INVITE:4011,INVALID_ACTIVITY_JOIN_REQUEST:4012,INVALID_LOBBY:4013,INVALID_LOBBY_SECRET:4014,OAUTH2_ERROR:5e3,SELECT_CHANNEL_TIMED_OUT:5001,GET_GUILD_TIMED_OUT:5002,SELECT_VOICE_FORCE_REQUIRED:5003,CAPTURE_SHORTCUT_ALREADY_LISTENING:5004,INVALID_ACTIVITY_SECRET:5005,NO_ELIGIBLE_ACTIVITY:5006,LOBBY_FULL:5007},t.RPCCloseCodes={CLOSE_NORMAL:1e3,CLOSE_UNSUPPORTED:1003,CLOSE_ABNORMAL:1006,INVALID_CLIENTID:4e3,INVALID_ORIGIN:4001,RATELIMITED:4002,TOKEN_REVOKED:4003,INVALID_VERSION:4004,INVALID_ENCODING:4005},t.LobbyTypes={PRIVATE:1,PUBLIC:2}}])}); |
@@ -43,2 +43,4 @@ 'use strict'; | ||
rpc.on('error', (e) => instance.emit('error', e)); | ||
rpc.login({ clientId }) | ||
@@ -45,0 +47,0 @@ .then(() => { |
{ | ||
"name": "discord-rich-presence", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "rich presence wrapper for discord-rpc", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
23506
57