@mescius/js-collaboration-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 +126 -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 client 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-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,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The collaboration client, provides bidirectional communication.
|
|
3
|
+
*/
|
|
4
|
+
export declare class Client {
|
|
5
|
+
url: string;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a new collaboration client.
|
|
9
|
+
* @param url - The server url.
|
|
10
|
+
*/
|
|
11
|
+
constructor(url?: string);
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Connect to a room.
|
|
15
|
+
* @param roomId - The room id.
|
|
16
|
+
* @param options - The connect options.
|
|
17
|
+
*/
|
|
18
|
+
connect(roomId: string, options?: IConnectOptions): Connection;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IConnectOptions {
|
|
22
|
+
/**
|
|
23
|
+
* The query arguments.
|
|
24
|
+
*/
|
|
25
|
+
query?: IQuery;
|
|
26
|
+
/**
|
|
27
|
+
* The authentication data.
|
|
28
|
+
*/
|
|
29
|
+
auth?: IAuth;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface IQuery {
|
|
33
|
+
[key: string]: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface IAuth {
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The collaboration connection of client.
|
|
41
|
+
*/
|
|
42
|
+
export declare class Connection {
|
|
43
|
+
/**
|
|
44
|
+
* Get the connection id.
|
|
45
|
+
* @returns {string} Returns the connection id.
|
|
46
|
+
*/
|
|
47
|
+
get id(): string;
|
|
48
|
+
/**
|
|
49
|
+
* Gets whether the connection can send messages.
|
|
50
|
+
* @returns {boolean} Returns whether the connection can send messages.
|
|
51
|
+
*/
|
|
52
|
+
get canSend(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Send a message to the server.
|
|
55
|
+
* @param data - The data to send.
|
|
56
|
+
* @param [type] - The message type.
|
|
57
|
+
*/
|
|
58
|
+
send(data: MessageData, type?: MessageType): void;
|
|
59
|
+
/**
|
|
60
|
+
* Close the connection.
|
|
61
|
+
*/
|
|
62
|
+
close(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Register a listener for an event.
|
|
65
|
+
* @param name - The event name.
|
|
66
|
+
* @param f - The event handler.
|
|
67
|
+
*/
|
|
68
|
+
on<NAME extends keyof IEvents & string>(name: NAME, f: IEvents[NAME]): IEvents[NAME];
|
|
69
|
+
/**
|
|
70
|
+
* Register a listener for an event that will only be called once.
|
|
71
|
+
* @param name - The event name.
|
|
72
|
+
* @param f - The event handler.
|
|
73
|
+
*/
|
|
74
|
+
once<NAME_1 extends keyof IEvents & string>(name: NAME_1, f: IEvents[NAME_1]): void;
|
|
75
|
+
/**
|
|
76
|
+
* Remove a listener for an event.
|
|
77
|
+
* @param name - The event name.
|
|
78
|
+
* @param f - The event handler.
|
|
79
|
+
*/
|
|
80
|
+
off<NAME_2 extends keyof IEvents & string>(name: NAME_2, f: IEvents[NAME_2]): void;
|
|
81
|
+
/**
|
|
82
|
+
* Destroy the observable.
|
|
83
|
+
*/
|
|
84
|
+
destroy(): void;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface IEvents {
|
|
88
|
+
open: () => void;
|
|
89
|
+
message: (data: MessageData, type: MessageType) => void;
|
|
90
|
+
close: (reason: CloseReason) => void;
|
|
91
|
+
error: (e: unknown) => void;
|
|
92
|
+
reconnect: (attempts: number) => void;
|
|
93
|
+
reconnectFailed: (err?: Error) => void;
|
|
94
|
+
reconnectAttempts: (attempts: number) => void;
|
|
95
|
+
connectionStateChanged: () => void;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export type MessageData = unknown;
|
|
99
|
+
export type MessageType = string | null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The reason of the connection closed.
|
|
103
|
+
*/
|
|
104
|
+
export enum CloseReason {
|
|
105
|
+
/**
|
|
106
|
+
* The client has manually disconnected.
|
|
107
|
+
*/
|
|
108
|
+
CLIENT_DISCONNECT,
|
|
109
|
+
/**
|
|
110
|
+
* The server has manually disconnected.
|
|
111
|
+
*/
|
|
112
|
+
SERVER_DISCONNECT,
|
|
113
|
+
/**
|
|
114
|
+
* The client did not send a PONG packet in the pingTimeout delay.
|
|
115
|
+
*/
|
|
116
|
+
PING_TIMEOUT,
|
|
117
|
+
/**
|
|
118
|
+
* The transport connection was closed.
|
|
119
|
+
*/
|
|
120
|
+
TRANSPORT_CLOSE,
|
|
121
|
+
/**
|
|
122
|
+
* The transport connection has encountered an error.
|
|
123
|
+
*/
|
|
124
|
+
TRANSPORT_ERROR
|
|
125
|
+
}
|
|
126
|
+
|
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 o=t();for(var n in o)("object"==typeof exports?exports:e)[n]=o[n]}}(this,(()=>(()=>{"use strict";var e={234:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Client=void 0;const n=o(42);t.Client=class{constructor(e){this.url=e||"/"}connect(e,t){return new n.Connection(this.url,{query:Object.assign({roomId:e},null==t?void 0:t.query),auth:null==t?void 0:t.auth})}}},42:(e,t,o)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Connection=t.CloseReason=void 0;const n=o(87),r=o(884);var s;!function(e){e[e.CLIENT_DISCONNECT=0]="CLIENT_DISCONNECT",e[e.SERVER_DISCONNECT=1]="SERVER_DISCONNECT",e[e.PING_TIMEOUT=2]="PING_TIMEOUT",e[e.TRANSPORT_CLOSE=3]="TRANSPORT_CLOSE",e[e.TRANSPORT_ERROR=4]="TRANSPORT_ERROR"}(s||(t.CloseReason=s={}));class i extends r.Observable{constructor(e,t){var o;super(),t=null!=t?t:{},this._socket=(0,n.io)(e,Object.assign(Object.assign({},t),{perMessageDeflate:{threshold:1024},transports:["websocket"],path:null!==(o=t.path)&&void 0!==o?o:r.DEFAULT_REQUEST_PATH})),this._socket.on("connect",this.onopen.bind(this)),this._socket.on("disconnect",this.onclose.bind(this)),this._socket.on("connect_error",(e=>this.emit("error",[e]))),this._socket.on(r.SOCKET_IO_MESSAGE_EVENT,this.onmessage.bind(this))}get id(){return this._socket.id}get canSend(){return this._socket.connected}send(e,t){this._socket.emit(r.SOCKET_IO_MESSAGE_EVENT,(0,r.encodeMessage)(e,t))}close(){this._socket.disconnect()}onopen(){this.emit("open",[]),this.emit("connectionStateChanged",[])}onmessage(e){this.emit("message",(0,r.decodeMessage)(e))}onclose(e){this.emit("close",[c(e)]),this.emit("connectionStateChanged",[])}}function c(e){switch(e){case"io server disconnect":return s.SERVER_DISCONNECT;case"io client disconnect":return s.CLIENT_DISCONNECT;case"transport close":return s.TRANSPORT_CLOSE;default:return s.TRANSPORT_ERROR}}t.Connection=i},871:e=>{e.exports=require("buffer")},331:e=>{e.exports=require("pako")},87:e=>{e.exports=require("socket.io-client")},884:function(e,t,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),r=this&&this.__exportStar||function(e,t){for(var o in e)"default"===o||Object.prototype.hasOwnProperty.call(t,o)||n(t,e,o)};Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_REQUEST_PATH=void 0,r(o(589),t),r(o(735),t),r(o(31),t),r(o(76),t),r(o(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,o){var n=this&&this.__createBinding||(Object.create?function(e,t,o,n){void 0===n&&(n=o);var r=Object.getOwnPropertyDescriptor(t,o);r&&!("get"in r?!t.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return t[o]}}),Object.defineProperty(e,n,r)}:function(e,t,o,n){void 0===n&&(n=o),e[n]=t[o]}),r=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)"default"!==o&&Object.prototype.hasOwnProperty.call(e,o)&&n(t,e,o);return r(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]?u(e[1]):e[1],e[0]]};const i=s(o(331)),c=o(871);function a(e){const t=(new TextEncoder).encode(e),o=i.deflate(t);return c.Buffer.from(o).toString("base64")}function u(e){const t=c.Buffer.from(e,"base64"),o=i.inflate(new Uint8Array(t));return(new TextDecoder).decode(o)}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 o=this.middlewares.get(e);if(!o)return;o=o.slice();const n=async e=>{if(e)throw e;const r=null==o?void 0:o.shift();r&&await r(t,n)};await n()}emit(e,t){const o=this.hooks.get(e);o&&o.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 o(this._observers,e,(()=>new Set)).add(t),t}once(e,t){const o=(...n)=>{this.off(e,o),t(...n)};this.on(e,o)}off(e,t){const o=this._observers.get(e);void 0!==o&&(o.delete(t),0===o.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 o=(e,t,o)=>{let n=e.get(t);return void 0===n&&(n=o(),e.set(t,n)),n}},76:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.isNullOrUndefined=function(e){return null==e}}},t={};function o(n){var r=t[n];if(void 0!==r)return r.exports;var s=t[n]={exports:{}};return e[n].call(s.exports,s,s.exports,o),s.exports}var n={};return(()=>{var e=n;Object.defineProperty(e,"__esModule",{value:!0}),e.logger=e.Connection=e.CloseReason=e.Client=void 0;const t=o(234);Object.defineProperty(e,"Client",{enumerable:!0,get:function(){return t.Client}});const r=o(42);Object.defineProperty(e,"CloseReason",{enumerable:!0,get:function(){return r.CloseReason}}),Object.defineProperty(e,"Connection",{enumerable:!0,get:function(){return r.Connection}});const s=o(884);Object.defineProperty(e,"logger",{enumerable:!0,get:function(){return s.logger}})})(),n})()));
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mescius/js-collaboration-client",
|
|
3
|
+
"version": "18.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"author": {
|
|
7
|
+
"email": "us.sales@mescius.com",
|
|
8
|
+
"name": "MESCIUS inc"
|
|
9
|
+
},
|
|
10
|
+
"license": "Commercial",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"socket.io-client": "4.8.1",
|
|
13
|
+
"buffer": "6.0.3",
|
|
14
|
+
"pako": "2.1.0"
|
|
15
|
+
},
|
|
16
|
+
"description": "SpreadJS Collaboration plugin",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"js-collaboration-client",
|
|
19
|
+
"js-collaboration",
|
|
20
|
+
"collaboration",
|
|
21
|
+
"spread",
|
|
22
|
+
"sheet",
|
|
23
|
+
"javascript",
|
|
24
|
+
"excel",
|
|
25
|
+
"spreadjs"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://developer.mescius.com/spreadjs"
|
|
28
|
+
}
|