You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+120Lines changed: 120 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,8 @@ __Options__
95
95
through this pub/sub adapter. Defaults to `ShareDB.MemoryPubSub()`.
96
96
*`options.milestoneDb`_(instance of ShareDB.MilestoneDB`)_
97
97
Store snapshots of documents at a specified interval of versions
98
+
*`options.presence`_boolean_
99
+
Enable presence functionality. Off by default. Note that this feature is not optimized for large numbers of clients and could cause fan-out issues
98
100
99
101
#### Database Adapters
100
102
*`ShareDB.MemoryDB`, backed by a non-persistent database with no queries
@@ -158,6 +160,7 @@ Register a new middleware.
158
160
the database.
159
161
*`'receive'`: Received a message from a client
160
162
*`'reply'`: About to send a non-error reply to a client message
163
+
*`'sendPresence'`: About to send presence information to a client
161
164
*`fn`_(Function(context, callback))_
162
165
Call this function at the time specified by `action`.
163
166
*`context` will always have the following properties:
@@ -307,6 +310,20 @@ Get a read-only snapshot of a document at the requested version.
307
310
}
308
311
```
309
312
313
+
`connection.getPresence(channel): Presence;`
314
+
Get a [`Presence`](#class-sharedbpresence) instance that can be used to subscribe to presence information to other clients, and create instances of local presence.
Get a special [`DocPresence`](#class-sharedbdocpresence) instance that can be used to subscribe to presence information to other clients, and create instances of local presence. This is tied to a `Doc`, and all presence will be automatically transformed against ops to keep presence current. Note that the `Doc` must be of a type that supports presence.
Representation of the presence data associated with a given channel.
663
+
664
+
#### `subscribe`
665
+
666
+
```javascript
667
+
presence.subscribe(callback):void;
668
+
```
669
+
670
+
Subscribe to presence updates from other clients. Note that presence can be submitted without subscribing, but remote clients will not be able to re-request presence from you if you are not subscribed.
671
+
672
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
673
+
674
+
#### `unsubscribe`
675
+
676
+
```javascript
677
+
presence.unsubscribe(callback):void;
678
+
```
679
+
680
+
Unsubscribe from presence updates from remote clients.
681
+
682
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
683
+
684
+
#### `on`
685
+
686
+
```javascript
687
+
presence.on('receive', callback):void;
688
+
```
689
+
690
+
An update from a remote presence client has been received.
691
+
692
+
*`callback`_Function_: callback for handling the received presence: `function (presenceId, presenceValue): void;`
693
+
694
+
```javascript
695
+
presence.on('error', callback):void;
696
+
```
697
+
698
+
A presence-related error has occurred.
699
+
700
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
701
+
702
+
#### `create`
703
+
704
+
```javascript
705
+
presence.create(presenceId): LocalPresence;
706
+
```
707
+
708
+
Create an instance of [`LocalPresence`](#class-sharedblocalpresence), which can be used to represent local presence. Many or none such local presences may exist on a `Presence` instance.
709
+
710
+
*`presenceId`_string (optional)_: a unique ID representing the local presence. Remember - depending on use-case - the same client might have multiple presences, so this might not necessarily be a user or client ID. If one is not provided, a random ID will be assigned for you.
711
+
712
+
#### `destroy`
713
+
714
+
```javascript
715
+
presence.destroy(callback);
716
+
```
717
+
718
+
Updates all remote clients with a `null` presence, and removes it from the `Connection` cache, so that it can be garbage-collected. This should be called when you are done with a presence, and no longer need to use it to fire updates.
719
+
720
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
721
+
722
+
### Class: `ShareDB.DocPresence`
723
+
724
+
Specialised case of [`Presence`](#class-sharedbpresence), which is tied to a specific [`Doc`](#class-sharedbdoc). When using presence with an associated `Doc`, any ops applied to the `Doc` will automatically be used to transform associated presence. On destroy, the `DocPresence` will unregister its listeners from the `Doc`.
725
+
726
+
See [`Presence`](#class-sharedbpresence) for available methods.
727
+
728
+
### Class: `ShareDB.LocalPresence`
729
+
730
+
`LocalPresence` represents the presence of the local client in a given `Doc`. For example, this might be the position of a caret in a text document; which field has been highlighted in a complex JSON object; etc. Multiple presences may exist per `Doc` even on the same client.
731
+
732
+
#### `submit`
733
+
734
+
```javascript
735
+
localPresence.submit(presence, callback):void;
736
+
```
737
+
738
+
Update the local representation of presence, and broadcast that presence to any other document presence subscribers.
739
+
740
+
*`presence`_Object_: the presence object to broadcast. The structure of this will depend on the OT type
741
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
742
+
743
+
#### `send`
744
+
745
+
```javascript
746
+
localPresence.send(callback):void;
747
+
```
748
+
749
+
Send presence like `submit`, but without updating the value. Can be useful if local presences expire periodically.
750
+
751
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
752
+
753
+
#### `destroy`
754
+
755
+
```javascript
756
+
localPresence.destroy(callback):void;
757
+
```
758
+
759
+
Informs all remote clients that this presence is now `null`, and deletes itself for garbage collection.
760
+
761
+
*`callback`_Function_: a callback with the signature `function (error: Error): void;`
762
+
643
763
### Logging
644
764
645
765
By default, ShareDB logs to `console`. This can be overridden if you wish to silence logs, or to log to your own logging driver or alert service.
This is a collaborative rich text editor using [Quill](https://github.com/quilljs/quill) and the [rich-text OT type](https://github.com/ottypes/rich-text).
4
+
5
+
In this demo, data is not persisted. To persist data, run a Mongo
0 commit comments