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 0.8.0-0 to 0.8.0

2

dist/browser.cjs.development.js

@@ -815,3 +815,3 @@ 'use strict';

// uses this SDK.
credentials: authorizationUrl.includes('https://api.roomservice.dev') && authorizationUrl.includes('debugger-auth-endpoint') ? 'include' : undefined,
credentials: authorizationUrl.includes('https://aws.roomservice.dev') && authorizationUrl.includes('debugger-auth-endpoint') ? 'include' : undefined,
throwHttpErrors: false

@@ -818,0 +818,0 @@ })).then(function (result) {

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

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("automerge"),o=e(t),n=require("immutable"),r=e(require("invariant")),i=require("lodash"),c=require("manymerge"),s=e(require("safe-json-stringify")),a=require("idb-keyval"),u=e(require("uuid/v4")),f=e(require("socket.io-client")),d=e(require("ky-universal"));function l(e,t){try{var o=e()}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var h=function(){try{return"undefined"==typeof window&&r(!1),Promise.resolve(l((function(){return Promise.resolve(a.get("rs:actor")).then((function(e){if(e)return e;var t=u();return a.set("rs:actor",t),t}))}),(function(){return console.warn("Cant use offline mode in this environment, skipping."),null})))}catch(e){return Promise.reject(e)}},m={newSocket:function(e,t){return f(e,t)},on:function(e,t,o){e&&t||r(!1),e.on(t,o)},off:function(e,t){e.off(t)},emit:function(e,t){e&&t||r(!1);for(var o=arguments.length,n=new Array(o>2?o-2:0),i=2;i<o;i++)n[i-2]=arguments[i];e.emit.apply(e,[t].concat(n))},disconnect:function(e){e.disconnect()}},_=function(e,t,o){try{return Promise.resolve(new Promise((function(n){e||r(!1);var i=setTimeout((function(){n(!1)}),15e3);m.emit(e,"authenticate",{meta:{roomId:o},payload:t}),m.on(e,"authenticated",(function(){clearTimeout(i),m.off(e,"authenticated"),n(!0)}))})))}catch(e){return Promise.reject(e)}},v=function(){function e(e){var o=this,n=this;this._sendMsgToSocket=function(e){try{return n._socket?Promise.resolve(n._authorized).then((function(t){t?(n._roomId||r(!1),m.emit(n._socket,"sync_room_state",s({meta:{roomId:n._roomId},payload:{msg:e}}))):console.error("Room Service is unable to authorize")})):Promise.resolve()}catch(e){return Promise.reject(e)}},this._roomReference=e.roomReference,this._defaultDoc=e.defaultDoc,this._peer=new c.Peer(this._sendMsgToSocket),this._socketURL="https://aws.roomservice.dev",this._saveOffline=i.debounce((function(e,n){!function(e,t,o){try{var n=l((function(){return Promise.resolve(a.set("rs:"+e+"/"+t,o)).then((function(){}))}),(function(e){console.warn("Something went wrong saving Room Service's state offline",e)}));Promise.resolve(n&&n.then?n.then((function(){})):void 0)}catch(e){return Promise.reject(e)}}(o._roomReference,e,t.save(n))}),120)}var u=e.prototype;return u.readActorIdThenCreateDoc=function(e){try{var t=this;return Promise.resolve(h()).then((function(o){return t._actorId=o,t.createDoc(o,e)}))}catch(e){return Promise.reject(e)}},u.createDoc=function(e,t){if(this._doc)return this._doc;var n=o.from(t||{},e?{actorId:e}:void 0);return this._doc=n,this._peer.notify(this._doc),this._doc},u.restore=function(){try{var e=function(){return t.syncOfflineCache()},t=this;if("undefined"==typeof window||"undefined"==typeof indexedDB)return Promise.resolve({});var o=function(){if(!t._doc)return Promise.resolve(t.readActorIdThenCreateDoc(t._defaultDoc)).then((function(){}))}();return Promise.resolve(o&&o.then?o.then(e):e())}catch(e){return Promise.reject(e)}},u.init=function(e){var n=e.room,i=e.session;try{var c=function(){var e=!1;function c(c){return e?c:(s._roomId=n.id,s._socket=m.newSocket(s._socketURL+"/v1/doc",{transports:["websocket"]}),m.on(s._socket,"reconnect_attempt",(function(){s._socket||r(!1),s._socket.io.opts.transports=["websocket"]})),m.on(s._socket,"error",(function(e){try{var t=JSON.parse(e);console.error("Error from Socket: "+t.message)}catch(t){console.error("Unparsable error from socket: "+e)}})),s._authorized=_(s._socket,i.token,n.id),m.on(s._socket,"connect",(function(){s._peer.notify(s._doc),s.syncOfflineCache()})),m.on(s._socket,"disconnect",(function(e){"io server disconnect"===e&&console.warn("The RoomService client was forcibly disconnected from the server, likely due to invalid auth.")})),s._onUpdateSocketCallback&&m.on(s._socket,"sync_room_state",s._onUpdateSocketCallback),s._onConnectSocketCallback&&m.on(s._socket,"connect",s._onConnectSocketCallback),s._onDisconnectSocketCallback&&m.on(s._socket,"disconnect",s._onDisconnectSocketCallback),Promise.resolve(fetch(s._socketURL+"/client/v1/rooms/"+n.id+"/documents/default",{headers:{authorization:"Bearer "+i.token}})).then((function(e){if(200!==e.status)throw new Error("Unexpectedly did not find document for room "+n.reference);return Promise.resolve(e.text()).then((function(e){function n(){return{doc:r}}var r,i=l((function(){return r=o.load(e),Promise.resolve(s.syncOfflineCache()).then((function(e){r=t.merge(e,r),s._doc=r,s._peer.notify(s._doc)}))}),(function(e){console.error(e),r={}}));return i&&i.then?i.then(n):n()}))})))}var a=function(){if(!n||!i)return Promise.resolve(s.syncOfflineCache()).then((function(){return e=!0,{doc:s._doc}}))}();return a&&a.then?a.then(c):c(a)},s=this;if("undefined"==typeof window)return Promise.resolve({doc:void 0});var a=function(){if(!s._doc)return Promise.resolve(s.readActorIdThenCreateDoc(s._defaultDoc)).then((function(){}))}();return Promise.resolve(a&&a.then?a.then(c):c())}catch(e){return Promise.reject(e)}},u.disconnect=function(){"undefined"!=typeof window?(this._socket&&m.disconnect(this._socket),this._socket=void 0):console.warn("Attempting to call disconnect on the server, this is a no-op.")},u.onSetDoc=function(e){var t=this;if("undefined"!=typeof window){this._onUpdateSocketCallback&&r(!1);var o=function(o){try{var r=function(){s.msg.clock=n.Map(s.msg.clock);try{var o=t._peer.applyMessage(s.msg,t._doc);if(!o)return;t._doc=o,t._saveOffline("default",t._doc),s.msg.changes&&e(t._doc)}catch(e){if(e.message&&e.message.includes("Inconsistent reuse of sequence number"))return;console.error(e)}},i=JSON.parse(o),c=i.meta,s=i.payload;if(!t._roomId)throw new Error("Expected a _roomId to be defined before we invoked the the onSetDoc callback. This is a sign of a broken client, please contact us if you're seeing this.");if(c.roomId!==t._roomId)return Promise.resolve();if(!s.msg)throw new Error("The room's state object does not include an 'msg' attribute, which could signal a corrupted room. If you're seeing this in production, that's quite bad and represents a fixable bug within the SDK itself. Please let us know and we'll fix it immediately!");var a=function(){if(!t._doc)return Promise.resolve(t.readActorIdThenCreateDoc(t._defaultDoc)).then((function(){}))}();return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}};this._socket?m.on(this._socket,"sync_room_state",o):this._onUpdateSocketCallback=o}else console.warn("Attempting to call onSetDoc on the server, this is a no-op.")},u.onConnect=function(e){"undefined"!=typeof window?this._socket?this._socket.on("connect",e):this._onConnectSocketCallback=e:console.warn("Attempting to call onConnect on the server, this is a no-op.")},u.onDisconnect=function(e){"undefined"!=typeof window?this._socket?this._socket.on("disconnect",e):this._onDisconnectSocketCallback=e:console.warn("Attempting to call onDisconnect on the server, this is a no-op.")},u.syncOfflineCache=function(){try{var e=this;return Promise.resolve(function(e,t){try{return Promise.resolve(l((function(){return Promise.resolve(a.get("rs:"+e+"/default"))}),(function(e){return console.warn("Something went wrong getting Room Service's state offline",e),""})))}catch(e){return Promise.reject(e)}}(e._roomReference)).then((function(o){return o?Promise.resolve(h()).then((function(n){n||console.error("Unexpectedly didn't find offline support in an environment like a browser where we should have offline support.");var r=t.load(o,{actorId:n});return e._doc=r,e._peer.notify(e._doc),r})):e._doc}))}catch(e){return Promise.reject(e)}},u.setDoc=function(e){try{var t=function(){if("function"!=typeof e)throw new Error("room.publishDoc expects a function.");var t=o.change(n._doc,e);return t||(n._actorId||r(!1),t=n.createDoc(n._actorId,n._defaultDoc)),n._doc=t,n._saveOffline("default",t),n._peer.notify(t),t},n=this;if("undefined"==typeof window)return console.warn("Attempting to call setDoc on the server, this is a no-op."),Promise.resolve({});var i=function(){if(!n._doc)return Promise.resolve(n.readActorIdThenCreateDoc(n._defaultDoc)).then((function(e){n._doc=e}))}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},u.undo=function(){if(this._doc&&o.canUndo(this._doc)){var e=o.undo(this._doc);return this._doc=e,this._saveOffline("default",e),this._peer.notify(e),e}return this._doc},u.redo=function(){if(this._doc&&o.canRedo(this._doc)){var e=o.redo(this._doc);return this._doc=e,this._saveOffline("default",e),this._peer.notify(e),e}return this._doc},e}(),p=i.throttle((function(e,t){for(var o=arguments.length,n=new Array(o>2?o-2:0),r=2;r<o;r++)n[r-2]=arguments[r];return m.emit.apply(m,[e,t].concat(n))}),40,{leading:!0}),y=function(){function e(e){this._socketURL="https://aws.roomservice.dev",this._authorizationUrl=e.authUrl,this._roomReference=e.roomReference}var t=e.prototype;return t.init=function(e){var t=this,o=e.room,n=e.session;o&&n?(this._roomId=o.id,this._socket=m.newSocket(this._socketURL+"/v1/presence",{transports:["websocket"]}),m.on(this._socket,"reconnect_attempt",(function(){t._socket||r(!1),t._socket.io.opts.transports=["websocket"]})),this._authorized=_(this._socket,n.token,o.id)):console.warn("Room Service is offline.")},t.setPresence=function(e,t,o){try{var n=function(){var n=(null==o?void 0:o.ttl)||2e3;if(t)if("object"==typeof(r=t)&&null!==r){var r,c={meta:{roomId:i._roomId,createdAt:(new Date).getTime(),namespace:e,ttl:n},payload:t};p(i._socket,"update_presence",c)}else console.error("Expected the function call 'setPresence(\""+e+"\", value)' to use a stringifiable object for variable 'value', instead got '"+t+"'.");else console.error("The function call 'setPresence(\""+e+"\", value)' passed in an undefined, null, or falsey 'value'.")},i=this;if(!i._socket)return Promise.resolve();i._roomId||r(!1);var c=function(){if(i._authorized)return Promise.resolve(i._authorized).then((function(){}))}();return Promise.resolve(c&&c.then?c.then(n):n())}catch(e){return Promise.reject(e)}},t.onSetPresence=function(e){var t=this;this._socket?m.on(this._socket,"update_presence",(function(o){try{var n=JSON.parse(o),r=n.meta,i=n.payload;if(!t._roomId)throw new Error("Expected a _roomId to be defined before we invoked the the onSetPresence callback. This is a sign of a broken client, please contact us if you're seeing this.");return r.connectionId||console.error("Unexpectedly got a packet without a connection id. We're skipping this for now, but this could be a sign of a service outage or a broken client."),r.connectionId===t._socket.id||r.roomId!==t._roomId||e(r,i),Promise.resolve()}catch(e){return Promise.reject(e)}})):console.warn("offline")},e}(),k=function(){function e(e){var t=this;this._init=i.throttle((function(){try{var e,o,n=function(){if("undefined"==typeof window){if(!e)throw new Error("Room Service can't access the auth endpoint on the server. More details: https://err.sh/getroomservice/browser/server-side-no-network");return{doc:void 0}}return t._presenceClient.init({room:e,session:o}),Promise.resolve(t._docClient.init({room:e,session:o})).then((function(e){return{doc:e.doc}}))},i=l((function(){return Promise.resolve(function(e,t,o){try{return Promise.resolve(d.post(e,{json:{room:{reference:t}},headers:o||void 0,credentials:e.includes("https://api.roomservice.dev")&&e.includes("debugger-auth-endpoint")?"include":void 0,throwHttpErrors:!1})).then((function(t){if(405===t.status&&r(!1),t.status<200||t.status>=400)throw new Error("Your Auth endpoint at '"+e+"' is not functioning properly, returned status of "+t.status+".");return Promise.resolve(t.json()).then((function(e){return{room:e.room,session:e.session}}))}))}catch(e){return Promise.reject(e)}}(t._authorizationUrl,t._roomReference,t._headers)).then((function(t){e=t.room,o=t.session}))}),(function(e){console.error("Room Service can't access the auth endpoint. More details: https://err.sh/getroomservice/browser/cant-access-auth-endpoint"),console.warn(e)}));return Promise.resolve(i&&i.then?i.then(n):n())}catch(e){return Promise.reject(e)}}),100,{leading:!0}),this._docClient=new v(e),this._presenceClient=new y(e),this._authorizationUrl=e.authUrl,this._roomReference=e.roomReference,this._headers=e.headers}var t,o=e.prototype;return o.init=function(){try{return Promise.resolve(this._init())}catch(e){return Promise.reject(e)}},o.restore=function(){try{return Promise.resolve(this._docClient.restore())}catch(e){return Promise.reject(e)}},o.onConnect=function(e){this._docClient.onConnect(e)},o.onDisconnect=function(e){this._docClient.onDisconnect(e)},o.disconnect=function(){this._docClient.disconnect()},o.setDoc=function(e){try{return Promise.resolve(this._docClient.setDoc(e))}catch(e){return Promise.reject(e)}},o.onSetDoc=function(e){this._docClient.onSetDoc(e)},o.undo=function(){return this._docClient.undo()},o.redo=function(){return this._docClient.redo()},o.setPresence=function(e,t){this._presenceClient.setPresence(e,t)},o.onSetPresence=function(e){this._presenceClient.onSetPresence(e)},(t=[{key:"_socketURL",set:function(e){this._docClient._socketURL=e,this._presenceClient._socketURL=e}}])&&function(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,t),e}();exports.default=function(){function e(e){this._roomPool={},this._authorizationUrl=e.authUrl,this._headers=e.headers}return e.prototype.room=function(e,t){if(this._roomPool[e])return this._roomPool[e];var o=new k({authUrl:this._authorizationUrl,roomReference:e,defaultDoc:t,headers:this._headers});return this._roomPool[e]=o,o},e}();
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("automerge"),o=e(t),n=require("immutable"),r=e(require("invariant")),i=require("lodash"),c=require("manymerge"),s=e(require("safe-json-stringify")),a=require("idb-keyval"),u=e(require("uuid/v4")),f=e(require("socket.io-client")),d=e(require("ky-universal"));function l(e,t){try{var o=e()}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var h=function(){try{return"undefined"==typeof window&&r(!1),Promise.resolve(l((function(){return Promise.resolve(a.get("rs:actor")).then((function(e){if(e)return e;var t=u();return a.set("rs:actor",t),t}))}),(function(){return console.warn("Cant use offline mode in this environment, skipping."),null})))}catch(e){return Promise.reject(e)}},m={newSocket:function(e,t){return f(e,t)},on:function(e,t,o){e&&t||r(!1),e.on(t,o)},off:function(e,t){e.off(t)},emit:function(e,t){e&&t||r(!1);for(var o=arguments.length,n=new Array(o>2?o-2:0),i=2;i<o;i++)n[i-2]=arguments[i];e.emit.apply(e,[t].concat(n))},disconnect:function(e){e.disconnect()}},_=function(e,t,o){try{return Promise.resolve(new Promise((function(n){e||r(!1);var i=setTimeout((function(){n(!1)}),15e3);m.emit(e,"authenticate",{meta:{roomId:o},payload:t}),m.on(e,"authenticated",(function(){clearTimeout(i),m.off(e,"authenticated"),n(!0)}))})))}catch(e){return Promise.reject(e)}},v=function(){function e(e){var o=this,n=this;this._sendMsgToSocket=function(e){try{return n._socket?Promise.resolve(n._authorized).then((function(t){t?(n._roomId||r(!1),m.emit(n._socket,"sync_room_state",s({meta:{roomId:n._roomId},payload:{msg:e}}))):console.error("Room Service is unable to authorize")})):Promise.resolve()}catch(e){return Promise.reject(e)}},this._roomReference=e.roomReference,this._defaultDoc=e.defaultDoc,this._peer=new c.Peer(this._sendMsgToSocket),this._socketURL="https://aws.roomservice.dev",this._saveOffline=i.debounce((function(e,n){!function(e,t,o){try{var n=l((function(){return Promise.resolve(a.set("rs:"+e+"/"+t,o)).then((function(){}))}),(function(e){console.warn("Something went wrong saving Room Service's state offline",e)}));Promise.resolve(n&&n.then?n.then((function(){})):void 0)}catch(e){return Promise.reject(e)}}(o._roomReference,e,t.save(n))}),120)}var u=e.prototype;return u.readActorIdThenCreateDoc=function(e){try{var t=this;return Promise.resolve(h()).then((function(o){return t._actorId=o,t.createDoc(o,e)}))}catch(e){return Promise.reject(e)}},u.createDoc=function(e,t){if(this._doc)return this._doc;var n=o.from(t||{},e?{actorId:e}:void 0);return this._doc=n,this._peer.notify(this._doc),this._doc},u.restore=function(){try{var e=function(){return t.syncOfflineCache()},t=this;if("undefined"==typeof window||"undefined"==typeof indexedDB)return Promise.resolve({});var o=function(){if(!t._doc)return Promise.resolve(t.readActorIdThenCreateDoc(t._defaultDoc)).then((function(){}))}();return Promise.resolve(o&&o.then?o.then(e):e())}catch(e){return Promise.reject(e)}},u.init=function(e){var n=e.room,i=e.session;try{var c=function(){var e=!1;function c(c){return e?c:(s._roomId=n.id,s._socket=m.newSocket(s._socketURL+"/v1/doc",{transports:["websocket"]}),m.on(s._socket,"reconnect_attempt",(function(){s._socket||r(!1),s._socket.io.opts.transports=["websocket"]})),m.on(s._socket,"error",(function(e){try{var t=JSON.parse(e);console.error("Error from Socket: "+t.message)}catch(t){console.error("Unparsable error from socket: "+e)}})),s._authorized=_(s._socket,i.token,n.id),m.on(s._socket,"connect",(function(){s._peer.notify(s._doc),s.syncOfflineCache()})),m.on(s._socket,"disconnect",(function(e){"io server disconnect"===e&&console.warn("The RoomService client was forcibly disconnected from the server, likely due to invalid auth.")})),s._onUpdateSocketCallback&&m.on(s._socket,"sync_room_state",s._onUpdateSocketCallback),s._onConnectSocketCallback&&m.on(s._socket,"connect",s._onConnectSocketCallback),s._onDisconnectSocketCallback&&m.on(s._socket,"disconnect",s._onDisconnectSocketCallback),Promise.resolve(fetch(s._socketURL+"/client/v1/rooms/"+n.id+"/documents/default",{headers:{authorization:"Bearer "+i.token}})).then((function(e){if(200!==e.status)throw new Error("Unexpectedly did not find document for room "+n.reference);return Promise.resolve(e.text()).then((function(e){function n(){return{doc:r}}var r,i=l((function(){return r=o.load(e),Promise.resolve(s.syncOfflineCache()).then((function(e){r=t.merge(e,r),s._doc=r,s._peer.notify(s._doc)}))}),(function(e){console.error(e),r={}}));return i&&i.then?i.then(n):n()}))})))}var a=function(){if(!n||!i)return Promise.resolve(s.syncOfflineCache()).then((function(){return e=!0,{doc:s._doc}}))}();return a&&a.then?a.then(c):c(a)},s=this;if("undefined"==typeof window)return Promise.resolve({doc:void 0});var a=function(){if(!s._doc)return Promise.resolve(s.readActorIdThenCreateDoc(s._defaultDoc)).then((function(){}))}();return Promise.resolve(a&&a.then?a.then(c):c())}catch(e){return Promise.reject(e)}},u.disconnect=function(){"undefined"!=typeof window?(this._socket&&m.disconnect(this._socket),this._socket=void 0):console.warn("Attempting to call disconnect on the server, this is a no-op.")},u.onSetDoc=function(e){var t=this;if("undefined"!=typeof window){this._onUpdateSocketCallback&&r(!1);var o=function(o){try{var r=function(){s.msg.clock=n.Map(s.msg.clock);try{var o=t._peer.applyMessage(s.msg,t._doc);if(!o)return;t._doc=o,t._saveOffline("default",t._doc),s.msg.changes&&e(t._doc)}catch(e){if(e.message&&e.message.includes("Inconsistent reuse of sequence number"))return;console.error(e)}},i=JSON.parse(o),c=i.meta,s=i.payload;if(!t._roomId)throw new Error("Expected a _roomId to be defined before we invoked the the onSetDoc callback. This is a sign of a broken client, please contact us if you're seeing this.");if(c.roomId!==t._roomId)return Promise.resolve();if(!s.msg)throw new Error("The room's state object does not include an 'msg' attribute, which could signal a corrupted room. If you're seeing this in production, that's quite bad and represents a fixable bug within the SDK itself. Please let us know and we'll fix it immediately!");var a=function(){if(!t._doc)return Promise.resolve(t.readActorIdThenCreateDoc(t._defaultDoc)).then((function(){}))}();return Promise.resolve(a&&a.then?a.then(r):r())}catch(e){return Promise.reject(e)}};this._socket?m.on(this._socket,"sync_room_state",o):this._onUpdateSocketCallback=o}else console.warn("Attempting to call onSetDoc on the server, this is a no-op.")},u.onConnect=function(e){"undefined"!=typeof window?this._socket?this._socket.on("connect",e):this._onConnectSocketCallback=e:console.warn("Attempting to call onConnect on the server, this is a no-op.")},u.onDisconnect=function(e){"undefined"!=typeof window?this._socket?this._socket.on("disconnect",e):this._onDisconnectSocketCallback=e:console.warn("Attempting to call onDisconnect on the server, this is a no-op.")},u.syncOfflineCache=function(){try{var e=this;return Promise.resolve(function(e,t){try{return Promise.resolve(l((function(){return Promise.resolve(a.get("rs:"+e+"/default"))}),(function(e){return console.warn("Something went wrong getting Room Service's state offline",e),""})))}catch(e){return Promise.reject(e)}}(e._roomReference)).then((function(o){return o?Promise.resolve(h()).then((function(n){n||console.error("Unexpectedly didn't find offline support in an environment like a browser where we should have offline support.");var r=t.load(o,{actorId:n});return e._doc=r,e._peer.notify(e._doc),r})):e._doc}))}catch(e){return Promise.reject(e)}},u.setDoc=function(e){try{var t=function(){if("function"!=typeof e)throw new Error("room.publishDoc expects a function.");var t=o.change(n._doc,e);return t||(n._actorId||r(!1),t=n.createDoc(n._actorId,n._defaultDoc)),n._doc=t,n._saveOffline("default",t),n._peer.notify(t),t},n=this;if("undefined"==typeof window)return console.warn("Attempting to call setDoc on the server, this is a no-op."),Promise.resolve({});var i=function(){if(!n._doc)return Promise.resolve(n.readActorIdThenCreateDoc(n._defaultDoc)).then((function(e){n._doc=e}))}();return Promise.resolve(i&&i.then?i.then(t):t())}catch(e){return Promise.reject(e)}},u.undo=function(){if(this._doc&&o.canUndo(this._doc)){var e=o.undo(this._doc);return this._doc=e,this._saveOffline("default",e),this._peer.notify(e),e}return this._doc},u.redo=function(){if(this._doc&&o.canRedo(this._doc)){var e=o.redo(this._doc);return this._doc=e,this._saveOffline("default",e),this._peer.notify(e),e}return this._doc},e}(),p=i.throttle((function(e,t){for(var o=arguments.length,n=new Array(o>2?o-2:0),r=2;r<o;r++)n[r-2]=arguments[r];return m.emit.apply(m,[e,t].concat(n))}),40,{leading:!0}),y=function(){function e(e){this._socketURL="https://aws.roomservice.dev",this._authorizationUrl=e.authUrl,this._roomReference=e.roomReference}var t=e.prototype;return t.init=function(e){var t=this,o=e.room,n=e.session;o&&n?(this._roomId=o.id,this._socket=m.newSocket(this._socketURL+"/v1/presence",{transports:["websocket"]}),m.on(this._socket,"reconnect_attempt",(function(){t._socket||r(!1),t._socket.io.opts.transports=["websocket"]})),this._authorized=_(this._socket,n.token,o.id)):console.warn("Room Service is offline.")},t.setPresence=function(e,t,o){try{var n=function(){var n=(null==o?void 0:o.ttl)||2e3;if(t)if("object"==typeof(r=t)&&null!==r){var r,c={meta:{roomId:i._roomId,createdAt:(new Date).getTime(),namespace:e,ttl:n},payload:t};p(i._socket,"update_presence",c)}else console.error("Expected the function call 'setPresence(\""+e+"\", value)' to use a stringifiable object for variable 'value', instead got '"+t+"'.");else console.error("The function call 'setPresence(\""+e+"\", value)' passed in an undefined, null, or falsey 'value'.")},i=this;if(!i._socket)return Promise.resolve();i._roomId||r(!1);var c=function(){if(i._authorized)return Promise.resolve(i._authorized).then((function(){}))}();return Promise.resolve(c&&c.then?c.then(n):n())}catch(e){return Promise.reject(e)}},t.onSetPresence=function(e){var t=this;this._socket?m.on(this._socket,"update_presence",(function(o){try{var n=JSON.parse(o),r=n.meta,i=n.payload;if(!t._roomId)throw new Error("Expected a _roomId to be defined before we invoked the the onSetPresence callback. This is a sign of a broken client, please contact us if you're seeing this.");return r.connectionId||console.error("Unexpectedly got a packet without a connection id. We're skipping this for now, but this could be a sign of a service outage or a broken client."),r.connectionId===t._socket.id||r.roomId!==t._roomId||e(r,i),Promise.resolve()}catch(e){return Promise.reject(e)}})):console.warn("offline")},e}(),k=function(){function e(e){var t=this;this._init=i.throttle((function(){try{var e,o,n=function(){if("undefined"==typeof window){if(!e)throw new Error("Room Service can't access the auth endpoint on the server. More details: https://err.sh/getroomservice/browser/server-side-no-network");return{doc:void 0}}return t._presenceClient.init({room:e,session:o}),Promise.resolve(t._docClient.init({room:e,session:o})).then((function(e){return{doc:e.doc}}))},i=l((function(){return Promise.resolve(function(e,t,o){try{return Promise.resolve(d.post(e,{json:{room:{reference:t}},headers:o||void 0,credentials:e.includes("https://aws.roomservice.dev")&&e.includes("debugger-auth-endpoint")?"include":void 0,throwHttpErrors:!1})).then((function(t){if(405===t.status&&r(!1),t.status<200||t.status>=400)throw new Error("Your Auth endpoint at '"+e+"' is not functioning properly, returned status of "+t.status+".");return Promise.resolve(t.json()).then((function(e){return{room:e.room,session:e.session}}))}))}catch(e){return Promise.reject(e)}}(t._authorizationUrl,t._roomReference,t._headers)).then((function(t){e=t.room,o=t.session}))}),(function(e){console.error("Room Service can't access the auth endpoint. More details: https://err.sh/getroomservice/browser/cant-access-auth-endpoint"),console.warn(e)}));return Promise.resolve(i&&i.then?i.then(n):n())}catch(e){return Promise.reject(e)}}),100,{leading:!0}),this._docClient=new v(e),this._presenceClient=new y(e),this._authorizationUrl=e.authUrl,this._roomReference=e.roomReference,this._headers=e.headers}var t,o=e.prototype;return o.init=function(){try{return Promise.resolve(this._init())}catch(e){return Promise.reject(e)}},o.restore=function(){try{return Promise.resolve(this._docClient.restore())}catch(e){return Promise.reject(e)}},o.onConnect=function(e){this._docClient.onConnect(e)},o.onDisconnect=function(e){this._docClient.onDisconnect(e)},o.disconnect=function(){this._docClient.disconnect()},o.setDoc=function(e){try{return Promise.resolve(this._docClient.setDoc(e))}catch(e){return Promise.reject(e)}},o.onSetDoc=function(e){this._docClient.onSetDoc(e)},o.undo=function(){return this._docClient.undo()},o.redo=function(){return this._docClient.redo()},o.setPresence=function(e,t){this._presenceClient.setPresence(e,t)},o.onSetPresence=function(e){this._presenceClient.onSetPresence(e)},(t=[{key:"_socketURL",set:function(e){this._docClient._socketURL=e,this._presenceClient._socketURL=e}}])&&function(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(e.prototype,t),e}();exports.default=function(){function e(e){this._roomPool={},this._authorizationUrl=e.authUrl,this._headers=e.headers}return e.prototype.room=function(e,t){if(this._roomPool[e])return this._roomPool[e];var o=new k({authUrl:this._authorizationUrl,roomReference:e,defaultDoc:t,headers:this._headers});return this._roomPool[e]=o,o},e}();
//# sourceMappingURL=browser.cjs.production.min.js.map

@@ -808,3 +808,3 @@ import Automerge, { merge, load, save } from 'automerge';

// uses this SDK.
credentials: authorizationUrl.includes('https://api.roomservice.dev') && authorizationUrl.includes('debugger-auth-endpoint') ? 'include' : undefined,
credentials: authorizationUrl.includes('https://aws.roomservice.dev') && authorizationUrl.includes('debugger-auth-endpoint') ? 'include' : undefined,
throwHttpErrors: false

@@ -811,0 +811,0 @@ })).then(function (result) {

{
"version": "0.8.0-0",
"version": "0.8.0",
"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