Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@roomservice/browser

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@roomservice/browser - npm Package Compare versions

Comparing version 1.0.0-10 to 1.0.0-11-staging

9

dist/browser.cjs.development.js

@@ -12,5 +12,8 @@ 'use strict';

// export const PRESENCE_URL = 'http://localhost:3454/presence';
var WS_URL = 'wss://super.roomservice.dev/ws';
var DOCS_URL = 'https://super.roomservice.dev/docs';
var PRESENCE_URL = 'https://super.roomservice.dev/presence';
// export const WS_URL = 'wss://super.roomservice.dev/ws';
// export const DOCS_URL = 'https://super.roomservice.dev/docs';
// export const PRESENCE_URL = 'https://super.roomservice.dev/presence';
var WS_URL = 'wss://super.stagingmcstagingface.com/ws';
var DOCS_URL = 'https://super.stagingmcstagingface.com/docs';
var PRESENCE_URL = 'https://super.stagingmcstagingface.com/presence';

@@ -17,0 +20,0 @@ var SuperlumeWebSocket = /*#__PURE__*/function () {

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("tiny-invariant"))&&"object"==typeof t&&"default"in t?t.default:t,r=function(){function t(t){var e=this;this.callbacks={},this.lastTime=0,this.msgsThisMilisecond=0,this.conn=t,this.conn.onmessage=function(t){var r=JSON.parse(t.data);e.dispatch(r.type,r.body)}}var e=t.prototype;return e.timestamp=function(){var t=Date.now();return t===this.lastTime?this.msgsThisMilisecond++:(this.lastTime=t,this.msgsThisMilisecond=0),t+":"+this.msgsThisMilisecond},e.send=function(t,e){var r=this.timestamp();this.conn.send(JSON.stringify({type:t,ts:r,ver:0,body:e}))},e.bind=function(t,e){return this.callbacks[t]=this.callbacks[t]||[],this.callbacks[t].push(e),e},e.unbind=function(t,e){this.callbacks[t]=this.callbacks[t].filter((function(t){return t!==e}))},e.dispatch=function(t,e){var r=this.callbacks[t];if(r)for(var n=0;n<r.length;n++)r[n](e)},t}();function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}function c(t,e){if("root"===e)return"root";var r=e.split(":");return r[0]+":"+t.actors[parseInt(r[1])]}var h=function(){function t(t){this.count=0,this.actor=t,this.nodes={},this.log=[]}var r=t.prototype;return r.import=function(t,r){t||e(!1);for(var n=t.lists[r],o=n.afters||[],i=n.ids||[],s=n.values||[],h=0;h<o.length;h++){var u={after:c(t,o[h]),id:c(t,i[h]),value:s[h]};this.nodes[u.id]=u,this.log.push(u)}this.count=this.log.length},r.get=function(t){if(this.nodes[t])return this.nodes[t].value},r.insert=function(t,r,n){this.log||e(!1);var o=n;o||(o=this.count+":"+this.actor),this.count++;var i={after:t,value:r,id:o};return this.nodes[o]=i,this.log.push(i),o},r.put=function(t,e){this.nodes[t]&&(this.nodes[t].value=e)},r.has=function(t){return!!this.nodes[t]},r.delete=function(t){this.nodes[t].value={t:""}},r.toTree=function(){for(var t,e={children:[],id:"root",value:""},r={root:e},n=s(this.log);!(t=n()).done;){var o=t.value,i={children:[],id:o.id,value:o.value};if(r[o.id]=i,"root"===o.after)e.children.push(i);else{if(!r[o.after])throw new Error("Unexpectedly missing node "+o.after);r[o.after].children.push(i)}}return e},r.sortLog=function(){this.log.sort((function(t,e){var r=t.id.split(":"),n=r[0],o=r[1],i=e.id.split(":"),s=i[0];return n===s?o.localeCompare(i[1]):parseInt(n)-parseInt(s)}))},r.lastID=function(){return 0===this.log.length?"root":(this.sortLog(),function t(e){return e.children&&0!==e.children.length?t(e.children[e.children.length-1]):e}(this.toTree()).id)},r.toArray=function(){return this.sortLog(),function t(e){if(!e.children||0===e.children.length)return[];for(var r,n=[],o=s(e.children);!(r=o()).done;){var i=r.value,c=i.value;if("string"!=typeof i.value){if(""===i.value.t){n=n.concat([].concat(t(i)));continue}throw new Error("Unimplemented")}n=n.concat([c].concat(t(i)))}return n}(this.toTree())},o(t,[{key:"length",get:function(){return Object.keys(this.nodes).length}}]),t}();function u(t){return"number"==typeof t?""+t:'"'+t+'"'}function a(t){return t.length>=2&&'"'===t[0]&&'"'===t[t.length-1]?t.slice(1,t.length-1):parseInt(t)}var d=function(){function t(t,r,n,o,i,s){this.itemIDs=[],this.roomID=r,this.docID=n,this.id=o,this.ws=i,this.rt=new h(s),t.lists[o]||e(!1),this.rt.import(t,o);for(var u=t.lists[o].ids||[],a=0;a<u.length;a++)this.itemIDs.push(c(t,u[a]))}var r=t.prototype;return r.sendCmd=function(t){this.ws.send("doc:cmd",{room:this.roomID,args:t})},r.clone=function(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)},r.update=function(t){if(t.length<3)throw new Error("Unexpected command: "+t);var e=t[0];if(t[1]!==this.docID||t[2]!==this.id)throw new Error("Command unexpectedly routed to the wrong client");switch(e){case"lins":this.rt.insert(t[3],t[5],t[4]);break;case"lput":this.rt.put(t[3],t[4]);break;case"ldel":this.rt.delete(t[3]);break;default:throw new Error("Unexpected command keyword: "+e)}return this.clone()},r.get=function(t){var e=this.itemIDs[t];if(e){var r=this.rt.get(e);if(r){if("object"==typeof r){if(""===r.t)return;throw new Error("Unimplemented references")}return a(r)}}},r.set=function(t,e){var r=this.itemIDs[t];if(!r)throw new Error("Unexpected");var n=u(e);return this.rt.put(r,n),this.sendCmd(["lput",this.docID,this.id,r,n]),this.clone()},r.delete=function(t){var e=this.itemIDs[t];return e?(this.rt.delete(e),this.sendCmd(["ldel",this.docID,this.id,e]),Object.assign(Object.create(Object.getPrototypeOf(this)),this),this.clone()):Object.assign({},this)},r.insertAfter=function(t,e){var r=this.itemIDs[t];if(!r)throw new RangeError("List '"+this.id+"' has no index: '"+t+"'");var n=u(e),o=this.rt.insert(r,n);return this.itemIDs.splice(t,0,o),this.sendCmd(["lins",this.docID,this.id,r,o,n]),this.clone()},r.push=function(t){var e=this.rt.lastID(),r=u(t),n=this.rt.insert(e,r);return this.itemIDs.push(n),this.sendCmd(["lins",this.docID,this.id,e,n,r]),this.clone()},r.toArray=function(){return this.rt.toArray().map((function(t){return a(t)}))},t}(),f=function(){function t(t,e,r,n,o){for(var i in this.roomID=e,this.docID=r,this.id=n,this.ws=o,this.store={},t){var s=t[i];"string"==typeof s&&(this.store[i]=unescape(s))}}var e=t.prototype;return e.sendCmd=function(t){this.ws.send("doc:cmd",{room:this.roomID,args:t})},e.clone=function(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)},e.update=function(t){if(t.length<3)throw new Error("Unexpected command: "+t);var e=t[0];if(t[1]!==this.docID||t[2]!==this.id)throw new Error("Command unexpectedly routed to the wrong client");switch(e){case"mput":if(5!==t.length){console.error("Malformed command ",t);break}this.store[t[3]]=t[4];break;case"mdel":if(4!==t.length){console.error("Malformed command ",t);break}delete this.store[t[3]];break;default:throw new Error("Unexpected command keyword: "+e)}return this.clone()},e.get=function(t){return this.store[t]},e.set=function(t,e){var r=u(e);return this.store[t]=e,this.sendCmd(["mput",this.docID,this.id,t,r]),this.clone()},e.delete=function(t){return delete this.store[t],this.sendCmd(["mdel",this.docID,this.id,t]),this.clone()},t}(),l=function(){function t(t,e,r,n){this.roomID=t,this.ws=e,this.actor=r,this.token=n,this.cache={},this.send=function(t,e,r){void 0===r&&(r=!1);var n=null,o=!0;return function(){var e=arguments,i=this,s=r&&o,c=function(){t.apply(i,e),n=null};s&&(o=!1,c()),n||(n=setTimeout(c,40))}}(this.ws.send.bind(this.ws))}var e=t.prototype;return e.getAll=function(t){try{var e=this;return Promise.resolve(function(t,e,r,n){try{return Promise.resolve(fetch("https://super.roomservice.dev/presence/"+r+"/"+encodeURIComponent(n),{headers:{Authorization:"Bearer: "+e}})).then((function(t){return Promise.resolve(t.json())}))}catch(t){return Promise.reject(t)}}(0,e.token,e.roomID,t)).then((function(r){return e.cache[t]=r,e.withoutExpired(t)}))}catch(t){return Promise.reject(t)}},e.withoutExpired=function(t){var e={};for(var r in this.cache[t]){var n=this.cache[t][r];new Date>n.expAt?delete this.cache[t][r]:e[r]=n.value}return e},e.set=function(t,e,r){var n=r||60,o=Math.round((new Date).getTime()/1e3)+n;return this.send("presence:cmd",{room:this.roomID,key:t,value:JSON.stringify(e),expAt:o}),this.cache[t]||(this.cache[t]={}),this.cache[t][this.actor]={value:e,expAt:new Date(1e3*o)},this.withoutExpired(t)},e.update=function(t){if(t.room===this.roomID&&t.from!==this.actor){var e={expAt:new Date(1e3*t.expAt),value:JSON.parse(t.value)};return this.cache[t.key]||(this.cache[t.key]={}),this.cache[t.key][t.from]=e,this.withoutExpired(t.key)}},o(t,[{key:"me",get:function(){return this.actor}}]),t}(),m=function(){function t(t){this.ws=new r(t.conn),this.token=t.token,this.roomID=t.roomID,this.docID=t.checkpoint.id,this.actor=t.actor,this.checkpoint=t.checkpoint}var n=t.prototype;return n.once=function(t){try{var e,r=this;return Promise.race([new Promise((function(t,e){return setTimeout((function(){return e("timeout")}),2e3)})),new Promise((function(n){e=r.ws.bind(t,(function(t){n(t)}))}))]).then((function(){e&&r.ws.unbind(t,e)}))}catch(t){return Promise.reject(t)}},n.reconnect=function(){try{var t=this;t.errorListener||(t.errorListener=t.ws.bind("error",(function(t){console.error("Room Service encountered a server-side error. If you see this, please let us know; this could be a bug.",t)})));var e=t.once("guest:authenticated");return t.ws.send("guest:authenticate",t.token),Promise.resolve(e).then((function(){var e=t.once("room:joined");return t.ws.send("room:join",t.roomID),Promise.resolve(e).then((function(){}))}))}catch(t){return Promise.reject(t)}},n.list=function(t){try{this.checkpoint.lists[t]||(this.ws.send("doc:cmd",{args:["lcreate",this.docID,t],room:this.roomID}),this.checkpoint.lists[t]={afters:[],ids:[],values:[]});var e=new d(this.checkpoint,this.roomID,this.docID,t,this.ws,this.actor);return Promise.resolve(e)}catch(t){return Promise.reject(t)}},n.map=function(t){try{this.checkpoint.maps[t]||this.ws.send("doc:cmd",{args:["mcreate",this.docID,t],room:this.roomID});var e=new f(this.checkpoint.maps[t]||{},this.roomID,this.docID,t,this.ws);return Promise.resolve(e)}catch(t){return Promise.reject(t)}},n.presence=function(){try{var t=new l(this.roomID,this.ws,this.actor,this.token);return Promise.resolve(t)}catch(t){return Promise.reject(t)}},n.subscribe=function(t,r,n){var o=this;return"string"==typeof r?(t||e(!1),this.ws.bind("presence:fwd",(function(i){if(i.room===o.roomID&&i.key===r&&i.from!==o.actor){var s=t.update(i);n||e(!1),n(s,i.from)}}))):this.ws.bind("doc:fwd",(function(e){if(e.room===o.roomID)if(!e.args||e.args.length<3)console.error("Unexpected command: ",e.args);else if(e.from!==o.actor){var n=[e.args[1],e.args[2]];if(n[0]===o.docID&&n[1]===t.id){var i=t.update(e.args);r(i,e.from)}}}))},n.unsubscribe=function(t){this.ws.unbind("doc:fwd",t)},t}();exports.RoomService=function(){function t(t){this.auth=t.auth}return t.prototype.room=function(t){try{var e=new WebSocket("wss://super.roomservice.dev/ws");return Promise.resolve(function(t,e,r,n,o){try{return Promise.resolve(function(t,e,r){try{var n=function(r){if(o)return r;var n=t;return Promise.resolve(fetch(n,{method:"POST",body:JSON.stringify({resources:[{object:"document",reference:"default",permission:"read_write",room:e},{object:"room",reference:e,permission:"join"}]})})).then((function(t){if(401===t.status)throw new Error("AuthURL returned unauthorized");return Promise.resolve(t.json()).then((function(t){var e=t.token,r=t.user,o=t.resources;if(!o||!e||!r)throw new Error("Invalid response from the AuthURL: "+n);return{token:e,guestReference:r,docID:o.find((function(t){return"document"===t.object})).id,roomID:o.find((function(t){return"room"===t.object})).id}}))}))},o=!1,i=function(){if("function"==typeof t)return Promise.resolve(t(e)).then((function(t){if(!t.user)throw new Error("The auth function must return a 'user' key.");var e=t.resources.find((function(t){return"document"===t.object})).id,r=t.resources.find((function(t){return"room"===t.object})).id;return o=!0,{token:t.token,guestReference:t.user,docID:e,roomID:r}}))}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(t){return Promise.reject(t)}}(r,n)).then((function(e){return Promise.resolve(function(t,e,r){try{return Promise.resolve(fetch("https://super.roomservice.dev/docs/"+r,{headers:{Authorization:"Bearer: "+e}})).then((function(t){return Promise.resolve(t.json())}))}catch(t){return Promise.reject(t)}}(0,e.token,e.docID)).then((function(r){var n=new m({conn:t,actor:e.guestReference,checkpoint:r.body,token:e.token,roomID:e.roomID});return Promise.resolve(n.reconnect()).then((function(){return n}))}))}))}catch(t){return Promise.reject(t)}}(e,0,this.auth,t))}catch(t){return Promise.reject(t)}},t}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("tiny-invariant"))&&"object"==typeof t&&"default"in t?t.default:t,r=function(){function t(t){var e=this;this.callbacks={},this.lastTime=0,this.msgsThisMilisecond=0,this.conn=t,this.conn.onmessage=function(t){var r=JSON.parse(t.data);e.dispatch(r.type,r.body)}}var e=t.prototype;return e.timestamp=function(){var t=Date.now();return t===this.lastTime?this.msgsThisMilisecond++:(this.lastTime=t,this.msgsThisMilisecond=0),t+":"+this.msgsThisMilisecond},e.send=function(t,e){var r=this.timestamp();this.conn.send(JSON.stringify({type:t,ts:r,ver:0,body:e}))},e.bind=function(t,e){return this.callbacks[t]=this.callbacks[t]||[],this.callbacks[t].push(e),e},e.unbind=function(t,e){this.callbacks[t]=this.callbacks[t].filter((function(t){return t!==e}))},e.dispatch=function(t,e){var r=this.callbacks[t];if(r)for(var n=0;n<r.length;n++)r[n](e)},t}();function n(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function o(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}function c(t,e){if("root"===e)return"root";var r=e.split(":");return r[0]+":"+t.actors[parseInt(r[1])]}var h=function(){function t(t){this.count=0,this.actor=t,this.nodes={},this.log=[]}var r=t.prototype;return r.import=function(t,r){t||e(!1);for(var n=t.lists[r],o=n.afters||[],i=n.ids||[],s=n.values||[],h=0;h<o.length;h++){var u={after:c(t,o[h]),id:c(t,i[h]),value:s[h]};this.nodes[u.id]=u,this.log.push(u)}this.count=this.log.length},r.get=function(t){if(this.nodes[t])return this.nodes[t].value},r.insert=function(t,r,n){this.log||e(!1);var o=n;o||(o=this.count+":"+this.actor),this.count++;var i={after:t,value:r,id:o};return this.nodes[o]=i,this.log.push(i),o},r.put=function(t,e){this.nodes[t]&&(this.nodes[t].value=e)},r.has=function(t){return!!this.nodes[t]},r.delete=function(t){this.nodes[t].value={t:""}},r.toTree=function(){for(var t,e={children:[],id:"root",value:""},r={root:e},n=s(this.log);!(t=n()).done;){var o=t.value,i={children:[],id:o.id,value:o.value};if(r[o.id]=i,"root"===o.after)e.children.push(i);else{if(!r[o.after])throw new Error("Unexpectedly missing node "+o.after);r[o.after].children.push(i)}}return e},r.sortLog=function(){this.log.sort((function(t,e){var r=t.id.split(":"),n=r[0],o=r[1],i=e.id.split(":"),s=i[0];return n===s?o.localeCompare(i[1]):parseInt(n)-parseInt(s)}))},r.lastID=function(){return 0===this.log.length?"root":(this.sortLog(),function t(e){return e.children&&0!==e.children.length?t(e.children[e.children.length-1]):e}(this.toTree()).id)},r.toArray=function(){return this.sortLog(),function t(e){if(!e.children||0===e.children.length)return[];for(var r,n=[],o=s(e.children);!(r=o()).done;){var i=r.value,c=i.value;if("string"!=typeof i.value){if(""===i.value.t){n=n.concat([].concat(t(i)));continue}throw new Error("Unimplemented")}n=n.concat([c].concat(t(i)))}return n}(this.toTree())},o(t,[{key:"length",get:function(){return Object.keys(this.nodes).length}}]),t}();function u(t){return"number"==typeof t?""+t:'"'+t+'"'}function a(t){return t.length>=2&&'"'===t[0]&&'"'===t[t.length-1]?t.slice(1,t.length-1):parseInt(t)}var d=function(){function t(t,r,n,o,i,s){this.itemIDs=[],this.roomID=r,this.docID=n,this.id=o,this.ws=i,this.rt=new h(s),t.lists[o]||e(!1),this.rt.import(t,o);for(var u=t.lists[o].ids||[],a=0;a<u.length;a++)this.itemIDs.push(c(t,u[a]))}var r=t.prototype;return r.sendCmd=function(t){this.ws.send("doc:cmd",{room:this.roomID,args:t})},r.clone=function(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)},r.update=function(t){if(t.length<3)throw new Error("Unexpected command: "+t);var e=t[0];if(t[1]!==this.docID||t[2]!==this.id)throw new Error("Command unexpectedly routed to the wrong client");switch(e){case"lins":this.rt.insert(t[3],t[5],t[4]);break;case"lput":this.rt.put(t[3],t[4]);break;case"ldel":this.rt.delete(t[3]);break;default:throw new Error("Unexpected command keyword: "+e)}return this.clone()},r.get=function(t){var e=this.itemIDs[t];if(e){var r=this.rt.get(e);if(r){if("object"==typeof r){if(""===r.t)return;throw new Error("Unimplemented references")}return a(r)}}},r.set=function(t,e){var r=this.itemIDs[t];if(!r)throw new Error("Unexpected");var n=u(e);return this.rt.put(r,n),this.sendCmd(["lput",this.docID,this.id,r,n]),this.clone()},r.delete=function(t){var e=this.itemIDs[t];return e?(this.rt.delete(e),this.sendCmd(["ldel",this.docID,this.id,e]),Object.assign(Object.create(Object.getPrototypeOf(this)),this),this.clone()):Object.assign({},this)},r.insertAfter=function(t,e){var r=this.itemIDs[t];if(!r)throw new RangeError("List '"+this.id+"' has no index: '"+t+"'");var n=u(e),o=this.rt.insert(r,n);return this.itemIDs.splice(t,0,o),this.sendCmd(["lins",this.docID,this.id,r,o,n]),this.clone()},r.push=function(t){var e=this.rt.lastID(),r=u(t),n=this.rt.insert(e,r);return this.itemIDs.push(n),this.sendCmd(["lins",this.docID,this.id,e,n,r]),this.clone()},r.toArray=function(){return this.rt.toArray().map((function(t){return a(t)}))},t}(),f=function(){function t(t,e,r,n,o){for(var i in this.roomID=e,this.docID=r,this.id=n,this.ws=o,this.store={},t){var s=t[i];"string"==typeof s&&(this.store[i]=unescape(s))}}var e=t.prototype;return e.sendCmd=function(t){this.ws.send("doc:cmd",{room:this.roomID,args:t})},e.clone=function(){return Object.assign(Object.create(Object.getPrototypeOf(this)),this)},e.update=function(t){if(t.length<3)throw new Error("Unexpected command: "+t);var e=t[0];if(t[1]!==this.docID||t[2]!==this.id)throw new Error("Command unexpectedly routed to the wrong client");switch(e){case"mput":if(5!==t.length){console.error("Malformed command ",t);break}this.store[t[3]]=t[4];break;case"mdel":if(4!==t.length){console.error("Malformed command ",t);break}delete this.store[t[3]];break;default:throw new Error("Unexpected command keyword: "+e)}return this.clone()},e.get=function(t){return this.store[t]},e.set=function(t,e){var r=u(e);return this.store[t]=e,this.sendCmd(["mput",this.docID,this.id,t,r]),this.clone()},e.delete=function(t){return delete this.store[t],this.sendCmd(["mdel",this.docID,this.id,t]),this.clone()},t}(),l=function(){function t(t,e,r,n){this.roomID=t,this.ws=e,this.actor=r,this.token=n,this.cache={},this.send=function(t,e,r){void 0===r&&(r=!1);var n=null,o=!0;return function(){var e=arguments,i=this,s=r&&o,c=function(){t.apply(i,e),n=null};s&&(o=!1,c()),n||(n=setTimeout(c,40))}}(this.ws.send.bind(this.ws))}var e=t.prototype;return e.getAll=function(t){try{var e=this;return Promise.resolve(function(t,e,r,n){try{return Promise.resolve(fetch("https://super.stagingmcstagingface.com/presence/"+r+"/"+encodeURIComponent(n),{headers:{Authorization:"Bearer: "+e}})).then((function(t){return Promise.resolve(t.json())}))}catch(t){return Promise.reject(t)}}(0,e.token,e.roomID,t)).then((function(r){return e.cache[t]=r,e.withoutExpired(t)}))}catch(t){return Promise.reject(t)}},e.withoutExpired=function(t){var e={};for(var r in this.cache[t]){var n=this.cache[t][r];new Date>n.expAt?delete this.cache[t][r]:e[r]=n.value}return e},e.set=function(t,e,r){var n=r||60,o=Math.round((new Date).getTime()/1e3)+n;return this.send("presence:cmd",{room:this.roomID,key:t,value:JSON.stringify(e),expAt:o}),this.cache[t]||(this.cache[t]={}),this.cache[t][this.actor]={value:e,expAt:new Date(1e3*o)},this.withoutExpired(t)},e.update=function(t){if(t.room===this.roomID&&t.from!==this.actor){var e={expAt:new Date(1e3*t.expAt),value:JSON.parse(t.value)};return this.cache[t.key]||(this.cache[t.key]={}),this.cache[t.key][t.from]=e,this.withoutExpired(t.key)}},o(t,[{key:"me",get:function(){return this.actor}}]),t}(),m=function(){function t(t){this.ws=new r(t.conn),this.token=t.token,this.roomID=t.roomID,this.docID=t.checkpoint.id,this.actor=t.actor,this.checkpoint=t.checkpoint}var n=t.prototype;return n.once=function(t){try{var e,r=this;return Promise.race([new Promise((function(t,e){return setTimeout((function(){return e("timeout")}),2e3)})),new Promise((function(n){e=r.ws.bind(t,(function(t){n(t)}))}))]).then((function(){e&&r.ws.unbind(t,e)}))}catch(t){return Promise.reject(t)}},n.reconnect=function(){try{var t=this;t.errorListener||(t.errorListener=t.ws.bind("error",(function(t){console.error("Room Service encountered a server-side error. If you see this, please let us know; this could be a bug.",t)})));var e=t.once("guest:authenticated");return t.ws.send("guest:authenticate",t.token),Promise.resolve(e).then((function(){var e=t.once("room:joined");return t.ws.send("room:join",t.roomID),Promise.resolve(e).then((function(){}))}))}catch(t){return Promise.reject(t)}},n.list=function(t){try{this.checkpoint.lists[t]||(this.ws.send("doc:cmd",{args:["lcreate",this.docID,t],room:this.roomID}),this.checkpoint.lists[t]={afters:[],ids:[],values:[]});var e=new d(this.checkpoint,this.roomID,this.docID,t,this.ws,this.actor);return Promise.resolve(e)}catch(t){return Promise.reject(t)}},n.map=function(t){try{this.checkpoint.maps[t]||this.ws.send("doc:cmd",{args:["mcreate",this.docID,t],room:this.roomID});var e=new f(this.checkpoint.maps[t]||{},this.roomID,this.docID,t,this.ws);return Promise.resolve(e)}catch(t){return Promise.reject(t)}},n.presence=function(){try{var t=new l(this.roomID,this.ws,this.actor,this.token);return Promise.resolve(t)}catch(t){return Promise.reject(t)}},n.subscribe=function(t,r,n){var o=this;return"string"==typeof r?(t||e(!1),this.ws.bind("presence:fwd",(function(i){if(i.room===o.roomID&&i.key===r&&i.from!==o.actor){var s=t.update(i);n||e(!1),n(s,i.from)}}))):this.ws.bind("doc:fwd",(function(e){if(e.room===o.roomID)if(!e.args||e.args.length<3)console.error("Unexpected command: ",e.args);else if(e.from!==o.actor){var n=[e.args[1],e.args[2]];if(n[0]===o.docID&&n[1]===t.id){var i=t.update(e.args);r(i,e.from)}}}))},n.unsubscribe=function(t){this.ws.unbind("doc:fwd",t)},t}();exports.RoomService=function(){function t(t){this.auth=t.auth}return t.prototype.room=function(t){try{var e=new WebSocket("wss://super.stagingmcstagingface.com/ws");return Promise.resolve(function(t,e,r,n,o){try{return Promise.resolve(function(t,e,r){try{var n=function(r){if(o)return r;var n=t;return Promise.resolve(fetch(n,{method:"POST",body:JSON.stringify({resources:[{object:"document",reference:"default",permission:"read_write",room:e},{object:"room",reference:e,permission:"join"}]})})).then((function(t){if(401===t.status)throw new Error("AuthURL returned unauthorized");return Promise.resolve(t.json()).then((function(t){var e=t.token,r=t.user,o=t.resources;if(!o||!e||!r)throw new Error("Invalid response from the AuthURL: "+n);return{token:e,guestReference:r,docID:o.find((function(t){return"document"===t.object})).id,roomID:o.find((function(t){return"room"===t.object})).id}}))}))},o=!1,i=function(){if("function"==typeof t)return Promise.resolve(t(e)).then((function(t){if(!t.user)throw new Error("The auth function must return a 'user' key.");var e=t.resources.find((function(t){return"document"===t.object})).id,r=t.resources.find((function(t){return"room"===t.object})).id;return o=!0,{token:t.token,guestReference:t.user,docID:e,roomID:r}}))}();return Promise.resolve(i&&i.then?i.then(n):n(i))}catch(t){return Promise.reject(t)}}(r,n)).then((function(e){return Promise.resolve(function(t,e,r){try{return Promise.resolve(fetch("https://super.stagingmcstagingface.com/docs/"+r,{headers:{Authorization:"Bearer: "+e}})).then((function(t){return Promise.resolve(t.json())}))}catch(t){return Promise.reject(t)}}(0,e.token,e.docID)).then((function(r){var n=new m({conn:t,actor:e.guestReference,checkpoint:r.body,token:e.token,roomID:e.roomID});return Promise.resolve(n.reconnect()).then((function(){return n}))}))}))}catch(t){return Promise.reject(t)}}(e,0,this.auth,t))}catch(t){return Promise.reject(t)}},t}();
//# sourceMappingURL=browser.cjs.production.min.js.map

