@mescius/js-collaboration-presence-client 18.0.0
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.
- package/README.md +18 -0
- package/dist/index.d.ts +82 -0
- package/dist/index.js +1 -0
- package/package.json +28 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SpreadJS Collaboration Plugin
|
|
2
|
+
|
|
3
|
+
The js collaboration presence client package is one of the plugins for [SpreadJS](https://developer.mescius.com/spreadjs).
|
|
4
|
+
|
|
5
|
+
Extends SpreadJS with support for collaboration
|
|
6
|
+
|
|
7
|
+
For a detailed listing of SpreadJS sub-libraries and plug-ins, please see [Using SpreadJS Libraries](https://developer.mescius.com/spreadjs/docs/getstarted/modules).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
```sh
|
|
11
|
+
npm install @mescius/js-collaboration-presence-client
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Getting more help
|
|
15
|
+
Visit the SpreadJS home page to get more info about the library:
|
|
16
|
+
[https://developer.mescius.com/spreadjs](https://developer.mescius.com/spreadjs)
|
|
17
|
+
|
|
18
|
+
You can ask any question about SpreadJS using the [SpreadJS Forum](https://developer.mescius.com/forums/spreadjs).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { Connection } from "@mescius/js-collaboration-client";
|
|
2
|
+
|
|
3
|
+
export interface IPresences<P> {
|
|
4
|
+
[id: string]: P;
|
|
5
|
+
}
|
|
6
|
+
export interface IEvents<P> {
|
|
7
|
+
add: (presences: IPresences<P>) => void;
|
|
8
|
+
update: (presences: IPresences<P>) => void;
|
|
9
|
+
remove: (presencesIds: string[]) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @example
|
|
14
|
+
* const uiComponent = new xxx.uiComponent();
|
|
15
|
+
* const conn = new Client('ws://localhost:8080/').connect('room1');
|
|
16
|
+
* const presence = new Presence(conn);
|
|
17
|
+
* presence.subscribe(() => {
|
|
18
|
+
* uiComponent.showPresences(presence.others);
|
|
19
|
+
* uiComponent.on('selectionChanges', () => {
|
|
20
|
+
* uiComponent.submitLocal({ userId: xxx, selection: xxx });
|
|
21
|
+
* });
|
|
22
|
+
* presence.on('add', () => {
|
|
23
|
+
* uiComponent.showPresences(presence.others);
|
|
24
|
+
* });
|
|
25
|
+
* presence.on('update', () => {
|
|
26
|
+
* uiComponent.showPresences(presence.others);
|
|
27
|
+
* });
|
|
28
|
+
* presence.on('remove', () => {
|
|
29
|
+
* uiComponent.showPresences(presence.others);
|
|
30
|
+
* });
|
|
31
|
+
* presence.submitLocal({ userId: xxx, selection: xxx });
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export declare class Presence<P> {
|
|
35
|
+
constructor(conn: Connection);
|
|
36
|
+
get id(): string;
|
|
37
|
+
/**
|
|
38
|
+
* The local presence object.
|
|
39
|
+
*/
|
|
40
|
+
local?: P;
|
|
41
|
+
/**
|
|
42
|
+
* The other presence objects.
|
|
43
|
+
*/
|
|
44
|
+
others: IPresences<P>;
|
|
45
|
+
conn: Connection;
|
|
46
|
+
/**
|
|
47
|
+
* Submit the local presence object to the server, server will broadcast the presence object to other clients.
|
|
48
|
+
* @param p - The local presence object.
|
|
49
|
+
*/
|
|
50
|
+
submitLocal(p: P): void;
|
|
51
|
+
/**
|
|
52
|
+
* Remove the local presence object from the server, server will broadcast to other clients.
|
|
53
|
+
*/
|
|
54
|
+
removeLocal(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Subscribe to presences.
|
|
57
|
+
* @param callback - After the subscription is successful, can get others presences by "presence.others".
|
|
58
|
+
*/
|
|
59
|
+
subscribe(callback: () => void): void;
|
|
60
|
+
/**
|
|
61
|
+
* Register a listener for an event.
|
|
62
|
+
* @param name - The event name.
|
|
63
|
+
* @param f - The event handler.
|
|
64
|
+
*/
|
|
65
|
+
on<NAME extends keyof IEvents<P> & string>(name: NAME, f: IEvents<P>[NAME]): IEvents<P>[NAME];
|
|
66
|
+
/**
|
|
67
|
+
* Register a listener for an event that will only be called once.
|
|
68
|
+
* @param name - The event name.
|
|
69
|
+
* @param f - The event handler.
|
|
70
|
+
*/
|
|
71
|
+
once<NAME_1 extends keyof IEvents<P> & string>(name: NAME_1, f: IEvents<P>[NAME_1]): void;
|
|
72
|
+
/**
|
|
73
|
+
* Remove a listener for an event.
|
|
74
|
+
* @param name - The event name.
|
|
75
|
+
* @param f - The event handler.
|
|
76
|
+
*/
|
|
77
|
+
off<NAME_2 extends keyof IEvents<P> & string>(name: NAME_2, f: IEvents<P>[NAME_2]): void;
|
|
78
|
+
/**
|
|
79
|
+
* Destroy the observable.
|
|
80
|
+
*/
|
|
81
|
+
destroy(): void;
|
|
82
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var s=t();for(var r in s)("object"==typeof exports?exports:e)[r]=s[r]}}(this,(()=>(()=>{"use strict";var e={871:e=>{e.exports=require("buffer")},331:e=>{e.exports=require("pako")},884:function(e,t,s){var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var i=Object.getOwnPropertyDescriptor(t,s);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,i)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_REQUEST_PATH=void 0,i(s(589),t),i(s(735),t),i(s(31),t),i(s(76),t),i(s(959),t),t.DEFAULT_REQUEST_PATH="/collaboration/"},31:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.logger=void 0,t.logger=class{static info(e,...t){}static warn(e,...t){}static error(e,...t){}}},735:function(e,t,s){var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s);var i=Object.getOwnPropertyDescriptor(t,s);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[s]}}),Object.defineProperty(e,r,i)}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var s in e)"default"!==s&&Object.prototype.hasOwnProperty.call(e,s)&&r(t,e,s);return i(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.SOCKET_IO_MESSAGE_EVENT=void 0,t.encodeMessage=function(e,t=null){return[t,"string"==typeof e?a(e):e]},t.decodeMessage=function(e){return["string"==typeof e[1]?d(e[1]):e[1],e[0]]};const n=o(s(331)),c=s(871);function a(e){const t=(new TextEncoder).encode(e),s=n.deflate(t);return c.Buffer.from(s).toString("base64")}function d(e){const t=c.Buffer.from(e,"base64"),s=n.inflate(new Uint8Array(t));return(new TextDecoder).decode(s)}t.SOCKET_IO_MESSAGE_EVENT="m"},589:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Middleware=void 0,t.Middleware=class{constructor(){this.middlewares=new Map,this.hooks=new Map}use(e,t){this.middlewares.has(e)||this.middlewares.set(e,[]),this.middlewares.get(e).push(t)}on(e,t){this.hooks.has(e)||this.hooks.set(e,[]),this.hooks.get(e).push(t)}async trigger(e,t){let s=this.middlewares.get(e);if(!s)return;s=s.slice();const r=async e=>{if(e)throw e;const i=null==s?void 0:s.shift();i&&await i(t,r)};await r()}emit(e,t){const s=this.hooks.get(e);s&&s.forEach((e=>e(t)))}}},959:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Observable=void 0,t.Observable=class{constructor(){this._observers=new Map}on(e,t){return s(this._observers,e,(()=>new Set)).add(t),t}once(e,t){const s=(...r)=>{this.off(e,s),t(...r)};this.on(e,s)}off(e,t){const s=this._observers.get(e);void 0!==s&&(s.delete(t),0===s.size&&this._observers.delete(e))}emit(e,t){return Array.from((this._observers.get(e)||new Map).values()).forEach((e=>e(...t)))}destroy(){this._observers=new Map}};const s=(e,t,s)=>{let r=e.get(t);return void 0===r&&(r=s(),e.set(t,r)),r}},76:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isNullOrUndefined=function(e){return null==e}},773:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.PRESENCE_MESSAGE_TYPE=t.Actions=void 0,t.createPresences=function(e,t){const s={};for(let r=0;r<e.length;r++)s[e[r]]=t[r];return s},function(e){e.subscribe="s",e.unsubscribe="u",e.update="d",e.add="a",e.remove="r"}(s||(t.Actions=s={})),t.PRESENCE_MESSAGE_TYPE="p"}},t={};function s(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,s),o.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.Presence=void 0;const t=s(773),i=s(884);class o extends i.Observable{constructor(e){super(),this.conn=e,this.others={},this._subscribeCallback=[],e.on("message",this._messageHandler.bind(this))}get id(){return this.conn.id}submitLocal(e){this.local=e,this._send({a:t.Actions.update,presence:e})}removeLocal(){delete this.local,this._send({a:t.Actions.remove})}subscribe(e){var s;null===(s=this._subscribeCallback)||void 0===s||s.push(e),this._send({a:t.Actions.subscribe})}_send(e){this.conn.send(JSON.stringify(e),t.PRESENCE_MESSAGE_TYPE)}_messageHandler(e,s){if(s!==t.PRESENCE_MESSAGE_TYPE)return;if("string"!=typeof e)return;const r=JSON.parse(e);switch(r.a){case t.Actions.subscribe:this._handleSubscribe(r);break;case t.Actions.add:this._handleAdd(r);break;case t.Actions.update:this._handleUpdate(r);break;case t.Actions.remove:this._handleRemove(r)}}_handleSubscribe(e){e.presences&&(this.others={},this._updatePresences(e.presences),this._subscribeCallback.forEach((e=>e())),this._subscribeCallback=[])}_handleAdd(e){const t=e.presences;t&&(this._updatePresences(t),this.emit("add",[t]))}_handleUpdate(e){const t=e.presences;t&&(this._updatePresences(t),this.emit("update",[t]))}_handleRemove(e){const t=e.presencesIds;if(!t||0===t.length)return;const s=this.id;t.forEach((e=>{e!==s?delete this.others[e]:delete this.local})),this.emit("remove",[t])}_updatePresences(e){const t=this.id;Object.keys(e).forEach((s=>{s!==t?this.others[s]=e[s]:this.local=e[s]}))}}e.Presence=o})(),r})()));
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mescius/js-collaboration-presence-client",
|
|
3
|
+
"version": "18.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"js-collaboration-presence-client",
|
|
8
|
+
"js-collaboration-presence",
|
|
9
|
+
"js-collaboration",
|
|
10
|
+
"collaboration",
|
|
11
|
+
"presence",
|
|
12
|
+
"spread",
|
|
13
|
+
"sheet",
|
|
14
|
+
"javascript",
|
|
15
|
+
"excel",
|
|
16
|
+
"spreadjs"
|
|
17
|
+
],
|
|
18
|
+
"author": {
|
|
19
|
+
"email": "us.sales@mescius.com",
|
|
20
|
+
"name": "MESCIUS inc"
|
|
21
|
+
},
|
|
22
|
+
"license": "Commercial",
|
|
23
|
+
"description": "SpreadJS Collaboration plugin",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@mescius/js-collaboration-client": "18.0.0"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://developer.mescius.com/spreadjs"
|
|
28
|
+
}
|