@sockethub/client 5.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sockethub-client.js","sourceRoot":"/","sources":["sockethub-client.ts"],"names":[],"mappings":";;;;;AAAA,iDAA8C;AAC9C,mFAAoD;AAkBpD,MAAM,eAAe;IAanB,YAAY,MAAM;QAXV,WAAM,GAAG;YACf,aAAa,EAAE,IAAI,GAAG,EAAE;YACxB,iBAAiB,EAAE,IAAI,GAAG,EAAE;YAC5B,SAAS,EAAE,IAAI,GAAG,EAAE;YACpB,MAAM,EAAE,IAAI,GAAG,EAAE;SAClB,CAAC;QAGK,WAAM,GAAG,KAAK,CAAC;QACf,UAAK,GAAG,IAAI,CAAC;QAGlB,IAAI,CAAE,MAAM,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SAAE;QACnF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,aAAa;QACb,IAAI,CAAC,eAAe,GAAG,IAAA,0BAAS,EAAC,EAAC,WAAW,EAAE,CAAC,aAAa,CAAC,EAAC,CAAC,CAAC;QAEjE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzC,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAEhC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC,wBAAwB,EAAE,CAAC,GAAG,EAAE,EAAE;YACxD,MAAM,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE;gBAC1C,IAAI,GAAG,EAAE;oBAAE,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;iBAAE;qBAChE;oBAAE,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;iBAAE;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MA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,YAAY,CAAC,CAAC,CAAC;QAEzD,6EAA6E;QAC7E,0EAA0E;QAC1E,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,KAAU;QACrC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACpB,IAAI,CAAC,GAAG,CAAC,aAAa,IAAI,EAAE,EAAE,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAAA,CAAC;CACH;AAED,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,OAAO,EAAE;IAChD,MAAM,CAAC,OAAO,GAAG,eAAe,CAAC;CAClC;AAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;IAC/B,OAAO,GAAG,eAAe,CAAC,CAAE,wCAAwC;CACrE;AAED,aAAa;AACb,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;IAC9B,aAAa;IACb,MAAM,CAAC,eAAe,GAAG,eAAe,CAAC;CAC1C"}
@@ -0,0 +1,2 @@
1
+ /*! For license information please see sockethub-client.min.js.LICENSE.txt */
2
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var n in r)("object"==typeof exports?exports:e)[n]=r[n]}}(self,(function(){return e={423:(e,t,r)=>{"use strict";var n=r(132),i=r(421),s=r(240),o=r(343),c=r(50),l=e.exports=function(e,t){var r,i,l,a,f;return arguments.length<2||"string"!=typeof e?(a=t,t=e,e=null):a=arguments[2],n(e)?(r=c.call(e,"c"),i=c.call(e,"e"),l=c.call(e,"w")):(r=l=!0,i=!1),f={value:t,configurable:r,enumerable:i,writable:l},a?s(o(a),f):f};l.gs=function(e,t,r){var l,a,f,u;return"string"!=typeof e?(f=r,r=t,t=e,e=null):f=arguments[3],n(t)?i(t)?n(r)?i(r)||(f=r,r=void 0):r=void 0:(f=t,t=r=void 0):t=void 0,n(e)?(l=c.call(e,"c"),a=c.call(e,"e")):(l=!0,a=!1),u={get:t,set:r,configurable:l,enumerable:a},f?s(o(f),u):u}},91:e=>{"use strict";e.exports=function(){}},240:(e,t,r)=>{"use strict";e.exports=r(229)()?Object.assign:r(640)},229:e=>{"use strict";e.exports=function(){var e,t=Object.assign;return"function"==typeof t&&(t(e={foo:"raz"},{bar:"dwa"},{trzy:"trzy"}),e.foo+e.bar+e.trzy==="razdwatrzy")}},640:(e,t,r)=>{"use strict";var n=r(255),i=r(110),s=Math.max;e.exports=function(e,t){var r,o,c,l=s(arguments.length,2);for(e=Object(i(e)),c=function(n){try{e[n]=t[n]}catch(e){r||(r=e)}},o=1;o<l;++o)n(t=arguments[o]).forEach(c);if(void 0!==r)throw r;return e}},515:(e,t,r)=>{"use strict";var n=r(91)();e.exports=function(e){return e!==n&&null!==e}},255:(e,t,r)=>{"use strict";e.exports=r(291)()?Object.keys:r(184)},291:e=>{"use strict";e.exports=function(){try{return Object.keys("primitive"),!0}catch(e){return!1}}},184:(e,t,r)=>{"use strict";var n=r(515),i=Object.keys;e.exports=function(e){return i(n(e)?Object(e):e)}},343:(e,t,r)=>{"use strict";var n=r(515),i=Array.prototype.forEach,s=Object.create,o=function(e,t){var r;for(r in e)t[r]=e[r]};e.exports=function(e){var t=s(null);return i.call(arguments,(function(e){n(e)&&o(Object(e),t)})),t}},979:e=>{"use strict";e.exports=function(e){if("function"!=typeof e)throw new TypeError(e+" is not a function");return e}},110:(e,t,r)=>{"use strict";var n=r(515);e.exports=function(e){if(!n(e))throw new TypeError("Cannot use null or undefined");return e}},50:(e,t,r)=>{"use strict";e.exports=r(459)()?String.prototype.contains:r(131)},459:e=>{"use strict";var t="razdwatrzy";e.exports=function(){return"function"==typeof t.contains&&!0===t.contains("dwa")&&!1===t.contains("foo")}},131:e=>{"use strict";var t=String.prototype.indexOf;e.exports=function(e){return t.call(this,e,arguments[1])>-1}},360:(e,t,r)=>{"use strict";var n,i,s,o,c,l,a,f=r(423),u=r(979),h=Function.prototype.apply,p=Function.prototype.call,y=Object.create,v=Object.defineProperty,_=Object.defineProperties,m=Object.prototype.hasOwnProperty,d={configurable:!0,enumerable:!1,writable:!0};i=function(e,t){var r,i;return u(t),i=this,n.call(this,e,r=function(){s.call(i,e,r),h.call(t,this,arguments)}),r.__eeOnceListener__=t,this},o=function(e){var t,r,n,i,s;if(m.call(this,"__ee__")&&(i=this.__ee__[e]))if("object"==typeof i){for(r=arguments.length,s=new Array(r-1),t=1;t<r;++t)s[t-1]=arguments[t];for(i=i.slice(),t=0;n=i[t];++t)h.call(n,this,s)}else switch(arguments.length){case 1:p.call(i,this);break;case 2:p.call(i,this,arguments[1]);break;case 3:p.call(i,this,arguments[1],arguments[2]);break;default:for(r=arguments.length,s=new Array(r-1),t=1;t<r;++t)s[t-1]=arguments[t];h.call(i,this,s)}},c={on:n=function(e,t){var r;return u(t),m.call(this,"__ee__")?r=this.__ee__:(r=d.value=y(null),v(this,"__ee__",d),d.value=null),r[e]?"object"==typeof r[e]?r[e].push(t):r[e]=[r[e],t]:r[e]=t,this},once:i,off:s=function(e,t){var r,n,i,s;if(u(t),!m.call(this,"__ee__"))return this;if(!(r=this.__ee__)[e])return this;if("object"==typeof(n=r[e]))for(s=0;i=n[s];++s)i!==t&&i.__eeOnceListener__!==t||(2===n.length?r[e]=n[s?0:1]:n.splice(s,1));else n!==t&&n.__eeOnceListener__!==t||delete r[e];return this},emit:o},l={on:f(n),once:f(i),off:f(s),emit:f(o)},a=_({},l),e.exports=t=function(e){return null==e?y(a):_(Object(e),l)},t.methods=c},414:(e,t,r)=>{"use strict";var n=r(670);e.exports=function(e){if("function"!=typeof e)return!1;if(!hasOwnProperty.call(e,"length"))return!1;try{if("number"!=typeof e.length)return!1;if("function"!=typeof e.call)return!1;if("function"!=typeof e.apply)return!1}catch(e){return!1}return!n(e)}},783:(e,t,r)=>{"use strict";var n=r(132),i={object:!0,function:!0,undefined:!0};e.exports=function(e){return!!n(e)&&hasOwnProperty.call(i,typeof e)}},421:(e,t,r)=>{"use strict";var n=r(414),i=/^\s*class[\s{/}]/,s=Function.prototype.toString;e.exports=function(e){return!!n(e)&&!i.test(s.call(e))}},670:(e,t,r)=>{"use strict";var n=r(783);e.exports=function(e){if(!n(e))return!1;try{return!!e.constructor&&e.constructor.prototype===e}catch(e){return!1}}},132:e=>{"use strict";e.exports=function(e){return null!=e}},744:(e,t,r)=>{const n=r(360)(),i={stream:["id","type","actor","target","object","context","context","published","error"],object:["id","type","context","alias","attachedTo","attachment","attributedTo","attributedWith","content","contentMap","context","contextOf","name","endTime","generator","generatorOf","group","icon","image","inReplyTo","members","memberOf","message","location","locationOf","objectOf","originOf","presence","preview","previewOf","provider","providerOf","published","rating","relationship","resultOf","replies","role","scope","scopeOf","startTime","status","summary","topic","tag","tagOf","targetOf","title","titleMap","updated","url"]},s={"@id":"id","@type":"type",verb:"type",displayName:"name",objectType:"type",platform:"context"},o={actor:{primary:"id",props:i},target:{primary:"id",props:i},object:{primary:"content",props:i}};let c=new Map,l=!1,a=[],f={};function u(e,t){return!("object"!=typeof f[e]||!f[e].includes(t))}function h(e,t){return e[s[t]]=e[t],delete e[t],e}function p(e,t={}){const r=Object.keys(t).filter((t=>{if(!i[e].includes(t))return t}));for(let e of r)if(s[e])t=h(t,e);else if(!u(t.type,e)&&!a.includes(t.type)){const t=`invalid property: "${e}"`;if(l)throw new Error(t);console.warn(t)}}function y(e){p("stream",e),"object"==typeof e.object&&p("object",e.object);const t=function(e){let t={};for(let r of Object.keys(e))if("string"==typeof e[r])t[r]=c.get(e[r])||e[r];else if(Array.isArray(e[r])){t[r]=[];for(let n of e[r])"string"==typeof n&&t[r].push(c.get(n)||n)}else t[r]=e[r];for(let e of Object.keys(o))if("string"==typeof t[e]){let r={};r[o[e].primary]=t[e],t[e]=r}return t}(e);return n.emit("activity-stream",t),t}const v={create:function(e){return p("object",e),e=e,c.set(e.id,e),n.emit("activity-object-create",e),e},delete:function(e){const t=c.delete(e);return t&&n.emit("activity-object-delete",e),t},get:function(e,t){let r=c.get(e);if(!r){if(!t)return e;r={id:e}}return r},list:function(){return c.keys()}};function _(e={}){a=e.specialObjs||[],l="boolean"==typeof e.failOnUnknownObjectProperties&&e.failOnUnknownObjectProperties;for(let t of Object.keys(e.customProps||{}))"object"==typeof e.customProps[t]&&(f[t]=e.customProps[t]);return{Stream:y,Object:v,on:function(e,t){return n.on(e,t)},once:function(e,t){return n.once(e,t)},off:function(e,t){return n.off(e,t)}}}e.exports&&(e.exports=_),"object"==typeof window&&(window.ASFactory=_)},650:function(e,t,r){"use strict";var n=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=r(387),s=n(r(744));class o{constructor(e){if(this.events={credentials:new Map,"activity-object":new Map,connect:new Map,join:new Map},this.online=!1,this.debug=!0,!e)throw new Error("SockethubClient requires a socket.io instance");this._socket=e,this.ActivityStreams=(0,s.default)({specialObjs:["credentials"]}),this.socket=this.createPublicEmitter(),this.registerSocketIOHandlers(),this.ActivityStreams.on("activity-object-create",(t=>{e.emit("activity-object",t,(e=>{e?console.error("failed to create activity-object ",e):this.eventActivityObject(t)}))})),e.on("activity-object",(e=>{this.ActivityStreams.Object.create(e)}))}createPublicEmitter(){let e=new i.EventEmitter2({wildcard:!0,verboseMemoryLeak:!1});return e._emit=e.emit,e.emit=(e,t,r)=>{"credentials"===e?this.eventCredentials(t):"activity-object"===e?this.eventActivityObject(t):"message"===e&&this.eventMessage(t),this._socket.emit(e,t,r)},e}eventActivityObject(e){e.id&&this.events["activity-object"].set(e.id,e)}eventCredentials(e){e.object&&"credentials"===e.object.type&&this.events.credentials.set(e.actor.id||e.actor,e)}eventMessage(e){if(!this.online)return;const t=o.getKey(e);"join"===e.type||"connect"===e.type?this.events[e.type].set(t,e):"leave"===e.type?this.events.join.delete(t):"disconnect"===e.type&&this.events.connect.delete(t)}static getKey(e){var t;let r=(null===(t=e.actor)||void 0===t?void 0:t.id)||e.actor;if(!r)throw new Error("actor property not present for message type: "+(null==e?void 0:e.type));return r+"-"+(e.target?e.target.id||e.target:"")}log(e,t){this.debug&&console.log(e,t)}registerSocketIOHandlers(){const e=e=>(t,r)=>{"connect"===e?(this.online=!0,this.replay("activity-object",this.events["activity-object"]),this.replay("credentials",this.events.credentials),this.replay("message",this.events.connect),this.replay("message",this.events.join)):"disconnect"===e&&(this.online=!1),this.socket._emit(e,t,r)};this._socket.on("connect",e("connect")),this._socket.on("connect_error",e("connect_error")),this._socket.on("disconnect",e("disconnect")),this._socket.on("message",((e,t)=>{this.socket._emit("message",this.ActivityStreams.Stream(e),t)}))}replay(e,t){t.forEach((t=>{this.log(`replaying ${e}`,t),this._socket.emit(e,t)}))}}e.exports&&(e.exports=o),t=o,"object"==typeof window&&(window.SockethubClient=o)},387:(e,t,r)=>{var n;!function(i){var s=Object.hasOwnProperty,o=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)},c="object"==typeof process&&"function"==typeof process.nextTick,l="function"==typeof Symbol,a="object"==typeof Reflect,f="function"==typeof setImmediate?setImmediate:setTimeout,u=l?a&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:function(e){var t=Object.getOwnPropertyNames(e);return t.push.apply(t,Object.getOwnPropertySymbols(e)),t}:Object.keys;function h(){this._events={},this._conf&&p.call(this,this._conf)}function p(e){e&&(this._conf=e,e.delimiter&&(this.delimiter=e.delimiter),e.maxListeners!==i&&(this._maxListeners=e.maxListeners),e.wildcard&&(this.wildcard=e.wildcard),e.newListener&&(this._newListener=e.newListener),e.removeListener&&(this._removeListener=e.removeListener),e.verboseMemoryLeak&&(this.verboseMemoryLeak=e.verboseMemoryLeak),e.ignoreErrors&&(this.ignoreErrors=e.ignoreErrors),this.wildcard&&(this.listenerTree={}))}function y(e,t){var r="(node) warning: possible EventEmitter memory leak detected. "+e+" listeners added. Use emitter.setMaxListeners() to increase limit.";if(this.verboseMemoryLeak&&(r+=" Event name: "+t+"."),"undefined"!=typeof process&&process.emitWarning){var n=new Error(r);n.name="MaxListenersExceededWarning",n.emitter=this,n.count=e,process.emitWarning(n)}else console.error(r),console.trace&&console.trace()}var v=function(e,t,r){var n=arguments.length;switch(n){case 0:return[];case 1:return[e];case 2:return[e,t];case 3:return[e,t,r];default:for(var i=new Array(n);n--;)i[n]=arguments[n];return i}};function _(e,t){for(var r={},n=e.length,s=t?value.length:0,o=0;o<n;o++)r[e[o]]=o<s?t[o]:i;return r}function m(e,t,r){var n,i;if(this._emitter=e,this._target=t,this._listeners={},this._listenersCount=0,(r.on||r.off)&&(n=r.on,i=r.off),t.addEventListener?(n=t.addEventListener,i=t.removeEventListener):t.addListener?(n=t.addListener,i=t.removeListener):t.on&&(n=t.on,i=t.off),!n&&!i)throw Error("target does not implement any known event API");if("function"!=typeof n)throw TypeError("on method must be a function");if("function"!=typeof i)throw TypeError("off method must be a function");this._on=n,this._off=i;var s=e._observers;s?s.push(this):e._observers=[this]}function d(e,t,r,n){var o=Object.assign({},t);if(!e)return o;if("object"!=typeof e)throw TypeError("options must be an object");var c,l,a,f=Object.keys(e),u=f.length;function h(e){throw Error('Invalid "'+c+'" option value'+(e?". Reason: "+e:""))}for(var p=0;p<u;p++){if(c=f[p],!n&&!s.call(t,c))throw Error('Unknown "'+c+'" option');(l=e[c])!==i&&(a=r[c],o[c]=a?a(l,h):l)}return o}function b(e,t){return"function"==typeof e&&e.hasOwnProperty("prototype")||t("value must be a constructor"),e}function g(e){var t="value must be type of "+e.join("|"),r=e.length,n=e[0],i=e[1];return 1===r?function(e,r){if(typeof e===n)return e;r(t)}:2===r?function(e,r){var s=typeof e;if(s===n||s===i)return e;r(t)}:function(n,i){for(var s=typeof n,o=r;o-- >0;)if(s===e[o])return n;i(t)}}Object.assign(m.prototype,{subscribe:function(e,t,r){var n=this,i=this._target,s=this._emitter,o=this._listeners,c=function(){var n=v.apply(null,arguments),o={data:n,name:t,original:e};if(r){var c=r.call(i,o);!1!==c&&s.emit.apply(s,[o.name].concat(n))}else s.emit.apply(s,[t].concat(n))};if(o[e])throw Error("Event '"+e+"' is already listening");this._listenersCount++,s._newListener&&s._removeListener&&!n._onNewListener?(this._onNewListener=function(r){r===t&&null===o[e]&&(o[e]=c,n._on.call(i,e,c))},s.on("newListener",this._onNewListener),this._onRemoveListener=function(r){r===t&&!s.hasListeners(r)&&o[e]&&(o[e]=null,n._off.call(i,e,c))},o[e]=null,s.on("removeListener",this._onRemoveListener)):(o[e]=c,n._on.call(i,e,c))},unsubscribe:function(e){var t,r,n,i=this,s=this._listeners,o=this._emitter,c=this._off,l=this._target;if(e&&"string"!=typeof e)throw TypeError("event must be a string");function a(){i._onNewListener&&(o.off("newListener",i._onNewListener),o.off("removeListener",i._onRemoveListener),i._onNewListener=null,i._onRemoveListener=null);var e=O.call(o,i);o._observers.splice(e,1)}if(e){if(!(t=s[e]))return;c.call(l,e,t),delete s[e],--this._listenersCount||a()}else{for(n=(r=u(s)).length;n-- >0;)e=r[n],c.call(l,e,s[e]);this._listeners={},this._listenersCount=0,a()}}});var w=g(["function"]),j=g(["object","function"]);function L(e,t,r){var n,i,s,o=0,c=new e((function(l,a,f){function u(){i&&(i=null),o&&(clearTimeout(o),o=0)}r=d(r,{timeout:0,overload:!1},{timeout:function(e,t){return("number"!=typeof(e*=1)||e<0||!Number.isFinite(e))&&t("timeout must be a positive number"),e}}),n=!r.overload&&"function"==typeof e.prototype.cancel&&"function"==typeof f;var h=function(e){u(),l(e)},p=function(e){u(),a(e)};n?t(h,p,f):(i=[function(e){p(e||Error("canceled"))}],t(h,p,(function(e){if(s)throw Error("Unable to subscribe on cancel event asynchronously");if("function"!=typeof e)throw TypeError("onCancel callback must be a function");i.push(e)})),s=!0),r.timeout>0&&(o=setTimeout((function(){var e=Error("timeout");e.code="ETIMEDOUT",o=0,c.cancel(e),a(e)}),r.timeout))}));return n||(c.cancel=function(e){if(i){for(var t=i.length,r=1;r<t;r++)i[r](e);i[0](e),i=null}}),c}function O(e){var t=this._observers;if(!t)return-1;for(var r=t.length,n=0;n<r;n++)if(t[n]._target===e)return n;return-1}function x(e,t,r,n,i){if(!r)return null;if(0===n){var s=typeof t;if("string"===s){var o,c,l=0,a=0,f=this.delimiter,h=f.length;if(-1!==(c=t.indexOf(f))){o=new Array(5);do{o[l++]=t.slice(a,c),a=c+h}while(-1!==(c=t.indexOf(f,a)));o[l++]=t.slice(a),t=o,i=l}else t=[t],i=1}else"object"===s?i=t.length:(t=[t],i=1)}var p,y,v,_,m,d,b,g=null,w=t[n],j=t[n+1];if(n===i)r._listeners&&("function"==typeof r._listeners?(e&&e.push(r._listeners),g=[r]):(e&&e.push.apply(e,r._listeners),g=[r]));else{if("*"===w){for(c=(d=u(r)).length;c-- >0;)"_listeners"!==(p=d[c])&&(b=x(e,t,r[p],n+1,i))&&(g?g.push.apply(g,b):g=b);return g}if("**"===w){for((m=n+1===i||n+2===i&&"*"===j)&&r._listeners&&(g=x(e,t,r,i,i)),c=(d=u(r)).length;c-- >0;)"_listeners"!==(p=d[c])&&("*"===p||"**"===p?(r[p]._listeners&&!m&&(b=x(e,t,r[p],i,i))&&(g?g.push.apply(g,b):g=b),b=x(e,t,r[p],n,i)):b=x(e,t,r[p],p===j?n+2:n,i),b&&(g?g.push.apply(g,b):g=b));return g}r[w]&&(g=x(e,t,r[w],n+1,i))}if((y=r["*"])&&x(e,t,y,n+1,i),v=r["**"])if(n<i)for(v._listeners&&x(e,t,v,i,i),c=(d=u(v)).length;c-- >0;)"_listeners"!==(p=d[c])&&(p===j?x(e,t,v[p],n+2,i):p===w?x(e,t,v[p],n+1,i):((_={})[p]=v[p],x(e,t,{"**":_},n+1,i)));else v._listeners?x(e,t,v,i,i):v["*"]&&v["*"]._listeners&&x(e,t,v["*"],i,i);return g}function k(e,t,r){var n,i,s=0,o=0,c=this.delimiter,l=c.length;if("string"==typeof e)if(-1!==(n=e.indexOf(c))){i=new Array(5);do{i[s++]=e.slice(o,n),o=n+l}while(-1!==(n=e.indexOf(c,o)));i[s++]=e.slice(o)}else i=[e],s=1;else i=e,s=e.length;if(s>1)for(n=0;n+1<s;n++)if("**"===i[n]&&"**"===i[n+1])return;var a,f=this.listenerTree;for(n=0;n<s;n++)if(f=f[a=i[n]]||(f[a]={}),n===s-1)return f._listeners?("function"==typeof f._listeners&&(f._listeners=[f._listeners]),r?f._listeners.unshift(t):f._listeners.push(t),!f._listeners.warned&&this._maxListeners>0&&f._listeners.length>this._maxListeners&&(f._listeners.warned=!0,y.call(this,f._listeners.length,a))):f._listeners=t,!0;return!0}function E(e,t,r,n){for(var i,s,o,c,l=u(e),a=l.length,f=e._listeners;a-- >0;)i=e[s=l[a]],o="_listeners"===s?r:r?r.concat(s):[s],c=n||"symbol"==typeof s,f&&t.push(c?o:o.join(this.delimiter)),"object"==typeof i&&E.call(this,i,t,o,c);return t}function T(e){for(var t,r,n,i=u(e),s=i.length;s-- >0;)(t=e[r=i[s]])&&(n=!0,"_listeners"===r||T(t)||delete e[r]);return n}function A(e,t,r){this.emitter=e,this.event=t,this.listener=r}function P(e,t,r){if(!0===r)s=!0;else if(!1===r)n=!0;else{if(!r||"object"!=typeof r)throw TypeError("options should be an object or true");var n=r.async,s=r.promisify,o=r.nextTick,l=r.objectify}if(n||o||s){var a=t,u=t._origin||t;if(o&&!c)throw Error("process.nextTick is not supported");s===i&&(s="AsyncFunction"===t.constructor.name),t=function(){var e=arguments,t=this,r=this.event;return s?o?Promise.resolve():new Promise((function(e){f(e)})).then((function(){return t.event=r,a.apply(t,e)})):(o?process.nextTick:f)((function(){t.event=r,a.apply(t,e)}))},t._async=!0,t._origin=u}return[t,l?new A(this,e,t):this]}function M(e){this._events={},this._newListener=!1,this._removeListener=!1,this.verboseMemoryLeak=!1,p.call(this,e)}A.prototype.off=function(){return this.emitter.off(this.event,this.listener),this},M.EventEmitter2=M,M.prototype.listenTo=function(e,t,r){if("object"!=typeof e)throw TypeError("target musts be an object");var n=this;function s(t){if("object"!=typeof t)throw TypeError("events must be an object");var i,s=r.reducers,o=O.call(n,e);i=-1===o?new m(n,e,r):n._observers[o];for(var c,l=u(t),a=l.length,f="function"==typeof s,h=0;h<a;h++)c=l[h],i.subscribe(c,t[c]||c,f?s:s&&s[c])}return r=d(r,{on:i,off:i,reducers:i},{on:w,off:w,reducers:j}),o(t)?s(_(t)):s("string"==typeof t?_(t.split(/\s+/)):t),this},M.prototype.stopListeningTo=function(e,t){var r=this._observers;if(!r)return!1;var n,i=r.length,s=!1;if(e&&"object"!=typeof e)throw TypeError("target should be an object");for(;i-- >0;)n=r[i],e&&n._target!==e||(n.unsubscribe(t),s=!0);return s},M.prototype.delimiter=".",M.prototype.setMaxListeners=function(e){e!==i&&(this._maxListeners=e,this._conf||(this._conf={}),this._conf.maxListeners=e)},M.prototype.getMaxListeners=function(){return this._maxListeners},M.prototype.event="",M.prototype.once=function(e,t,r){return this._once(e,t,!1,r)},M.prototype.prependOnceListener=function(e,t,r){return this._once(e,t,!0,r)},M.prototype._once=function(e,t,r,n){return this._many(e,1,t,r,n)},M.prototype.many=function(e,t,r,n){return this._many(e,t,r,!1,n)},M.prototype.prependMany=function(e,t,r,n){return this._many(e,t,r,!0,n)},M.prototype._many=function(e,t,r,n,i){var s=this;if("function"!=typeof r)throw new Error("many only accepts instances of Function");function o(){return 0==--t&&s.off(e,o),r.apply(this,arguments)}return o._origin=r,this._on(e,o,n,i)},M.prototype.emit=function(){if(!this._events&&!this._all)return!1;this._events||h.call(this);var e,t,r,n,i,s,o=arguments[0],c=this.wildcard;if("newListener"===o&&!this._newListener&&!this._events.newListener)return!1;if(c&&(e=o,"newListener"!==o&&"removeListener"!==o&&"object"==typeof o)){if(r=o.length,l)for(n=0;n<r;n++)if("symbol"==typeof o[n]){s=!0;break}s||(o=o.join(this.delimiter))}var a,f=arguments.length;if(this._all&&this._all.length)for(n=0,r=(a=this._all.slice()).length;n<r;n++)switch(this.event=o,f){case 1:a[n].call(this,o);break;case 2:a[n].call(this,o,arguments[1]);break;case 3:a[n].call(this,o,arguments[1],arguments[2]);break;default:a[n].apply(this,arguments)}if(c)a=[],x.call(this,a,e,this.listenerTree,0,r);else{if("function"==typeof(a=this._events[o])){switch(this.event=o,f){case 1:a.call(this);break;case 2:a.call(this,arguments[1]);break;case 3:a.call(this,arguments[1],arguments[2]);break;default:for(t=new Array(f-1),i=1;i<f;i++)t[i-1]=arguments[i];a.apply(this,t)}return!0}a&&(a=a.slice())}if(a&&a.length){if(f>3)for(t=new Array(f-1),i=1;i<f;i++)t[i-1]=arguments[i];for(n=0,r=a.length;n<r;n++)switch(this.event=o,f){case 1:a[n].call(this);break;case 2:a[n].call(this,arguments[1]);break;case 3:a[n].call(this,arguments[1],arguments[2]);break;default:a[n].apply(this,t)}return!0}if(!this.ignoreErrors&&!this._all&&"error"===o)throw arguments[1]instanceof Error?arguments[1]:new Error("Uncaught, unspecified 'error' event.");return!!this._all},M.prototype.emitAsync=function(){if(!this._events&&!this._all)return!1;this._events||h.call(this);var e,t,r,n,i,s,o=arguments[0],c=this.wildcard;if("newListener"===o&&!this._newListener&&!this._events.newListener)return Promise.resolve([!1]);if(c&&(e=o,"newListener"!==o&&"removeListener"!==o&&"object"==typeof o)){if(n=o.length,l)for(i=0;i<n;i++)if("symbol"==typeof o[i]){t=!0;break}t||(o=o.join(this.delimiter))}var a,f=[],u=arguments.length;if(this._all)for(i=0,n=this._all.length;i<n;i++)switch(this.event=o,u){case 1:f.push(this._all[i].call(this,o));break;case 2:f.push(this._all[i].call(this,o,arguments[1]));break;case 3:f.push(this._all[i].call(this,o,arguments[1],arguments[2]));break;default:f.push(this._all[i].apply(this,arguments))}if(c?(a=[],x.call(this,a,e,this.listenerTree,0)):a=this._events[o],"function"==typeof a)switch(this.event=o,u){case 1:f.push(a.call(this));break;case 2:f.push(a.call(this,arguments[1]));break;case 3:f.push(a.call(this,arguments[1],arguments[2]));break;default:for(r=new Array(u-1),s=1;s<u;s++)r[s-1]=arguments[s];f.push(a.apply(this,r))}else if(a&&a.length){if(a=a.slice(),u>3)for(r=new Array(u-1),s=1;s<u;s++)r[s-1]=arguments[s];for(i=0,n=a.length;i<n;i++)switch(this.event=o,u){case 1:f.push(a[i].call(this));break;case 2:f.push(a[i].call(this,arguments[1]));break;case 3:f.push(a[i].call(this,arguments[1],arguments[2]));break;default:f.push(a[i].apply(this,r))}}else if(!this.ignoreErrors&&!this._all&&"error"===o)return arguments[1]instanceof Error?Promise.reject(arguments[1]):Promise.reject("Uncaught, unspecified 'error' event.");return Promise.all(f)},M.prototype.on=function(e,t,r){return this._on(e,t,!1,r)},M.prototype.prependListener=function(e,t,r){return this._on(e,t,!0,r)},M.prototype.onAny=function(e){return this._onAny(e,!1)},M.prototype.prependAny=function(e){return this._onAny(e,!0)},M.prototype.addListener=M.prototype.on,M.prototype._onAny=function(e,t){if("function"!=typeof e)throw new Error("onAny only accepts instances of Function");return this._all||(this._all=[]),t?this._all.unshift(e):this._all.push(e),this},M.prototype._on=function(e,t,r,n){if("function"==typeof e)return this._onAny(e,t),this;if("function"!=typeof t)throw new Error("on only accepts instances of Function");this._events||h.call(this);var s,o=this;return n!==i&&(t=(s=P.call(this,e,t,n))[0],o=s[1]),this._newListener&&this.emit("newListener",e,t),this.wildcard?(k.call(this,e,t,r),o):(this._events[e]?("function"==typeof this._events[e]&&(this._events[e]=[this._events[e]]),r?this._events[e].unshift(t):this._events[e].push(t),!this._events[e].warned&&this._maxListeners>0&&this._events[e].length>this._maxListeners&&(this._events[e].warned=!0,y.call(this,this._events[e].length,e))):this._events[e]=t,o)},M.prototype.off=function(e,t){if("function"!=typeof t)throw new Error("removeListener only takes instances of Function");var r,n=[];if(this.wildcard){var i="string"==typeof e?e.split(this.delimiter):e.slice();if(!(n=x.call(this,null,i,this.listenerTree,0)))return this}else{if(!this._events[e])return this;r=this._events[e],n.push({_listeners:r})}for(var s=0;s<n.length;s++){var c=n[s];if(r=c._listeners,o(r)){for(var l=-1,a=0,f=r.length;a<f;a++)if(r[a]===t||r[a].listener&&r[a].listener===t||r[a]._origin&&r[a]._origin===t){l=a;break}if(l<0)continue;return this.wildcard?c._listeners.splice(l,1):this._events[e].splice(l,1),0===r.length&&(this.wildcard?delete c._listeners:delete this._events[e]),this._removeListener&&this.emit("removeListener",e,t),this}(r===t||r.listener&&r.listener===t||r._origin&&r._origin===t)&&(this.wildcard?delete c._listeners:delete this._events[e],this._removeListener&&this.emit("removeListener",e,t))}return this.listenerTree&&T(this.listenerTree),this},M.prototype.offAny=function(e){var t,r=0,n=0;if(e&&this._all&&this._all.length>0){for(r=0,n=(t=this._all).length;r<n;r++)if(e===t[r])return t.splice(r,1),this._removeListener&&this.emit("removeListenerAny",e),this}else{if(t=this._all,this._removeListener)for(r=0,n=t.length;r<n;r++)this.emit("removeListenerAny",t[r]);this._all=[]}return this},M.prototype.removeListener=M.prototype.off,M.prototype.removeAllListeners=function(e){if(e===i)return!this._events||h.call(this),this;if(this.wildcard){var t,r=x.call(this,null,e,this.listenerTree,0);if(!r)return this;for(t=0;t<r.length;t++)r[t]._listeners=null;this.listenerTree&&T(this.listenerTree)}else this._events&&(this._events[e]=null);return this},M.prototype.listeners=function(e){var t,r,n,s,o,c=this._events;if(e===i){if(this.wildcard)throw Error("event name required for wildcard emitter");if(!c)return[];for(s=(t=u(c)).length,n=[];s-- >0;)"function"==typeof(r=c[t[s]])?n.push(r):n.push.apply(n,r);return n}if(this.wildcard){if(!(o=this.listenerTree))return[];var l=[],a="string"==typeof e?e.split(this.delimiter):e.slice();return x.call(this,l,a,o,0),l}return c&&(r=c[e])?"function"==typeof r?[r]:r:[]},M.prototype.eventNames=function(e){var t=this._events;return this.wildcard?E.call(this,this.listenerTree,[],null,e):t?u(t):[]},M.prototype.listenerCount=function(e){return this.listeners(e).length},M.prototype.hasListeners=function(e){if(this.wildcard){var t=[],r="string"==typeof e?e.split(this.delimiter):e.slice();return x.call(this,t,r,this.listenerTree,0),t.length>0}var n=this._events,s=this._all;return!!(s&&s.length||n&&(e===i?u(n).length:n[e]))},M.prototype.listenersAny=function(){return this._all?this._all:[]},M.prototype.waitFor=function(e,t){var r=this,n=typeof t;return"number"===n?t={timeout:t}:"function"===n&&(t={filter:t}),L((t=d(t,{timeout:0,filter:i,handleError:!1,Promise,overload:!1},{filter:w,Promise:b})).Promise,(function(n,i,s){function o(){var s=t.filter;if(!s||s.apply(r,arguments))if(r.off(e,o),t.handleError){var c=arguments[0];c?i(c):n(v.apply(null,arguments).slice(1))}else n(v.apply(null,arguments))}s((function(){r.off(e,o)})),r._on(e,o,!1)}),{timeout:t.timeout,overload:t.overload})};var S=M.prototype;Object.defineProperties(M,{defaultMaxListeners:{get:function(){return S._maxListeners},set:function(e){if("number"!=typeof e||e<0||Number.isNaN(e))throw TypeError("n must be a non-negative number");S._maxListeners=e},enumerable:!0},once:{value:function(e,t,r){return L((r=d(r,{Promise,timeout:0,overload:!1},{Promise:b})).Promise,(function(r,n,i){var s;if("function"==typeof e.addEventListener)return s=function(){r(v.apply(null,arguments))},i((function(){e.removeEventListener(t,s)})),void e.addEventListener(t,s,{once:!0});var o,c=function(){o&&e.removeListener("error",o),r(v.apply(null,arguments))};"error"!==t&&(o=function(r){e.removeListener(t,c),n(r)},e.once("error",o)),i((function(){o&&e.removeListener("error",o),e.removeListener(t,c)})),e.once(t,c)}),{timeout:r.timeout,overload:r.overload})},writable:!0,configurable:!0}}),Object.defineProperties(S,{_maxListeners:{value:10,writable:!0,configurable:!0},_observers:{value:null,writable:!0,configurable:!0}}),(n=function(){return M}.call(t,r,t,e))===i||(e.exports=n)}()}},t={},function r(n){var i=t[n];if(void 0!==i)return i.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,r),s.exports}(650);var e,t}));
@@ -0,0 +1,24 @@
1
+ /*!
2
+ * EventEmitter2
3
+ * https://github.com/hij1nx/EventEmitter2
4
+ *
5
+ * Copyright (c) 2013 hij1nx
6
+ * Licensed under the MIT license.
7
+ */
8
+
9
+ /*!
10
+ * activity-streams
11
+ * https://github.com/silverbucket/activity-streams
12
+ *
13
+ * Developed and Maintained by:
14
+ * Nick Jennings <nick@silverbucket.net>
15
+ *
16
+ * activity-streams is released under the MIT (see LICENSE).
17
+ *
18
+ * You don't have to do anything special to choose one license or the other
19
+ * and you don't have to notify anyone which license you are using.
20
+ * Please see the corresponding license file for details of these licenses.
21
+ * You are free to use, modify and distribute this software, but all copyright
22
+ * information must remain.
23
+ *
24
+ */
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@sockethub/client",
3
+ "version": "5.0.0-alpha.3",
4
+ "description": "A JavaScript client for the Sockethub protocol gateway",
5
+ "main": "dist/sockethub-client.js",
6
+ "keywords": [
7
+ "sockethub",
8
+ "messaging",
9
+ "activitystreams",
10
+ "activity",
11
+ "streams",
12
+ "protocol",
13
+ "client"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/sockethub/sockethub.git",
18
+ "directory": "packages/client"
19
+ },
20
+ "homepage": "https://github.com/sockethub/sockethub/tree/master/packages/client",
21
+ "scripts": {
22
+ "clean": "npx rimraf dist coverage",
23
+ "clean:deps": "npx rimraf node_modules",
24
+ "compliance": "yarn run lint && yarn run test && yarn run coverage",
25
+ "test": "c8 -x src/bootstrap -x \"src/**/*.test.*\" mocha -r ts-node/register src/*.test.ts src/**/*.test.ts",
26
+ "coverage": "c8 check-coverage --statements 95 --branches 85 --functions 90 --lines 95",
27
+ "lint": "eslint \"**/*.ts\"",
28
+ "lint:fix": "eslint --fix \"**/*.ts\"",
29
+ "build": "tsc && webpack --config webpack.minified.config.js && webpack --config webpack.normal.config.js"
30
+ },
31
+ "author": "Nick Jennings <nick@silverbucket.net>",
32
+ "license": "LGPL-3.0+",
33
+ "devDependencies": {
34
+ "@sockethub/activity-streams": "^4.4.0-alpha.3",
35
+ "@types/chai": "4.3.0",
36
+ "@types/eslint": "8.4.1",
37
+ "@types/eventemitter2": "4.1.0",
38
+ "@types/mocha": "9.1.0",
39
+ "@types/node": "17.0.21",
40
+ "@types/proxyquire": "^1.3.28",
41
+ "@types/sinon": "10.0.11",
42
+ "@typescript-eslint/parser": "5.13.0",
43
+ "c8": "7.11.0",
44
+ "chai": "4.3.6",
45
+ "eslint": "8.10.0",
46
+ "eslint-cli": "1.1.1",
47
+ "eventemitter2": "6.4.5",
48
+ "mocha": "9.2.1",
49
+ "proxyquire": "2.1.3",
50
+ "sinon": "13.0.1",
51
+ "ts-node": "10.6.0",
52
+ "typescript": "4.6.2",
53
+ "webpack": "5.70.0",
54
+ "webpack-cli": "4.9.2"
55
+ },
56
+ "gitHead": "f02238a478b7ffd3f31d8deea292eb67e630a86b"
57
+ }
@@ -0,0 +1,237 @@
1
+ import proxyquire from 'proxyquire';
2
+ import { expect } from 'chai';
3
+ import * as sinon from 'sinon';
4
+ import { EventEmitter2 } from 'eventemitter2';
5
+
6
+ proxyquire.noPreserveCache();
7
+ proxyquire.noCallThru();
8
+
9
+ describe("SockethubClient bad initialization", () => {
10
+ it("no socket.io instance", () => {
11
+ const SockethubClient = proxyquire('./sockethub-client', {
12
+ '@sockethub/activity-streams': (config: any) => {}
13
+ });
14
+ expect(() => {
15
+ // @ts-ignore
16
+ const junk = new SockethubClient();
17
+ }).to.throw("SockethubClient requires a socket.io instance");
18
+ });
19
+ });
20
+
21
+ describe("SockethubClient", () => {
22
+ let asinstance: any, socket: any, sc: any, sandbox: any;
23
+
24
+ beforeEach(() => {
25
+ sandbox = sandbox = sinon.createSandbox();
26
+ socket = new EventEmitter2();
27
+ socket.__instance = 'socketio'; // used to uniquely identify the object we're passing in
28
+ sandbox.spy(socket, 'on');
29
+ sandbox.spy(socket, 'emit');
30
+ asinstance = new EventEmitter2();
31
+ sandbox.spy(asinstance, 'on');
32
+ sandbox.spy(asinstance, 'emit');
33
+ asinstance.Stream = sandbox.stub();
34
+ asinstance.Object = {
35
+ create: sandbox.stub(),
36
+ };
37
+ const SockethubClient = proxyquire('./sockethub-client', {
38
+ '@sockethub/activity-streams': (config: any) => {
39
+ return asinstance;
40
+ }
41
+ });
42
+ sc = new SockethubClient(socket);
43
+ sandbox.spy(sc.socket, 'on');
44
+ sandbox.spy(sc.socket, '_on');
45
+ sandbox.spy(sc.socket, 'emit');
46
+ sandbox.spy(sc.socket, '_emit');
47
+ });
48
+
49
+ afterEach(() => {
50
+ sinon.restore();
51
+ });
52
+
53
+ it("contains the ActivityStreams property", () => {
54
+ expect(asinstance).to.be.eql(sc.ActivityStreams);
55
+ expect(typeof asinstance.Stream).to.equal('function');
56
+ expect(typeof sc.ActivityStreams.Object.create).to.equal('function');
57
+ });
58
+
59
+ it("contains the socket property", () => {
60
+ expect(sc.socket instanceof EventEmitter2).to.be.true;
61
+ // the object we passed in should not be the publically available one
62
+ expect(sc.socket.__instance).to.not.equal('socketio');
63
+ expect(sc.debug).to.be.true;
64
+ expect(sc.online).to.be.false;
65
+ });
66
+
67
+ it("registers listeners for ActivityStream events", () => {
68
+ expect(asinstance.on.callCount).to.equal(1);
69
+ expect(asinstance.on.calledWithMatch('activity-object-create')).to.be.true;
70
+ });
71
+
72
+ it("registers a listeners for socket events", () => {
73
+ expect(socket.on.callCount).to.equal(5);
74
+ expect(socket.on.calledWithMatch('activity-object')).to.be.true;
75
+ expect(socket.on.calledWithMatch('connect')).to.be.true;
76
+ expect(socket.on.calledWithMatch('connect_error')).to.be.true;
77
+ expect(socket.on.calledWithMatch('disconnect')).to.be.true;
78
+ expect(socket.on.calledWithMatch('message')).to.be.true;
79
+ });
80
+
81
+ describe("event handling", () => {
82
+ it("activity-object", (done) => {
83
+ socket.emit('activity-object', {foo:"bar"});
84
+ setTimeout(() => {
85
+ sandbox.assert.calledWith(asinstance.Object.create, {foo:"bar"});
86
+ done();
87
+ }, 0);
88
+ });
89
+
90
+ it("activity-object-create", (done) => {
91
+ asinstance.emit('activity-object-create', {foo:"bar"});
92
+ setTimeout(() => {
93
+ expect(socket.emit.callCount).to.equal(1);
94
+ expect(socket.emit.calledWithMatch('activity-object', {foo:"bar"})).to.be.true;
95
+ done();
96
+ }, 0);
97
+ });
98
+
99
+ it("connect", (done) => {
100
+ expect(sc.online).to.be.false;
101
+ sc.socket.on("connect", () => {
102
+ expect(sc.online).to.be.true;
103
+ expect(sc.socket._emit.callCount).to.equal(1);
104
+ expect(sc.socket._emit.calledWithMatch('connect'));
105
+ done();
106
+ });
107
+ socket.emit("connect");
108
+ });
109
+
110
+ it("disconnect", (done) => {
111
+ sc.online = true;
112
+ sc.socket.on("disconnect", () => {
113
+ expect(sc.online).to.be.false;
114
+ expect(sc.socket._emit.callCount).to.equal(1);
115
+ expect(sc.socket._emit.calledWithMatch('disconnect'));
116
+ done();
117
+ });
118
+ socket.emit("disconnect");
119
+ });
120
+
121
+ it("connect_error", (done) => {
122
+ sc.socket.on("connect_error", () => {
123
+ expect(sc.socket._emit.callCount).to.equal(1);
124
+ expect(sc.socket._emit.calledWithMatch('connect_error'));
125
+ done();
126
+ });
127
+ socket.emit("connect_error");
128
+ });
129
+
130
+ it("message", (done) => {
131
+ sc.socket.on("message", () => {
132
+ expect(sc.socket._emit.callCount).to.equal(1);
133
+ expect(sc.socket._emit.calledWithMatch('message'));
134
+ done();
135
+ });
136
+ socket.emit("message");
137
+ });
138
+ });
139
+
140
+ describe("event emitting", () => {
141
+ it("message (no actor)", () => {
142
+ sc.online = true;
143
+ const callback = () => {};
144
+ expect(() => {
145
+ sc.socket.emit("message", {foo:"bar"}, callback);
146
+ }).to.throw("actor property not present");
147
+ });
148
+
149
+ it("message", (done) => {
150
+ sc.online = true;
151
+ const callback = () => {};
152
+ socket.once("message", (data: any, cb: any) => {
153
+ expect(data).to.be.eql({actor: "bar", type: "bar"});
154
+ expect(cb).to.be.eql(callback);
155
+ done();
156
+ });
157
+ sc.socket.emit("message", {actor:"bar", type: "bar"}, callback);
158
+ });
159
+
160
+ it("message (join)", (done) => {
161
+ sc.online = true;
162
+ const callback = () => {};
163
+ socket.once("message", (data: any, cb: any) => {
164
+ expect(data).to.be.eql({actor: "bar", type: "join"});
165
+ expect(cb).to.be.eql(callback);
166
+ done();
167
+ });
168
+ sc.socket.emit("message", {actor:"bar", type: "join"}, callback);
169
+ });
170
+
171
+ it("message (leave)", (done) => {
172
+ sc.online = true;
173
+ const callback = () => {};
174
+ socket.once("message", (data: any, cb: any) => {
175
+ expect(data).to.be.eql({actor: "bar", type: "leave"});
176
+ expect(cb).to.be.eql(callback);
177
+ done();
178
+ });
179
+ sc.socket.emit("message", {actor:"bar", type: "leave"}, callback);
180
+ });
181
+
182
+ it("message (connect)", (done) => {
183
+ sc.online = true;
184
+ const callback = () => {};
185
+ socket.once("message", (data: any, cb: any) => {
186
+ expect(data).to.be.eql({actor: "bar", type: "connect"});
187
+ expect(cb).to.be.eql(callback);
188
+ done();
189
+ });
190
+ sc.socket.emit("message", {actor:"bar", type: "connect"}, callback);
191
+ });
192
+
193
+ it("message (disconnect)", (done) => {
194
+ sc.online = true;
195
+ const callback = () => {};
196
+ socket.once("message", (data: any, cb: any) => {
197
+ expect(data).to.be.eql({actor: "bar", type: "disconnect"});
198
+ expect(cb).to.be.eql(callback);
199
+ done();
200
+ });
201
+ sc.socket.emit("message", {actor:"bar", type: "disconnect"}, callback);
202
+ });
203
+
204
+ it("message (offline)", (done) => {
205
+ sc.online = false;
206
+ const callback = () => {};
207
+ socket.once("message", (data: any, cb: any) => {
208
+ expect(data).to.be.eql({actor: "bar"});
209
+ expect(cb).to.be.eql(callback);
210
+ done();
211
+ });
212
+ sc.socket.emit("message", {actor:"bar"}, callback);
213
+ });
214
+
215
+ it("activity-object", (done) => {
216
+ sc.online = true;
217
+ const callback = () => {};
218
+ socket.once("activity-object", (data: any, cb: any) => {
219
+ expect(data).to.be.eql({actor: "bar"});
220
+ expect(cb).to.be.eql(callback);
221
+ done();
222
+ });
223
+ sc.socket.emit("activity-object", {actor:"bar"}, callback);
224
+ });
225
+
226
+ it("credentials", (done) => {
227
+ sc.online = true;
228
+ const callback = () => {};
229
+ socket.once("credentials", (data: any, cb: any) => {
230
+ expect(data).to.be.eql({actor: "bar"});
231
+ expect(cb).to.be.eql(callback);
232
+ done();
233
+ });
234
+ sc.socket.emit("credentials", {actor:"bar"}, callback);
235
+ });
236
+ });
237
+ });
@@ -0,0 +1,165 @@
1
+ import { EventEmitter2 } from 'eventemitter2';
2
+ import ASFactory from '@sockethub/activity-streams';
3
+
4
+ export interface ActivityObjectManager {
5
+ create(obj: any): any;
6
+ delete(id: string): boolean;
7
+ list(): Array<string>,
8
+ get(id: string, expand: boolean): any;
9
+ }
10
+
11
+ export interface ASManager {
12
+ Stream(meta: any): any,
13
+ Object: ActivityObjectManager,
14
+ emit(event, obj): void;
15
+ on(event, func): void;
16
+ once(event, func): void;
17
+ off(event, funcName): void;
18
+ }
19
+
20
+ class SockethubClient {
21
+ private _socket;
22
+ private events = {
23
+ 'credentials': new Map(),
24
+ 'activity-object': new Map(),
25
+ 'connect': new Map(),
26
+ 'join': new Map()
27
+ };
28
+ public socket;
29
+ public ActivityStreams: ASManager;
30
+ public online = false;
31
+ public debug = true;
32
+
33
+ constructor(socket) {
34
+ if (! socket) { throw new Error('SockethubClient requires a socket.io instance'); }
35
+ this._socket = socket;
36
+ // @ts-ignore
37
+ this.ActivityStreams = ASFactory({specialObjs: ['credentials']});
38
+
39
+ this.socket = this.createPublicEmitter();
40
+ this.registerSocketIOHandlers();
41
+
42
+ this.ActivityStreams.on('activity-object-create', (obj) => {
43
+ socket.emit('activity-object', obj, (err) => {
44
+ if (err) { console.error('failed to create activity-object ', err); }
45
+ else { this.eventActivityObject(obj); }
46
+ });
47
+ });
48
+
49
+ socket.on('activity-object', (obj) => {
50
+ this.ActivityStreams.Object.create(obj);
51
+ });
52
+ }
53
+
54
+ private createPublicEmitter(): EventEmitter2 {
55
+ let socket = new EventEmitter2({
56
+ wildcard: true,
57
+ verboseMemoryLeak: false
58
+ });
59
+ // @ts-ignore
60
+ socket._emit = socket.emit;
61
+ socket.emit = (event, content, callback): any => {
62
+ if (event === 'credentials') {
63
+ this.eventCredentials(content);
64
+ } else if (event === 'activity-object') {
65
+ this.eventActivityObject(content);
66
+ } else if (event === 'message') {
67
+ this.eventMessage(content);
68
+ }
69
+ this._socket.emit(event, content, callback);
70
+ };
71
+ return socket;
72
+ }
73
+
74
+ private eventActivityObject(content: any) {
75
+ if (content.id) {
76
+ this.events['activity-object'].set(content.id, content);
77
+ }
78
+ }
79
+
80
+ private eventCredentials(content: any) {
81
+ if ((content.object) && (content.object.type === 'credentials')) {
82
+ this.events['credentials'].set(content.actor.id || content.actor, content);
83
+ }
84
+ }
85
+
86
+ private eventMessage(content: any) {
87
+ if (! this.online) { return; }
88
+ // either store or delete the specified content onto the storedJoins map,
89
+ // for reply once we're back online.
90
+ const key = SockethubClient.getKey(content);
91
+ if (content.type === 'join' || content.type === 'connect') {
92
+ this.events[content.type].set(key, content);
93
+ } else if (content.type === 'leave') {
94
+ this.events['join'].delete(key);
95
+ } else if (content.type === 'disconnect') {
96
+ this.events['connect'].delete(key);
97
+ }
98
+ }
99
+
100
+ private static getKey(content: any) {
101
+ let actor = content.actor?.id || content.actor;
102
+ if (! actor) {
103
+ throw new Error("actor property not present for message type: " + content?.type);
104
+ }
105
+ let target = content.target ? content.target.id || content.target : '';
106
+ return actor + '-' + target;
107
+ }
108
+
109
+ private log(msg: string, obj?: any) {
110
+ if (this.debug) {
111
+ // eslint-disable-next-line security-node/detect-crlf
112
+ console.log(msg, obj);
113
+ }
114
+ }
115
+
116
+ private registerSocketIOHandlers() {
117
+ // middleware for events which don't deal in AS objects
118
+ const callHandler = (event: string) => {
119
+ return (obj, cb) => {
120
+ if (event === 'connect') {
121
+ this.online = true;
122
+ this.replay('activity-object', this.events['activity-object']);
123
+ this.replay('credentials', this.events['credentials']);
124
+ this.replay('message', this.events['connect']);
125
+ this.replay('message', this.events['join']);
126
+ } else if (event === 'disconnect') {
127
+ this.online = false;
128
+ }
129
+ this.socket._emit(event, obj, cb);
130
+ };
131
+ };
132
+
133
+ // register for events that give us information on connection status
134
+ this._socket.on('connect', callHandler('connect'));
135
+ this._socket.on('connect_error', callHandler('connect_error'));
136
+ this._socket.on('disconnect', callHandler('disconnect'));
137
+
138
+ // use as a middleware to receive incoming Sockethub messages and unpack them
139
+ // using the ActivityStreams library before passing them along to the app.
140
+ this._socket.on('message', (obj, cb) => {
141
+ this.socket._emit('message', this.ActivityStreams.Stream(obj), cb);
142
+ });
143
+ }
144
+
145
+ private replay(name: string, asMap: any) {
146
+ asMap.forEach((obj) => {
147
+ this.log(`replaying ${name}`, obj);
148
+ this._socket.emit(name, obj);
149
+ });
150
+ };
151
+ }
152
+
153
+ if (typeof module === 'object' && module.exports) {
154
+ module.exports = SockethubClient;
155
+ }
156
+
157
+ if (typeof exports === 'object') {
158
+ exports = SockethubClient; // lgtm [js/useless-assignment-to-local]
159
+ }
160
+
161
+ // @ts-ignore
162
+ if (typeof window === 'object') {
163
+ // @ts-ignore
164
+ window.SockethubClient = SockethubClient;
165
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "allowJs": false,
5
+ "outDir": "dist",
6
+ "rootDir": "src",
7
+ "baseUrl": "/",
8
+ "sourceRoot": "/",
9
+ "mapRoot": "/",
10
+ },
11
+ "include": [
12
+ "src"
13
+ ],
14
+ "exclude": [
15
+ "**/*.test.ts"
16
+ ]
17
+ }
@@ -0,0 +1,14 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './dist/sockethub-client.js',
5
+ mode: "production",
6
+ optimization: {
7
+ minimize: true
8
+ },
9
+ output: {
10
+ filename: './dist/sockethub-client.min.js',
11
+ path: path.resolve(__dirname, './'),
12
+ libraryTarget: 'umd'
13
+ }
14
+ };
@@ -0,0 +1,14 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ entry: './dist/sockethub-client.js',
5
+ mode: "production",
6
+ optimization: {
7
+ minimize: false
8
+ },
9
+ output: {
10
+ filename: './dist/sockethub-client.js',
11
+ path: path.resolve(__dirname, './'),
12
+ libraryTarget: 'umd'
13
+ }
14
+ };