@@ -6,5 +6,8 @@ import invariant from 'tiny-invariant';

// export const PRESENCE_URL = 'http://localhost:3454/presence';
var WS_URL = 'wss://super.roomservice.dev/ws';
var DOCS_URL = 'https://super.roomservice.dev/docs';
var PRESENCE_URL = 'https://super.roomservice.dev/presence';
// export const WS_URL = 'wss://super.roomservice.dev/ws';
// export const DOCS_URL = 'https://super.roomservice.dev/docs';
// export const PRESENCE_URL = 'https://super.roomservice.dev/presence';
var WS_URL = 'wss://super.stagingmcstagingface.com/ws';
var DOCS_URL = 'https://super.stagingmcstagingface.com/docs';
var PRESENCE_URL = 'https://super.stagingmcstagingface.com/presence';

@@ -11,0 +14,0 @@ var SuperlumeWebSocket = /*#__PURE__*/function () {

@@ -1,3 +0,3 @@

export declare const WS_URL = "wss://super.roomservice.dev/ws";
export declare const DOCS_URL = "https://super.roomservice.dev/docs";
export declare const PRESENCE_URL = "https://super.roomservice.dev/presence";
export declare const WS_URL = "wss://super.stagingmcstagingface.com/ws";
export declare const DOCS_URL = "https://super.stagingmcstagingface.com/docs";
export declare const PRESENCE_URL = "https://super.stagingmcstagingface.com/presence";
{
"version": "1.0.0-10",
"version": "1.0.0-11-staging",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc