@yorkie-js/sdk 0.6.29 → 0.6.34
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/dist/presence.html +140 -0
- package/dist/yorkie-js-sdk.d.ts +242 -38
- package/dist/yorkie-js-sdk.es.js +1267 -190
- package/dist/yorkie-js-sdk.es.js.map +1 -1
- package/dist/yorkie-js-sdk.js +1267 -190
- package/dist/yorkie-js-sdk.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<title>Presence Example</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<div class="container">
|
|
9
|
+
<h1>Presence</h1>
|
|
10
|
+
<p class="subtitle">Real-time online user tracking with Yorkie</p>
|
|
11
|
+
|
|
12
|
+
<div class="info-box">
|
|
13
|
+
<p><strong>Key:</strong> <span id="room-id">key-123</span></p>
|
|
14
|
+
<p><strong>Client ID:</strong> <span id="client-id">-</span></p>
|
|
15
|
+
<p>
|
|
16
|
+
<strong>Status:</strong>
|
|
17
|
+
<span id="status" class="status disconnected">Disconnected</span>
|
|
18
|
+
</p>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div class="counter-section">
|
|
22
|
+
<span class="counter-label">👥 Users Online</span>
|
|
23
|
+
<span class="counter-value" id="counter-value">0</span>
|
|
24
|
+
<button id="join-btn" class="join-btn">Join Room</button>
|
|
25
|
+
<button id="leave-btn" class="leave-btn" disabled>Leave Room</button>
|
|
26
|
+
</div>
|
|
27
|
+
|
|
28
|
+
<div class="events-log">
|
|
29
|
+
<h3>📋 Activity Log</h3>
|
|
30
|
+
<div id="events-container"></div>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
|
|
34
|
+
<script type="module">
|
|
35
|
+
import yorkie from './src/yorkie.ts';
|
|
36
|
+
|
|
37
|
+
const roomId = 'room-123';
|
|
38
|
+
const client = new yorkie.Client({
|
|
39
|
+
rpcAddr: 'http://localhost:8080',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let presence = null;
|
|
43
|
+
const events = [];
|
|
44
|
+
|
|
45
|
+
const elements = {
|
|
46
|
+
clientId: document.getElementById('client-id'),
|
|
47
|
+
status: document.getElementById('status'),
|
|
48
|
+
counterValue: document.getElementById('counter-value'),
|
|
49
|
+
joinBtn: document.getElementById('join-btn'),
|
|
50
|
+
leaveBtn: document.getElementById('leave-btn'),
|
|
51
|
+
eventsContainer: document.getElementById('events-container'),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
function updateStatus(isConnected) {
|
|
55
|
+
elements.status.textContent = isConnected
|
|
56
|
+
? 'Connected'
|
|
57
|
+
: 'Disconnected';
|
|
58
|
+
elements.status.className = isConnected
|
|
59
|
+
? 'status connected'
|
|
60
|
+
: 'status disconnected';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function updateCounter(count) {
|
|
64
|
+
elements.counterValue.textContent = count;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function addEvent(message) {
|
|
68
|
+
const timestamp = new Date().toLocaleTimeString();
|
|
69
|
+
events.unshift(`[${timestamp}] ${message}`);
|
|
70
|
+
if (events.length > 10) events.pop();
|
|
71
|
+
|
|
72
|
+
elements.eventsContainer.innerHTML = events
|
|
73
|
+
.map((event) => `<div class="event-item">${event}</div>`)
|
|
74
|
+
.join('');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function initialize() {
|
|
78
|
+
try {
|
|
79
|
+
await client.activate();
|
|
80
|
+
elements.clientId.textContent =
|
|
81
|
+
client.getID().substring(0, 8) + '...';
|
|
82
|
+
addEvent('Client activated successfully');
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.error('Failed to activate client:', error);
|
|
85
|
+
addEvent('❌ Failed to activate client');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
elements.joinBtn.addEventListener('click', async () => {
|
|
90
|
+
try {
|
|
91
|
+
elements.joinBtn.disabled = true;
|
|
92
|
+
|
|
93
|
+
presence = new yorkie.Presence(roomId);
|
|
94
|
+
|
|
95
|
+
presence.subscribe((event) => {
|
|
96
|
+
console.log('Presence event:', event);
|
|
97
|
+
updateCounter(event.count);
|
|
98
|
+
|
|
99
|
+
if (event.type === yorkie.PresenceEventType.Initialized) {
|
|
100
|
+
addEvent(`✅ Joined room - ${event.count} user(s) online`);
|
|
101
|
+
} else if (event.type === yorkie.PresenceEventType.Changed) {
|
|
102
|
+
addEvent(`📊 Count updated - ${event.count} user(s) online`);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
await client.attach(presence);
|
|
107
|
+
updateStatus(true);
|
|
108
|
+
elements.leaveBtn.disabled = false;
|
|
109
|
+
|
|
110
|
+
updateCounter(presence.getCount());
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error('Failed to join room:', error);
|
|
113
|
+
addEvent('❌ Failed to join room');
|
|
114
|
+
elements.joinBtn.disabled = false;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
elements.leaveBtn.addEventListener('click', async () => {
|
|
119
|
+
try {
|
|
120
|
+
elements.leaveBtn.disabled = true;
|
|
121
|
+
|
|
122
|
+
await client.detach(presence);
|
|
123
|
+
updateStatus(false);
|
|
124
|
+
elements.joinBtn.disabled = false;
|
|
125
|
+
|
|
126
|
+
addEvent(`👋 Left room - ${presence.getCount()} user(s) remaining`);
|
|
127
|
+
updateCounter(0);
|
|
128
|
+
presence = null;
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('Failed to leave room:', error);
|
|
131
|
+
addEvent('❌ Failed to leave room');
|
|
132
|
+
elements.leaveBtn.disabled = false;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Initialize on load
|
|
137
|
+
initialize();
|
|
138
|
+
</script>
|
|
139
|
+
</body>
|
|
140
|
+
</html>
|
package/dist/yorkie-js-sdk.d.ts
CHANGED
|
@@ -70,6 +70,34 @@ declare type ArraySetOpInfo_2 = {
|
|
|
70
70
|
path: string;
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* `Attachable` is an interface for resources that can be attached to a client.
|
|
75
|
+
*/
|
|
76
|
+
declare interface Attachable {
|
|
77
|
+
/**
|
|
78
|
+
* `getKey` returns the key of this resource.
|
|
79
|
+
*/
|
|
80
|
+
getKey(): string;
|
|
81
|
+
/**
|
|
82
|
+
* `getStatus` returns the status of this resource.
|
|
83
|
+
*/
|
|
84
|
+
getStatus(): ResourceStatus;
|
|
85
|
+
/**
|
|
86
|
+
* `setActor` sets the actor ID into this resource.
|
|
87
|
+
*/
|
|
88
|
+
setActor(actorID: ActorID): void;
|
|
89
|
+
/**
|
|
90
|
+
* `hasLocalChanges` returns whether this resource has local changes to be synchronized.
|
|
91
|
+
* Returns true for Document when there are uncommitted changes.
|
|
92
|
+
* Returns false for Presence as it is server-managed.
|
|
93
|
+
*/
|
|
94
|
+
hasLocalChanges(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* `publish` publishes an event to notify observers about changes in this resource.
|
|
97
|
+
*/
|
|
98
|
+
publish(event: unknown): void;
|
|
99
|
+
}
|
|
100
|
+
|
|
73
101
|
/**
|
|
74
102
|
* `AttachOptions` are user-settable options used when attaching documents.
|
|
75
103
|
*/
|
|
@@ -99,7 +127,7 @@ declare interface AuthErrorEvent extends BaseDocEvent {
|
|
|
99
127
|
type: DocEventType_2.AuthError;
|
|
100
128
|
value: {
|
|
101
129
|
reason: string;
|
|
102
|
-
method: 'PushPull' | '
|
|
130
|
+
method: 'PushPull' | 'WatchDocument' | 'Broadcast';
|
|
103
131
|
};
|
|
104
132
|
}
|
|
105
133
|
|
|
@@ -107,7 +135,7 @@ declare interface AuthErrorEvent_2 extends BaseDocEvent_2 {
|
|
|
107
135
|
type: DocEventType.AuthError;
|
|
108
136
|
value: {
|
|
109
137
|
reason: string;
|
|
110
|
-
method: 'PushPull' | '
|
|
138
|
+
method: 'PushPull' | 'WatchDocument' | 'Broadcast';
|
|
111
139
|
};
|
|
112
140
|
}
|
|
113
141
|
|
|
@@ -754,6 +782,7 @@ export declare class Client {
|
|
|
754
782
|
private syncLoopDuration;
|
|
755
783
|
private reconnectStreamDelay;
|
|
756
784
|
private retrySyncLoopDelay;
|
|
785
|
+
private presenceHeartbeatInterval;
|
|
757
786
|
private rpcClient;
|
|
758
787
|
private setAuthToken;
|
|
759
788
|
private taskQueue;
|
|
@@ -782,16 +811,39 @@ export declare class Client {
|
|
|
782
811
|
*/
|
|
783
812
|
deactivate(options?: DeactivateOptions): Promise<void>;
|
|
784
813
|
/**
|
|
785
|
-
* `
|
|
786
|
-
* @param
|
|
787
|
-
* @returns true if the
|
|
814
|
+
* `has` checks if the given resource is attached to this client.
|
|
815
|
+
* @param key - the key of the resource.
|
|
816
|
+
* @returns true if the resource is attached to this client.
|
|
788
817
|
*/
|
|
789
|
-
|
|
818
|
+
has(key: Key): boolean;
|
|
819
|
+
/**
|
|
820
|
+
* `attach` attaches a Document or Presence to this client.
|
|
821
|
+
* Overloaded to support both types.
|
|
822
|
+
*/
|
|
823
|
+
attach<R, P extends Indexable>(resource: Document_2<R, P>, opts?: AttachOptions<R, P>): Promise<Document_2<R, P>>;
|
|
824
|
+
/**
|
|
825
|
+
* `attach` attaches the given presence to this client. It tells the server that
|
|
826
|
+
* this client will track the presence.
|
|
827
|
+
*/
|
|
828
|
+
attach(resource: Presence): Promise<Presence>;
|
|
790
829
|
/**
|
|
791
830
|
* `attach` attaches the given document to this client. It tells the server that
|
|
792
831
|
* this client will synchronize the given document.
|
|
793
832
|
*/
|
|
794
|
-
|
|
833
|
+
private attachDocument;
|
|
834
|
+
/**
|
|
835
|
+
* `detach` detaches a Document or Presence from this client.
|
|
836
|
+
* Overloaded to support both types.
|
|
837
|
+
*/
|
|
838
|
+
detach<R, P extends Indexable>(resource: Document_2<R, P>, opts?: {
|
|
839
|
+
removeIfNotAttached?: boolean;
|
|
840
|
+
keepalive?: boolean;
|
|
841
|
+
}): Promise<Document_2<R, P>>;
|
|
842
|
+
/**
|
|
843
|
+
* `detach` detaches the given presence from this client.
|
|
844
|
+
* It tells the server that this client will no longer track the presence.
|
|
845
|
+
*/
|
|
846
|
+
detach(resource: Presence): Promise<Presence>;
|
|
795
847
|
/**
|
|
796
848
|
* `detach` detaches the given document from this client. It tells the
|
|
797
849
|
* server that this client will no longer synchronize the given document.
|
|
@@ -800,12 +852,19 @@ export declare class Client {
|
|
|
800
852
|
* the changes should be applied to other replicas before GC time. For this,
|
|
801
853
|
* if the document is no longer used by this client, it should be detached.
|
|
802
854
|
*/
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
855
|
+
private detachDocument;
|
|
856
|
+
/**
|
|
857
|
+
* `attach` attaches the given presence counter to this client.
|
|
858
|
+
* It tells the server that this client will track the presence count.
|
|
859
|
+
*/
|
|
860
|
+
attachPresence(presence: Presence): Promise<Presence>;
|
|
861
|
+
/**
|
|
862
|
+
* `detachPresence` detaches the given presence counter from this client.
|
|
863
|
+
* It tells the server that this client will no longer track the presence count.
|
|
864
|
+
*/
|
|
865
|
+
detachPresence(presence: Presence): Promise<Presence>;
|
|
807
866
|
/**
|
|
808
|
-
* `
|
|
867
|
+
* `changeSyncMode` changes the synchronization mode of the given document.
|
|
809
868
|
*/
|
|
810
869
|
changeSyncMode<R, P extends Indexable>(doc: Document_2<R, P>, syncMode: SyncMode): Promise<Document_2<R, P>>;
|
|
811
870
|
/**
|
|
@@ -841,18 +900,21 @@ export declare class Client {
|
|
|
841
900
|
/**
|
|
842
901
|
* `broadcast` broadcasts the given payload to the given topic.
|
|
843
902
|
*/
|
|
844
|
-
broadcast(
|
|
903
|
+
broadcast(key: Key, topic: string, payload: Json, options?: BroadcastOptions_2): Promise<void>;
|
|
845
904
|
/**
|
|
846
905
|
* `runSyncLoop` runs the sync loop. The sync loop pushes local changes to
|
|
847
906
|
* the server and pulls remote changes from the server.
|
|
848
907
|
*/
|
|
849
908
|
private runSyncLoop;
|
|
850
909
|
/**
|
|
851
|
-
* `runWatchLoop` runs the watch loop for the given
|
|
852
|
-
* listens to the events of the given
|
|
910
|
+
* `runWatchLoop` runs the watch loop for the given resource (Document or Presence).
|
|
911
|
+
* The watch loop listens to the events of the given resource from the server.
|
|
853
912
|
*/
|
|
854
913
|
private runWatchLoop;
|
|
855
|
-
|
|
914
|
+
/* Excluded from this release type: createDocumentWatchStream */
|
|
915
|
+
/* Excluded from this release type: createPresenceWatchStream */
|
|
916
|
+
/* Excluded from this release type: handleWatchPresenceResponse */
|
|
917
|
+
private handleWatchDocumentResponse;
|
|
856
918
|
private deactivateInternal;
|
|
857
919
|
private detachInternal;
|
|
858
920
|
private syncInternal;
|
|
@@ -942,6 +1004,12 @@ export declare interface ClientOptions {
|
|
|
942
1004
|
* default value is `1000`(ms).
|
|
943
1005
|
*/
|
|
944
1006
|
reconnectStreamDelay?: number;
|
|
1007
|
+
/**
|
|
1008
|
+
* `presenceHeartbeatInterval` is the interval of the presence heartbeat.
|
|
1009
|
+
* The client sends a heartbeat to the server to refresh the presence TTL.
|
|
1010
|
+
* The default value is `30000`(ms).
|
|
1011
|
+
*/
|
|
1012
|
+
presenceHeartbeatInterval?: number;
|
|
945
1013
|
/**
|
|
946
1014
|
* `userAgent` is the user agent of the client. It is used to identify the
|
|
947
1015
|
* client.
|
|
@@ -2082,6 +2150,8 @@ declare const _default: {
|
|
|
2082
2150
|
Text: typeof Text_2;
|
|
2083
2151
|
Counter: typeof Counter;
|
|
2084
2152
|
Tree: typeof Tree;
|
|
2153
|
+
Presence: typeof Presence;
|
|
2154
|
+
PresenceEventType: typeof PresenceEventType;
|
|
2085
2155
|
LogLevel: typeof LogLevel;
|
|
2086
2156
|
setLogLevel: typeof setLogLevel;
|
|
2087
2157
|
IntType: CounterType;
|
|
@@ -2119,7 +2189,7 @@ export { Devtools }
|
|
|
2119
2189
|
* `DocEvent` is an event that occurs in `Document`. It can be delivered
|
|
2120
2190
|
* using `Document.subscribe()`.
|
|
2121
2191
|
*/
|
|
2122
|
-
export declare type DocEvent<P extends Indexable = Indexable, T = OpInfo> = StatusChangedEvent_2 | ConnectionChangedEvent | SyncStatusChangedEvent | SnapshotEvent | LocalChangeEvent<T, P> | RemoteChangeEvent<T, P> |
|
|
2192
|
+
export declare type DocEvent<P extends Indexable = Indexable, T = OpInfo> = StatusChangedEvent_2 | ConnectionChangedEvent | SyncStatusChangedEvent | SnapshotEvent | LocalChangeEvent<T, P> | RemoteChangeEvent<T, P> | PresenceEvent_3<P> | BroadcastEvent_2 | LocalBroadcastEvent_2 | AuthErrorEvent_2;
|
|
2123
2193
|
|
|
2124
2194
|
/**
|
|
2125
2195
|
* `DocEvent` is an event that occurs in `Document`. It can be delivered
|
|
@@ -2132,7 +2202,7 @@ declare type DocEvent_2<P extends Indexable_2 = Indexable_2, T = OpInfo_2> =
|
|
|
2132
2202
|
| SnapshotEvent_2
|
|
2133
2203
|
| LocalChangeEvent_2<T, P>
|
|
2134
2204
|
| RemoteChangeEvent_2<T, P>
|
|
2135
|
-
|
|
|
2205
|
+
| PresenceEvent_2<P>
|
|
2136
2206
|
| BroadcastEvent
|
|
2137
2207
|
| LocalBroadcastEvent
|
|
2138
2208
|
| AuthErrorEvent;
|
|
@@ -2187,7 +2257,7 @@ declare class DocEventBody extends Message<DocEventBody> {
|
|
|
2187
2257
|
|
|
2188
2258
|
declare type DocEventCallbackMap<P extends Indexable> = {
|
|
2189
2259
|
default: NextFn<LocalChangeEvent<OpInfo, P> | RemoteChangeEvent<OpInfo, P> | SnapshotEvent>;
|
|
2190
|
-
presence: NextFn<
|
|
2260
|
+
presence: NextFn<PresenceEvent_3<P>>;
|
|
2191
2261
|
'my-presence': NextFn<InitializedEvent<P> | PresenceChangedEvent<P>>;
|
|
2192
2262
|
others: NextFn<WatchedEvent<P> | UnwatchedEvent<P> | PresenceChangedEvent<P>>;
|
|
2193
2263
|
connection: NextFn<ConnectionChangedEvent>;
|
|
@@ -2386,9 +2456,27 @@ declare enum DocEventType_3 {
|
|
|
2386
2456
|
}
|
|
2387
2457
|
|
|
2388
2458
|
/**
|
|
2389
|
-
* `
|
|
2459
|
+
* `Presence` represents a proxy for the Presence to be manipulated from the outside.
|
|
2390
2460
|
*/
|
|
2391
|
-
declare
|
|
2461
|
+
export declare class DocPresence<P extends Indexable> {
|
|
2462
|
+
private context;
|
|
2463
|
+
private presence;
|
|
2464
|
+
constructor(changeContext: ChangeContext, presence: P);
|
|
2465
|
+
/**
|
|
2466
|
+
* `set` updates the presence based on the partial presence.
|
|
2467
|
+
*/
|
|
2468
|
+
set(presence: Partial<P>, option?: {
|
|
2469
|
+
addToHistory: boolean;
|
|
2470
|
+
}): void;
|
|
2471
|
+
/**
|
|
2472
|
+
* `get` returns the presence value of the given key.
|
|
2473
|
+
*/
|
|
2474
|
+
get<K extends keyof P>(key: K): P[K];
|
|
2475
|
+
/**
|
|
2476
|
+
* `clear` clears the presence.
|
|
2477
|
+
*/
|
|
2478
|
+
clear(): void;
|
|
2479
|
+
}
|
|
2392
2480
|
|
|
2393
2481
|
/**
|
|
2394
2482
|
* `DocSize` represents the size of a document in bytes.
|
|
@@ -2478,8 +2566,9 @@ declare enum DocSyncStatus_2 {
|
|
|
2478
2566
|
/**
|
|
2479
2567
|
* `Document` is a CRDT-based data type. We can represent the model
|
|
2480
2568
|
* of the application and edit it even while offline.
|
|
2569
|
+
* It implements Attachable interface to be managed by Attachment.
|
|
2481
2570
|
*/
|
|
2482
|
-
declare class Document_2<R, P extends Indexable = Indexable> {
|
|
2571
|
+
declare class Document_2<R, P extends Indexable = Indexable> implements Attachable {
|
|
2483
2572
|
private key;
|
|
2484
2573
|
private status;
|
|
2485
2574
|
private opts;
|
|
@@ -2509,7 +2598,7 @@ declare class Document_2<R, P extends Indexable = Indexable> {
|
|
|
2509
2598
|
/**
|
|
2510
2599
|
* `update` executes the given updater to update this document.
|
|
2511
2600
|
*/
|
|
2512
|
-
update(updater: (root: JSONObject<R>, presence:
|
|
2601
|
+
update(updater: (root: JSONObject<R>, presence: DocPresence<P>) => void, message?: string): void;
|
|
2513
2602
|
/**
|
|
2514
2603
|
* `subscribe` registers a callback to subscribe to events on the document.
|
|
2515
2604
|
* The callback will be called when the document is changed.
|
|
@@ -3516,6 +3605,11 @@ declare type JsonPrimitive = string | number | boolean | null;
|
|
|
3516
3605
|
|
|
3517
3606
|
declare type JsonPrimitive_2 = string | number | boolean | null;
|
|
3518
3607
|
|
|
3608
|
+
/**
|
|
3609
|
+
* `Key` is a string representing the key of Document or Presence.
|
|
3610
|
+
*/
|
|
3611
|
+
declare type Key = string;
|
|
3612
|
+
|
|
3519
3613
|
declare type LeafElement = PrimitiveValue | Primitive | Text_2 | Counter | Tree;
|
|
3520
3614
|
|
|
3521
3615
|
/**
|
|
@@ -3712,6 +3806,13 @@ export declare interface Observable<T> {
|
|
|
3712
3806
|
getProxy?: () => ObserverProxy<T>;
|
|
3713
3807
|
}
|
|
3714
3808
|
|
|
3809
|
+
/**
|
|
3810
|
+
* Observable interface for subscribing to presence events.
|
|
3811
|
+
*/
|
|
3812
|
+
declare interface Observable_2<T> {
|
|
3813
|
+
subscribe(observer: (event: T) => void): Unsubscribe;
|
|
3814
|
+
}
|
|
3815
|
+
|
|
3715
3816
|
export declare interface Observer<T> {
|
|
3716
3817
|
next: NextFn<T>;
|
|
3717
3818
|
error?: ErrorFn;
|
|
@@ -4319,26 +4420,78 @@ declare type PathOfInner<TElem, Prefix extends string = '', Depth extends number
|
|
|
4319
4420
|
}[keyof TElem] : Prefix extends `${infer TRest}.` ? TRest : Prefix;
|
|
4320
4421
|
|
|
4321
4422
|
/**
|
|
4322
|
-
* `Presence` represents a
|
|
4423
|
+
* `Presence` represents a lightweight presence counter for tracking online users.
|
|
4424
|
+
* It provides real-time count updates through the watch stream.
|
|
4425
|
+
* It implements Attachable interface to be managed by Attachment.
|
|
4323
4426
|
*/
|
|
4324
|
-
export declare class Presence<
|
|
4325
|
-
private
|
|
4326
|
-
private
|
|
4327
|
-
|
|
4427
|
+
export declare class Presence implements Observable_2<PresenceEvent>, Attachable {
|
|
4428
|
+
private key;
|
|
4429
|
+
private status;
|
|
4430
|
+
private actorID?;
|
|
4431
|
+
private presenceID?;
|
|
4432
|
+
private count;
|
|
4433
|
+
private seq;
|
|
4434
|
+
private eventStream;
|
|
4435
|
+
private eventStreamObserver;
|
|
4328
4436
|
/**
|
|
4329
|
-
*
|
|
4437
|
+
* @param key - the key of the presence counter.
|
|
4330
4438
|
*/
|
|
4331
|
-
|
|
4332
|
-
addToHistory: boolean;
|
|
4333
|
-
}): void;
|
|
4439
|
+
constructor(key: string);
|
|
4334
4440
|
/**
|
|
4335
|
-
* `
|
|
4441
|
+
* `getKey` returns the key of this presence counter.
|
|
4336
4442
|
*/
|
|
4337
|
-
|
|
4443
|
+
getKey(): string;
|
|
4338
4444
|
/**
|
|
4339
|
-
* `
|
|
4445
|
+
* `getStatus` returns the status of this presence counter.
|
|
4340
4446
|
*/
|
|
4341
|
-
|
|
4447
|
+
getStatus(): PresenceStatus;
|
|
4448
|
+
/**
|
|
4449
|
+
* `applyStatus` applies the presence status into this presence counter.
|
|
4450
|
+
*/
|
|
4451
|
+
applyStatus(status: PresenceStatus): void;
|
|
4452
|
+
/**
|
|
4453
|
+
* `isAttached` returns whether this presence counter is attached or not.
|
|
4454
|
+
*/
|
|
4455
|
+
isAttached(): boolean;
|
|
4456
|
+
/**
|
|
4457
|
+
* `getActorID` returns the actor ID of this presence counter.
|
|
4458
|
+
*/
|
|
4459
|
+
getActorID(): ActorID | undefined;
|
|
4460
|
+
/**
|
|
4461
|
+
* `setActor` sets the actor ID into this presence counter.
|
|
4462
|
+
*/
|
|
4463
|
+
setActor(actorID: ActorID): void;
|
|
4464
|
+
/**
|
|
4465
|
+
* `getPresenceID` returns the presence ID from the server.
|
|
4466
|
+
*/
|
|
4467
|
+
getPresenceID(): string | undefined;
|
|
4468
|
+
/**
|
|
4469
|
+
* `setPresenceID` sets the presence ID from the server.
|
|
4470
|
+
*/
|
|
4471
|
+
setPresenceID(presenceID: string): void;
|
|
4472
|
+
/**
|
|
4473
|
+
* `getCount` returns the current count value.
|
|
4474
|
+
*/
|
|
4475
|
+
getCount(): number;
|
|
4476
|
+
/**
|
|
4477
|
+
* `updateCount` updates the count and sequence number if the sequence is newer.
|
|
4478
|
+
* Returns true if the count was updated, false if the update was ignored.
|
|
4479
|
+
*/
|
|
4480
|
+
updateCount(count: number, seq: number): boolean;
|
|
4481
|
+
/**
|
|
4482
|
+
* `hasLocalChanges` returns whether this presence has local changes or not.
|
|
4483
|
+
* Presence is server-managed, so it always returns false.
|
|
4484
|
+
*/
|
|
4485
|
+
hasLocalChanges(): boolean;
|
|
4486
|
+
/**
|
|
4487
|
+
* `subscribe` registers an observer for presence events.
|
|
4488
|
+
* Returns an unsubscribe function.
|
|
4489
|
+
*/
|
|
4490
|
+
subscribe(observer: (event: PresenceEvent) => void): Unsubscribe;
|
|
4491
|
+
/**
|
|
4492
|
+
* `publish` publishes an event to all registered handlers.
|
|
4493
|
+
*/
|
|
4494
|
+
publish(event: PresenceEvent): void;
|
|
4342
4495
|
}
|
|
4343
4496
|
|
|
4344
4497
|
/**
|
|
@@ -4447,10 +4600,24 @@ declare enum PresenceChangeType_2 {
|
|
|
4447
4600
|
Clear = "clear"
|
|
4448
4601
|
}
|
|
4449
4602
|
|
|
4603
|
+
/**
|
|
4604
|
+
* `PresenceEvent` represents an event that occurs in the presence.
|
|
4605
|
+
*/
|
|
4606
|
+
export declare interface PresenceEvent {
|
|
4607
|
+
/**
|
|
4608
|
+
* `type` is the type of the event.
|
|
4609
|
+
*/
|
|
4610
|
+
type: PresenceEventType;
|
|
4611
|
+
/**
|
|
4612
|
+
* `count` is the current count value.
|
|
4613
|
+
*/
|
|
4614
|
+
count: number;
|
|
4615
|
+
}
|
|
4616
|
+
|
|
4450
4617
|
/**
|
|
4451
4618
|
* `PresenceEvent` is an event that occurs when the presence of a client changes.
|
|
4452
4619
|
*/
|
|
4453
|
-
declare type
|
|
4620
|
+
declare type PresenceEvent_2<P extends Indexable_2 = Indexable_2> =
|
|
4454
4621
|
| InitializedEvent_2<P>
|
|
4455
4622
|
| WatchedEvent_2<P>
|
|
4456
4623
|
| UnwatchedEvent_2<P>
|
|
@@ -4459,7 +4626,39 @@ declare type PresenceEvent<P extends Indexable_2 = Indexable_2> =
|
|
|
4459
4626
|
/**
|
|
4460
4627
|
* `PresenceEvent` is an event that occurs when the presence of a client changes.
|
|
4461
4628
|
*/
|
|
4462
|
-
declare type
|
|
4629
|
+
declare type PresenceEvent_3<P extends Indexable = Indexable> = InitializedEvent<P> | WatchedEvent<P> | UnwatchedEvent<P> | PresenceChangedEvent<P>;
|
|
4630
|
+
|
|
4631
|
+
/**
|
|
4632
|
+
* `PresenceEventType` represents the type of presence event.
|
|
4633
|
+
*/
|
|
4634
|
+
export declare enum PresenceEventType {
|
|
4635
|
+
/**
|
|
4636
|
+
* `Changed` means that the presence count has changed.
|
|
4637
|
+
*/
|
|
4638
|
+
Changed = "changed",
|
|
4639
|
+
/**
|
|
4640
|
+
* `Initialized` means that the presence watch has been initialized.
|
|
4641
|
+
*/
|
|
4642
|
+
Initialized = "initialized"
|
|
4643
|
+
}
|
|
4644
|
+
|
|
4645
|
+
/**
|
|
4646
|
+
* `PresenceStatus` represents the status of the presence.
|
|
4647
|
+
*/
|
|
4648
|
+
export declare enum PresenceStatus {
|
|
4649
|
+
/**
|
|
4650
|
+
* `Detached` means that the presence is not attached to the client.
|
|
4651
|
+
*/
|
|
4652
|
+
Detached = "detached",
|
|
4653
|
+
/**
|
|
4654
|
+
* `Attached` means that the presence is attached to the client.
|
|
4655
|
+
*/
|
|
4656
|
+
Attached = "attached",
|
|
4657
|
+
/**
|
|
4658
|
+
* `Removed` means that the presence is removed.
|
|
4659
|
+
*/
|
|
4660
|
+
Removed = "removed"
|
|
4661
|
+
}
|
|
4463
4662
|
|
|
4464
4663
|
/**
|
|
4465
4664
|
* `Primitive` represents primitive data type including logical clock.
|
|
@@ -4600,6 +4799,11 @@ declare type RemoveOpInfo_2 = {
|
|
|
4600
4799
|
index?: number;
|
|
4601
4800
|
};
|
|
4602
4801
|
|
|
4802
|
+
/**
|
|
4803
|
+
* `ResourceStatus` represents the common status interface for attachable resources.
|
|
4804
|
+
*/
|
|
4805
|
+
declare type ResourceStatus = 'detached' | 'attached' | 'removed';
|
|
4806
|
+
|
|
4603
4807
|
/**
|
|
4604
4808
|
* `RGATreeSplit` is a block-based list with improved index-based lookup in RGA.
|
|
4605
4809
|
* The difference from RGATreeList is that it has data on a block basis to
|