@fluidframework/presence 2.118.1 → 3.0.1
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 +57 -405
- package/dist/getPresence.js +1 -2
- package/dist/getPresence.js.map +1 -1
- package/package.json +34 -47
package/README.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
A set of session-focused utilities for lightweight data sharing and messaging.
|
|
4
4
|
|
|
5
5
|
A session is a period of time when one or more clients are connected to a Fluid service. Session data and messages may be exchanged among clients, but will disappear once the no clients remain. (More specifically once no clients remain that have acquired the session `IPresence` interface.) Once fully implemented, no client will require container write permissions to use Presence features.
|
|
6
|
+
|
|
7
|
+
For more details and examples of how to use the library, please refer to the documentation on the Fluid Framework [website](https://fluidframework.com/docs/build/presence).
|
|
8
|
+
|
|
6
9
|
<!-- AUTO-GENERATED-CONTENT:START (LIBRARY_README_HEADER) -->
|
|
7
10
|
|
|
8
11
|
<!-- prettier-ignore-start -->
|
|
@@ -10,15 +13,15 @@ A session is a period of time when one or more clients are connected to a Fluid
|
|
|
10
13
|
|
|
11
14
|
## Using Fluid Framework libraries
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
library consumers should always prefer `^`.
|
|
16
|
+
For a dependency on a Fluid Framework library's public APIs, we recommend a `^` (caret) version range.
|
|
17
|
+
For example, use `^1.3.4`.
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
For a dependency on an unstable API, such as a `beta` API, we recommend a more restrictive version range.
|
|
20
|
+
For example, use a `~` version range.
|
|
18
21
|
|
|
19
22
|
## Installation
|
|
20
23
|
|
|
21
|
-
|
|
24
|
+
Run this command to install the package:
|
|
22
25
|
|
|
23
26
|
```bash
|
|
24
27
|
npm i @fluidframework/presence
|
|
@@ -26,372 +29,18 @@ npm i @fluidframework/presence
|
|
|
26
29
|
|
|
27
30
|
## Importing from this package
|
|
28
31
|
|
|
29
|
-
This package
|
|
30
|
-
For
|
|
32
|
+
This package uses [package.json exports](https://nodejs.org/api/packages.html#exports) to separate APIs by support level.
|
|
33
|
+
For information about the support guarantees, read [API Support Levels](https://fluidframework.com/docs/build/releases-and-apitags/#api-support-levels).
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
Import the `public` APIs from `@fluidframework/presence`.
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
Import the `beta` APIs from `@fluidframework/presence/beta`.
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
Import the `alpha` APIs from `@fluidframework/presence/alpha`.
|
|
37
40
|
|
|
38
41
|
## API Documentation
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<!-- prettier-ignore-end -->
|
|
43
|
-
|
|
44
|
-
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
45
|
-
|
|
46
|
-
<!-- AUTO-GENERATED-CONTENT:START (INCLUDE:path=../../../website/docs/build/presence.mdx&start=19) -->
|
|
47
|
-
|
|
48
|
-
<!-- prettier-ignore-start -->
|
|
49
|
-
<!-- NOTE: This section is automatically generated by embedding the referenced file contents. Do not update these generated contents directly. -->
|
|
50
|
-
|
|
51
|
-
A session is a period of time when one or more clients are connected to a Fluid service. Session data and messages may be exchanged among clients, but will disappear once no clients remain. (More specifically once no clients remain that have acquired the session `Presence` interface.) Once fully implemented, no client will require container write permissions to use Presence features.
|
|
52
|
-
|
|
53
|
-
### Attendees
|
|
54
|
-
|
|
55
|
-
For the lifetime of a session, each client connecting will be established as a unique and stable `Attendee`. The representation is stable because it will remain the same `Attendee` instance independent of connection drops and reconnections.
|
|
56
|
-
|
|
57
|
-
Client IDs maintained by `Attendee` may be used to associate `Attendee` with quorum, audience, and service audience members.
|
|
58
|
-
|
|
59
|
-
### Workspaces
|
|
60
|
-
|
|
61
|
-
Within Presence data sharing and messaging is broken into workspaces with custom identifiers (workspace addresses). Clients must use the same address within a session to connect with others. Unique addresses enable logical components within a client runtime to remain isolated or work together (without other piping between those components).
|
|
62
|
-
|
|
63
|
-
There are two types of workspaces: States and Notifications.
|
|
64
|
-
|
|
65
|
-
#### States Workspace
|
|
66
|
-
|
|
67
|
-
A `StatesWorkspace` allows sharing of simple data across attendees where each attendee maintains their own data values that others may read, but not change. This is distinct from a Fluid DDS where data values might be manipulated by multiple clients and one ultimate value is derived. Shared, independent values are maintained by State objects that specialize in incrementality and history of values.
|
|
68
|
-
|
|
69
|
-
#### Notifications Workspace
|
|
70
|
-
|
|
71
|
-
A `NotificationsWorkspace` is similar to `StatesWorkspace`, but is dedicated to notification use-cases via `NotificationsManager`.
|
|
72
|
-
|
|
73
|
-
### State objects
|
|
74
|
-
|
|
75
|
-
#### Latest, LatestRaw
|
|
76
|
-
|
|
77
|
-
`Latest` and `LatestRaw` (unvalidated data) retain the most recent atomic value each attendee has shared.
|
|
78
|
-
Use `StateFactory.latest` to add one to `StatesWorkspace`.
|
|
79
|
-
|
|
80
|
-
#### LatestMap, LatestMapRaw
|
|
81
|
-
|
|
82
|
-
`LatestMap` and `LatestMapRaw` (unvalidated data) retain the most recent atomic value each attendee has shared under arbitrary keys (mimics `Map` data structure).
|
|
83
|
-
Values associated with a key may be set to `undefined` to represent deletion.
|
|
84
|
-
Use `StateFactory.latestMap` to add one to a `StatesWorkspace`.
|
|
85
|
-
(`LatestMap` support is pending.)
|
|
86
|
-
|
|
87
|
-
#### NotificationsManager
|
|
88
|
-
|
|
89
|
-
Notifications are a special case where no data is retained during a session and all interactions appear as events that are sent and received. Notifications may be mixed into a `StatesWorkspace` for convenience. `NotificationsManager` is the only presence object permitted in a `NotificationsWorkspace`. Use `Notifications` to add one to a `NotificationsWorkspace` or `StatesWorkspace`.
|
|
90
|
-
|
|
91
|
-
## Using Presence
|
|
92
|
-
|
|
93
|
-
### State object use
|
|
94
|
-
|
|
95
|
-
State objects have:
|
|
96
|
-
|
|
97
|
-
1. a `local` property representing local clients state data
|
|
98
|
-
1. an `events` property to listen for remote and local updates
|
|
99
|
-
1. several `get*` methods to access other attendees and their data
|
|
100
|
-
|
|
101
|
-
#### Latest, LatestRaw use
|
|
102
|
-
|
|
103
|
-
Simple assignment of new value (new object) initiates broadcast of new value to other attendees.
|
|
104
|
-
|
|
105
|
-
```typescript
|
|
106
|
-
function updateMyPosition(positionTracker: Latest<PointXY>, newPosition: PointXY): void {
|
|
107
|
-
positionTracker.local = newPosition;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
Updates from remote clients can be listened for using `events`.
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
function startTrackingOthersPositions(positionTracker: Latest<PointXY>): (() => void) {
|
|
115
|
-
const stop = positionTracker.events.on("remoteUpdated", (update) => {
|
|
116
|
-
const pos = update.value();
|
|
117
|
-
if (pos === undefined) {
|
|
118
|
-
console.warn(`Attendee ${update.attendee.attendeeId} sent invalid position data`);
|
|
119
|
-
} else {
|
|
120
|
-
console.log(`Attendee ${update.attendee.attendeeId} now at (${pos.x}, ${pos.y})`);
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return stop;
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
Accumulated data can be enumerated using `getRemotes`.
|
|
128
|
-
|
|
129
|
-
```typescript
|
|
130
|
-
// Logs other attendees' current positions (includes now disconnected attendees)
|
|
131
|
-
function logOthersPositions(positionTracker: Latest<PointXY>): void {
|
|
132
|
-
for (const { attendee, value } of positionTracker.getRemotes()) {
|
|
133
|
-
const validated = value();
|
|
134
|
-
const position = validated === undefined ? "<invalid>" : `(${validated.x}, ${validated.y})`;
|
|
135
|
-
console.log(`${attendee.attendeeId} ${position} [${attendee.getConnectionStatus()}]:`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
#### LatestMap, LatestMapRaw use
|
|
141
|
-
|
|
142
|
-
A change to the `local` property automatically initiates a broadcast of updates to other attendees.
|
|
143
|
-
`local` is a [StateMap](../api/presence/statemap-interface.md) that mimics `Map` though it only supports `string | number` as property keys.
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
function updateCounter(counterTracker: LatestMap<number, string>, counterName: string, value: number): void {
|
|
147
|
-
counterTracker.local.set(counterName, value);
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
Updates from remote clients can be listened for using `events`.
|
|
152
|
-
`"remoteItemUpdated"` and `"remoteItemRemoved"` provide fine-grain updates and `"remoteUpdated"` (use not shown) notes any change but only provides complete new map.
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
function startTrackingOthersCounters(counterTracker: LatestMapRaw<number, string>): (() => void) {
|
|
156
|
-
const stopUpdated = counterTracker.events.on("remoteItemUpdated", (update) => {
|
|
157
|
-
console.log(`Attendee ${update.attendee.attendeeId} updated counter ${update.key} to ${update.value}.`);
|
|
158
|
-
});
|
|
159
|
-
const stopRemoved = counterTracker.events.on("remoteItemRemoved", (update) => {
|
|
160
|
-
console.log(`Attendee ${update.attendee.attendeeId} removed counter ${update.key}.`);
|
|
161
|
-
});
|
|
162
|
-
return () => { stopUpdated(); stopRemoved(); };
|
|
163
|
-
}
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
Accumulated data can be enumerated using `getRemotes`.
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
// Logs other attendee's current counters (excludes now _disconnected_ attendees)
|
|
170
|
-
function logOthersCounters(counterTracker: LatestMap<number, string>): void {
|
|
171
|
-
const counterMap = new Map<string, { attendee: Attendee; value: number }[]>();
|
|
172
|
-
// Collect counters from all remote attendees
|
|
173
|
-
for (const { attendee, items } of counterTracker.getRemotes()) {
|
|
174
|
-
// Only collect from *connected* attendees
|
|
175
|
-
if (attendee.getConnectionStatus() === AttendeeStatus.Connected) {
|
|
176
|
-
// `items` is a simple `ReadonlyMap` of remote data
|
|
177
|
-
for (const [counterName, state] of items.entries()) {
|
|
178
|
-
let entry = counterMap.get(counterName);
|
|
179
|
-
if (!entry) {
|
|
180
|
-
entry = [];
|
|
181
|
-
counterMap.set(counterName, entry);
|
|
182
|
-
}
|
|
183
|
-
const value = state.value();
|
|
184
|
-
// Just skip unrecognized data
|
|
185
|
-
if (value !== undefined) {
|
|
186
|
-
entry.push({ attendee, value });
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
for (const [key, items] of counterMap.entries()) {
|
|
193
|
-
console.log(`Counter ${key}:`);
|
|
194
|
-
for (const { attendee, value } of items) {
|
|
195
|
-
console.log(` ${attendee.attendeeId}: ${value}`);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### Setup
|
|
202
|
-
|
|
203
|
-
To access Presence APIs, use `getPresence()` with any `IFluidContainer`.
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
import { getPresence } from "fluid-framework";
|
|
207
|
-
|
|
208
|
-
function usePresence(container: IFluidContainer): void {
|
|
209
|
-
const presence = getPresence(container);
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
#### Schema Definition and Workspace
|
|
214
|
-
|
|
215
|
-
```typescript
|
|
216
|
-
import type { Latest, LatestMap, Presence, StatesWorkspaceSchema } from "@fluidframework/presence";
|
|
217
|
-
import { StateFactory } from "@fluidframework/presence";
|
|
218
|
-
|
|
219
|
-
interface PointXY { x: number; y: number }
|
|
220
|
-
|
|
221
|
-
// Basic custom type guard
|
|
222
|
-
function isPointXY(value: unknown): value is PointXY {
|
|
223
|
-
return typeof value === "object" && value !== null && "x" in value && "y" in value &&
|
|
224
|
-
typeof value.x === "number" && typeof value.y === "number";
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function numberOrUndefined(value: unknown): number | undefined {
|
|
228
|
-
return typeof value === 'number' ? value : undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// A Presence workspace schema with two State objects named "position" and "counters".
|
|
232
|
-
const PresenceSchemaV1 = {
|
|
233
|
-
// This `Latest<PointXY>` state defaults all values to (0, 0).
|
|
234
|
-
position: StateFactory.latest<PointXY>({
|
|
235
|
-
local: { x: 0, y: 0 },
|
|
236
|
-
validator: (v) => isPointXY(v) ? v : undefined
|
|
237
|
-
}),
|
|
238
|
-
// This `LatestMap<number, string>` state has `string` keys storing `number` values.
|
|
239
|
-
counters: StateFactory.latestMap<number, string>({ validator: numberOrUndefined }),
|
|
240
|
-
} as const satisfies StatesWorkspaceSchema;
|
|
241
|
-
|
|
242
|
-
// Creates our unique workspace with the State objects declared in above schema.
|
|
243
|
-
function getOurWorkspace(presence: Presence):
|
|
244
|
-
{
|
|
245
|
-
position: Latest<PointXY>;
|
|
246
|
-
counters: LatestMap<number, string>;
|
|
247
|
-
} {
|
|
248
|
-
return presence.states.getWorkspace("name:PointsAndCountersV1", PresenceSchemaV1).states;
|
|
249
|
-
}
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
## Other Capabilities
|
|
253
|
-
|
|
254
|
-
### Runtime data validation
|
|
255
|
-
|
|
256
|
-
The Presence API provides a simple mechanism (fully added in version 2.53.0) to validate that state data received within session from other clients matches the types declared.
|
|
257
|
-
|
|
258
|
-
When creating State objects using `StateFactory.latest` or `StateFactory.latestMap`, it is recommended that a validator function is specified.
|
|
259
|
-
That function will be called on-demand at runtime to verify data from other clients is valid.
|
|
260
|
-
|
|
261
|
-
When you provide a validator function, the data in a State object must be accessed via `.value()` function call instead of a directly accessing `.value` as a property.
|
|
262
|
-
This is reflected in the types.
|
|
263
|
-
|
|
264
|
-
> [!IMPORTANT]
|
|
265
|
-
> If no validator function is provided, then the data shared in Presence is assumed to be compatible.
|
|
266
|
-
> This may result in runtime errors if the data does not match the expected type.
|
|
267
|
-
> It is recommended to always provide a validator function to ensure that the data is valid and to prevent runtime errors.
|
|
268
|
-
|
|
269
|
-
#### Validator Requirements
|
|
270
|
-
|
|
271
|
-
1. Validator functions take the form `function validator(value: unknown): ExpectedType | undefined`.
|
|
272
|
-
1. Validator functions may not manipulate the given value.
|
|
273
|
-
1. Validator functions are not expected to throw exceptions.
|
|
274
|
-
1. When malformed data is found, a validator function may either return `undefined` or create a substitute value.
|
|
275
|
-
|
|
276
|
-
The result of call to validator is returned as-is to the `.value()` call that first attempted access to remote data.
|
|
277
|
-
That result is cached and will be returned to future `.value()` callers without invoking the validator.
|
|
278
|
-
|
|
279
|
-
#### Example Validated Setup
|
|
280
|
-
|
|
281
|
-
Custom validators can be convenient for simple types.
|
|
282
|
-
See [Schema Definition and Workspace](#schema-definition-and-workspace) for example.
|
|
283
|
-
For more complex types or peace of mind, consider a schema builder / validation package such as [TypeBox](https://github.com/sinclairzx81/typebox) or [Zod](https://zod.dev/).
|
|
284
|
-
|
|
285
|
-
Example using TypeBox:
|
|
286
|
-
```typescript
|
|
287
|
-
import { type Static, Type } from "@sinclair/typebox";
|
|
288
|
-
import { TypeCompiler } from '@sinclair/typebox/compiler'
|
|
289
|
-
|
|
290
|
-
const PointXY = Type.Object({
|
|
291
|
-
x: Type.Number(),
|
|
292
|
-
y: Type.Number(),
|
|
293
|
-
});
|
|
294
|
-
type PointXY = Static<typeof PointXY>;
|
|
295
|
-
|
|
296
|
-
const typeCheckPointXY = TypeCompiler.Compile(PointXY);
|
|
297
|
-
|
|
298
|
-
function validatorPointXY(value: unknown): PointXY | undefined {
|
|
299
|
-
return typeCheckPointXY.Check(value) ? value : undefined;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
const PresenceSchemaV1 = {
|
|
303
|
-
position: StateFactory.latest({
|
|
304
|
-
local: { x: 0, y: 0 },
|
|
305
|
-
validator: validatorPointXY
|
|
306
|
-
}),
|
|
307
|
-
} as const satisfies StatesWorkspaceSchema;
|
|
308
|
-
```
|
|
309
|
-
|
|
310
|
-
## Limitations
|
|
311
|
-
|
|
312
|
-
### Data Supported
|
|
313
|
-
|
|
314
|
-
Only plain old data is supported.
|
|
315
|
-
If `JSON.parse(JSON.stringify(foo))` returns a deeply equal value, then that data is supported.
|
|
316
|
-
Large data is not recommended and if used may exceed system capacity.
|
|
317
|
-
A small image could be shared but sharing a URL to an image is recommended.
|
|
318
|
-
|
|
319
|
-
### Compatibility and Versioning
|
|
320
|
-
|
|
321
|
-
The schema of workspace address, states and notifications names, and their types will only be consistent when all
|
|
322
|
-
clients connected to the session are using the same types for a unique value/notification path (workspace address + name
|
|
323
|
-
within workspace). In other words, don't mix versions or make sure to change identifiers when changing types in a
|
|
324
|
-
non-compatible way.
|
|
325
|
-
|
|
326
|
-
For example:
|
|
327
|
-
|
|
328
|
-
```typescript
|
|
329
|
-
presence.states.getWorkspace("app:v1states", { myState: StateFactory.latest({ local: { x: 0 }}) });
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
is incompatible with
|
|
333
|
-
|
|
334
|
-
```typescript
|
|
335
|
-
presence.states.getWorkspace("app:v1states", { myState: StateFactory.latest({ local: { x: "text" }}) });
|
|
336
|
-
```
|
|
337
|
-
|
|
338
|
-
because "app:v1states"+"myState" have different value type expectations: `{x: number}` versus `{x: string}`.
|
|
339
|
-
|
|
340
|
-
```typescript
|
|
341
|
-
presence.states.getWorkspace("app:v1states", { myState2: StateFactory.latest({ local: { x: true }}) });
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
would be compatible with both of the prior schemas because "myState2" is a different name. Though in this situation none of the different clients would be able to observe each other.
|
|
345
|
-
|
|
346
|
-
### States Reliability
|
|
347
|
-
|
|
348
|
-
The current implementation relies on Fluid Framework's signal infrastructure instead of ops. This has advantages, but comes with some risk of unreliable messaging. The most common known case of unreliable signals occurs during reconnection periods and the current implementation attempts to account for that. Be aware that all clients are not guaranteed to arrive at eventual consistency. Please [file a new issue](https://github.com/microsoft/FluidFramework/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=Presence:%20States:%20) if one is not found under [Presence States issues](https://github.com/microsoft/FluidFramework/issues?q=is%3Aissue+%22Presence%3A+States%3A%22).
|
|
349
|
-
|
|
350
|
-
### Notifications
|
|
351
|
-
|
|
352
|
-
Notifications API is partially implemented at alpha support level. All messages are always broadcast even if `unicast` API is used. Type inferences are not working even with a fully specified `initialSubscriptions` value provided to `Notifications`, and the schema type must be specified explicitly.
|
|
353
|
-
|
|
354
|
-
Notifications are fundamentally unreliable at this time as there are no built-in acknowledgements nor retained state. To prevent the most common loss of notifications, always check for connection before sending.
|
|
355
|
-
|
|
356
|
-
### Throttling / Grouping
|
|
357
|
-
|
|
358
|
-
Presence updates are grouped together and throttled to prevent flooding the network with messages when presence values are rapidly updated. This means the presence infrastructure will not immediately broadcast updates but will broadcast them after a configurable delay.
|
|
359
|
-
|
|
360
|
-
The `allowableUpdateLatencyMs` property configures how long a local update may be delayed under normal circumstances, enabling grouping with other updates. The default `allowableUpdateLatencyMs` is **60 milliseconds** but may be (1) specified during configuration of a [States Workspace](#states-workspace) or [States](#state-objects) and/or (2) updated later using the `controls` member of Workspace or States. The [States Workspace](#states-workspace) configuration is used when States do not have their own setting.
|
|
361
|
-
|
|
362
|
-
Notifications are never queued; they effectively always have an `allowableUpdateLatencyMs` of 0. However, they may be grouped with other updates that were already queued.
|
|
363
|
-
|
|
364
|
-
Note that due to throttling, clients will not receive updates for every intermediate value set by another client. For example,
|
|
365
|
-
with `Latest` and `LatestMap`, the only value sent is the value at the time the outgoing grouped message is sent. Previous
|
|
366
|
-
values set by the client will not be broadcast or seen by other clients.
|
|
367
|
-
|
|
368
|
-
#### Example
|
|
369
|
-
|
|
370
|
-
You can configure the grouping and throttling behavior using the `allowableUpdateLatencyMs` property as in the following example:
|
|
371
|
-
|
|
372
|
-
```ts
|
|
373
|
-
// Configure a states workspace
|
|
374
|
-
const stateWorkspace = presence.states.getWorkspace(
|
|
375
|
-
"app:v1states",
|
|
376
|
-
{
|
|
377
|
-
// This Latest state has an allowable latency of 100ms.
|
|
378
|
-
position: StateFactory.latest({ local: { x: 0, y: 0 }, settings: { allowableUpdateLatencyMs: 100 }}),
|
|
379
|
-
// This Latest state uses the workspace default.
|
|
380
|
-
count: StateFactory.latest({ local: { num: 0 }}),
|
|
381
|
-
},
|
|
382
|
-
// Specify the default for all state in this workspace to 200ms,
|
|
383
|
-
// overriding the default value of 60ms.
|
|
384
|
-
{ allowableUpdateLatencyMs: 200 },
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
// Temporarily set count updates to send as soon as possible
|
|
388
|
-
const countState = stateWorkspace.states.count;
|
|
389
|
-
countState.controls.allowableUpdateLatencyMs = 0;
|
|
390
|
-
countState.local = { num: 5000 };
|
|
391
|
-
|
|
392
|
-
// Reset the update latency to the workspace default
|
|
393
|
-
countState.controls.allowableUpdateLatencyMs = undefined;
|
|
394
|
-
```
|
|
43
|
+
Read the **@fluidframework/presence** API documentation at <https://fluidframework.com/docs/apis/presence>.
|
|
395
44
|
|
|
396
45
|
<!-- prettier-ignore-end -->
|
|
397
46
|
|
|
@@ -404,62 +53,69 @@ countState.controls.allowableUpdateLatencyMs = undefined;
|
|
|
404
53
|
|
|
405
54
|
## Minimum Client Requirements
|
|
406
55
|
|
|
407
|
-
|
|
408
|
-
These requirements
|
|
409
|
-
|
|
56
|
+
Fluid Framework client libraries support the platforms in this document.
|
|
57
|
+
These requirements are intentionally restrictive.
|
|
58
|
+
Within a major version series, we can relax these requirements, but we cannot make them stricter.
|
|
59
|
+
For a Long Term Support (LTS) version, we might need to support these platforms for several years.
|
|
60
|
+
|
|
61
|
+
Other configurations can work, but Fluid Framework does not support them.
|
|
62
|
+
If an unsupported configuration stops working, we do not classify this as a bug.
|
|
63
|
+
To request support for a configuration that is not listed, file an issue.
|
|
64
|
+
The product team will evaluate your request.
|
|
65
|
+
In the issue, specify the current status of the configuration:
|
|
410
66
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
When making such a request please include if the configuration already works (and thus the request is just that it becomes officially supported), or if changes are required to get it working.
|
|
67
|
+
- The configuration works but needs official support.
|
|
68
|
+
- The configuration does not work and requires changes.
|
|
414
69
|
|
|
415
70
|
### Supported Runtimes
|
|
416
71
|
|
|
417
|
-
-
|
|
418
|
-
-
|
|
419
|
-
-
|
|
72
|
+
- Fluid Framework supports Node.js versions 22 and 24 while they receive [upstream support](https://nodejs.org/en/about/previous-releases).
|
|
73
|
+
- Fluid Framework will stop support for version 22 [when upstream support ends on 2027-04-30](https://github.com/nodejs/release#release-schedule).
|
|
74
|
+
- Fluid Framework does not support Node.js with the `--no-experimental-fetch` flag.
|
|
75
|
+
- Fluid Framework supports modern browsers that support the ES2022 standard library.
|
|
420
76
|
|
|
421
77
|
### Supported Tools
|
|
422
78
|
|
|
423
|
-
- TypeScript
|
|
424
|
-
-
|
|
425
|
-
-
|
|
426
|
-
- [
|
|
427
|
-
-
|
|
428
|
-
|
|
79
|
+
- [TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0):
|
|
80
|
+
- Fluid Framework supports all [`strict`](https://www.typescriptlang.org/tsconfig) options.
|
|
81
|
+
- Set the build targets (`lib`, `target`) to `ES2022` or later.
|
|
82
|
+
- Enable [`strictNullChecks`](https://www.typescriptlang.org/tsconfig).
|
|
83
|
+
- Fluid Framework does not support [configuration options deprecated in TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0#breaking-changes-and-deprecations-in-typescript-6-0).
|
|
84
|
+
- Fluid Framework does not fully support `exactOptionalPropertyTypes`.
|
|
85
|
+
If you enable this option, do not use `in`, `Reflect.has`, `Object.hasOwn`, or `Object.prototype.hasOwnProperty` to narrow members of Fluid Framework types.
|
|
86
|
+
These methods can incorrectly exclude `undefined` from the possible values.
|
|
429
87
|
- [webpack](https://webpack.js.org/) 5
|
|
430
|
-
- We
|
|
431
|
-
Other bundlers
|
|
88
|
+
- We do not require a specific bundler.
|
|
89
|
+
Other bundlers that handle ES Modules can work, but we actively test only webpack.
|
|
432
90
|
|
|
433
91
|
### Module Resolution
|
|
434
92
|
|
|
435
|
-
[`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution)
|
|
436
|
-
|
|
93
|
+
In TypeScript `compilerOptions`, use [`Node16`, `Node20`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) module resolution.
|
|
94
|
+
These settings follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
|
|
95
|
+
|
|
96
|
+
Do not use `Node10` module resolution.
|
|
437
97
|
|
|
438
98
|
### Module Formats
|
|
439
99
|
|
|
440
100
|
- ES Modules:
|
|
441
|
-
ES Modules
|
|
442
|
-
-
|
|
443
|
-
|
|
444
|
-
This is done to accommodate some workflows without good ES Module support.
|
|
445
|
-
If you have a workflow you would like included in this list, file an issue.
|
|
446
|
-
Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
|
|
447
|
-
|
|
448
|
-
- Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
|
|
101
|
+
Use ES Modules to consume Fluid Framework client packages, including in Node.js.
|
|
102
|
+
- CommonJS:
|
|
103
|
+
Fluid Framework does not officially support CommonJS in version 3.0 or later.
|
|
449
104
|
|
|
450
105
|
## Contribution Guidelines
|
|
451
106
|
|
|
452
|
-
|
|
107
|
+
You can [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid Framework in these ways:
|
|
453
108
|
|
|
454
|
-
-
|
|
455
|
-
- [Submit
|
|
456
|
-
- Review
|
|
109
|
+
- Answer questions in [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
|
|
110
|
+
- [Submit bug reports](https://github.com/microsoft/FluidFramework/issues) and help verify fixes.
|
|
111
|
+
- Review [source code changes](https://github.com/microsoft/FluidFramework/pulls).
|
|
457
112
|
- [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
|
|
458
113
|
|
|
459
|
-
|
|
114
|
+
For detailed instructions, read the [repo documentation](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
|
|
460
115
|
|
|
461
|
-
This project
|
|
462
|
-
For more information
|
|
116
|
+
This project follows the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
117
|
+
For more information, read the [Code of Conduct frequently asked questions](https://opensource.microsoft.com/codeofconduct/faq/).
|
|
118
|
+
For questions or comments, contact [opencode@microsoft.com](mailto:opencode@microsoft.com).
|
|
463
119
|
|
|
464
120
|
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
465
121
|
Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
|
|
@@ -467,13 +123,9 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
|
|
|
467
123
|
|
|
468
124
|
## Help
|
|
469
125
|
|
|
470
|
-
|
|
471
|
-
Check out [fluidframework.com](https://fluidframework.com/docs/).
|
|
472
|
-
|
|
473
|
-
Still not finding what you're looking for?
|
|
474
|
-
Please [file an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
126
|
+
Read the [Fluid Framework documentation](https://fluidframework.com/docs/) for information about Fluid Framework concepts and APIs.
|
|
475
127
|
|
|
476
|
-
|
|
128
|
+
To request information that the documentation does not contain, [create an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
|
|
477
129
|
|
|
478
130
|
## Trademark
|
|
479
131
|
|
package/dist/getPresence.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Licensed under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.getPresenceFromDataStoreContext =
|
|
7
|
+
exports.getPresenceFromDataStoreContext = getPresenceFromDataStoreContext;
|
|
8
8
|
const extension_1 = require("@fluid-internal/presence-runtime/extension");
|
|
9
9
|
const internal_1 = require("@fluidframework/core-utils/internal");
|
|
10
10
|
function assertContextHasExtensionProvider(context) {
|
|
@@ -19,5 +19,4 @@ function getPresenceFromDataStoreContext(context) {
|
|
|
19
19
|
assertContextHasExtensionProvider(context);
|
|
20
20
|
return context.getExtension(extension_1.extensionId, extension_1.ContainerPresenceFactory);
|
|
21
21
|
}
|
|
22
|
-
exports.getPresenceFromDataStoreContext = getPresenceFromDataStoreContext;
|
|
23
22
|
//# sourceMappingURL=getPresence.js.map
|
package/dist/getPresence.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPresence.js","sourceRoot":"","sources":["../src/getPresence.ts"],"names":[],"mappings":";AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"getPresence.js","sourceRoot":"","sources":["../src/getPresence.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AA2BH,0EAGC;AA3BD,0EAGoD;AACpD,kEAA6D;AAM7D,SAAS,iCAAiC,CACzC,OAA+B;IAE/B,IAAA,iBAAM,EACL,cAAc,IAAI,OAAO,EACzB,KAAK,CAAC,sEAAsE,CAC5E,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,+BAA+B,CAAC,OAA+B;IAC9E,iCAAiC,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,OAAO,CAAC,YAAY,CAAC,uBAAW,EAAE,oCAAwB,CAAC,CAAC;AACpE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { Presence } from \"@fluid-internal/presence-definitions\";\nimport {\n\tContainerPresenceFactory,\n\textensionId,\n} from \"@fluid-internal/presence-runtime/extension\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tFluidDataStoreContextInternal,\n\tIFluidDataStoreContext,\n} from \"@fluidframework/runtime-definitions/internal\";\n\nfunction assertContextHasExtensionProvider(\n\tcontext: IFluidDataStoreContext,\n): asserts context is FluidDataStoreContextInternal {\n\tassert(\n\t\t\"getExtension\" in context,\n\t\t0xc9c /* Data store context does not implement ContainerExtensionProvider */,\n\t);\n}\n\n/**\n * Get {@link Presence} from a Fluid Data Store Context\n *\n * @legacy @alpha\n */\nexport function getPresenceFromDataStoreContext(context: IFluidDataStoreContext): Presence {\n\tassertContextHasExtensionProvider(context);\n\treturn context.getExtension(extensionId, ContainerPresenceFactory);\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/presence",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "A component for lightweight data sharing within a single session",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,43 +14,31 @@
|
|
|
14
14
|
"type": "module",
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"require": {
|
|
22
|
-
"types": "./dist/public.d.ts",
|
|
23
|
-
"default": "./dist/index.js"
|
|
17
|
+
"types": "./lib/public.d.ts",
|
|
18
|
+
"default": "./lib/index.js",
|
|
19
|
+
"internal-entrypoint-generation": {
|
|
20
|
+
"types": "./dist/public.d.ts"
|
|
24
21
|
}
|
|
25
22
|
},
|
|
26
23
|
"./beta": {
|
|
27
|
-
"
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"require": {
|
|
32
|
-
"types": "./dist/beta.d.ts",
|
|
33
|
-
"default": "./dist/index.js"
|
|
24
|
+
"types": "./lib/beta.d.ts",
|
|
25
|
+
"default": "./lib/index.js",
|
|
26
|
+
"internal-entrypoint-generation": {
|
|
27
|
+
"types": "./dist/beta.d.ts"
|
|
34
28
|
}
|
|
35
29
|
},
|
|
36
30
|
"./alpha": {
|
|
37
|
-
"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./dist/alpha.d.ts",
|
|
43
|
-
"default": "./dist/index.js"
|
|
31
|
+
"types": "./lib/alpha.d.ts",
|
|
32
|
+
"default": "./lib/index.js",
|
|
33
|
+
"internal-entrypoint-generation": {
|
|
34
|
+
"types": "./dist/alpha.d.ts"
|
|
44
35
|
}
|
|
45
36
|
},
|
|
46
37
|
"./legacy/alpha": {
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"require": {
|
|
52
|
-
"types": "./dist/legacy.alpha.d.ts",
|
|
53
|
-
"default": "./dist/index.js"
|
|
38
|
+
"types": "./lib/legacy.alpha.d.ts",
|
|
39
|
+
"default": "./lib/index.js",
|
|
40
|
+
"internal-entrypoint-generation": {
|
|
41
|
+
"types": "./dist/legacy.alpha.d.ts"
|
|
54
42
|
}
|
|
55
43
|
}
|
|
56
44
|
},
|
|
@@ -61,15 +49,15 @@
|
|
|
61
49
|
"!**/test/**"
|
|
62
50
|
],
|
|
63
51
|
"dependencies": {
|
|
64
|
-
"@fluid-internal/presence-definitions": "~
|
|
65
|
-
"@fluid-internal/presence-runtime": "~
|
|
66
|
-
"@fluidframework/core-utils": "~
|
|
67
|
-
"@fluidframework/runtime-definitions": "~
|
|
52
|
+
"@fluid-internal/presence-definitions": "~3.0.1",
|
|
53
|
+
"@fluid-internal/presence-runtime": "~3.0.1",
|
|
54
|
+
"@fluidframework/core-utils": "~3.0.1",
|
|
55
|
+
"@fluidframework/runtime-definitions": "~3.0.1"
|
|
68
56
|
},
|
|
69
57
|
"devDependencies": {
|
|
70
58
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
71
59
|
"@biomejs/biome": "~2.4.5",
|
|
72
|
-
"@fluid-internal/mocha-test-setup": "~
|
|
60
|
+
"@fluid-internal/mocha-test-setup": "~3.0.1",
|
|
73
61
|
"@fluid-tools/build-cli": "^0.67.0",
|
|
74
62
|
"@fluidframework/build-common": "^2.0.3",
|
|
75
63
|
"@fluidframework/build-tools": "^0.67.0",
|
|
@@ -81,13 +69,12 @@
|
|
|
81
69
|
"eslint": "~9.39.1",
|
|
82
70
|
"jiti": "^2.6.1",
|
|
83
71
|
"rimraf": "^6.1.3",
|
|
84
|
-
"typescript": "~
|
|
72
|
+
"typescript": "~6.0.3"
|
|
85
73
|
},
|
|
86
74
|
"fluidBuild": {
|
|
87
75
|
"tasks": {
|
|
88
76
|
"eslint": [
|
|
89
|
-
"^build:
|
|
90
|
-
"^build:entrypoints:esm"
|
|
77
|
+
"^build:package:esm"
|
|
91
78
|
]
|
|
92
79
|
}
|
|
93
80
|
},
|
|
@@ -97,16 +84,17 @@
|
|
|
97
84
|
"scripts": {
|
|
98
85
|
"build": "fluid-build . --task build",
|
|
99
86
|
"build:api-reports": "concurrently \"npm:build:api-reports:*\"",
|
|
100
|
-
"build:api-reports:current": "api-extractor run --local --config api-extractor/api-extractor.current.json",
|
|
101
|
-
"build:api-reports:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
|
|
87
|
+
"build:api-reports:current": "api-extractor run --local --config api-extractor/api-extractor-report.current.json",
|
|
88
|
+
"build:api-reports:legacy": "api-extractor run --local --config api-extractor/api-extractor-report.legacy.json",
|
|
89
|
+
"build:cjs": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist",
|
|
102
90
|
"build:commonjs": "fluid-build . --task commonjs",
|
|
103
91
|
"build:compile": "fluid-build . --task compile",
|
|
104
|
-
"build:docs": "api-extractor run --local",
|
|
92
|
+
"build:docs": "api-extractor run --local --config api-extractor/api-extractor-model.json",
|
|
105
93
|
"build:entrypoints": "fluid-build . --task build:entrypoints",
|
|
106
94
|
"build:entrypoints:cjs": "flub generate entrypoints --resolutionConditions require --outFileLegacyAlpha legacy.alpha --outDir ./dist",
|
|
107
95
|
"build:entrypoints:esm": "flub generate entrypoints --outFileLegacyAlpha legacy.alpha --outDir ./lib",
|
|
108
|
-
"build:
|
|
109
|
-
"check:are-the-types-wrong": "attw --pack . --profile
|
|
96
|
+
"build:esm": "tsc --project ./tsconfig.json",
|
|
97
|
+
"check:are-the-types-wrong": "attw --pack . --profile esm-only",
|
|
110
98
|
"check:biome": "biome check .",
|
|
111
99
|
"check:exports": "concurrently \"npm:check:exports:*\"",
|
|
112
100
|
"check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
|
|
@@ -120,16 +108,15 @@
|
|
|
120
108
|
"check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
|
|
121
109
|
"check:format": "npm run check:biome",
|
|
122
110
|
"ci:build:api-reports": "concurrently \"npm:ci:build:api-reports:*\"",
|
|
123
|
-
"ci:build:api-reports:current": "api-extractor run --config api-extractor/api-extractor.current.json",
|
|
124
|
-
"ci:build:api-reports:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
|
|
125
|
-
"ci:build:docs": "api-extractor run",
|
|
111
|
+
"ci:build:api-reports:current": "api-extractor run --config api-extractor/api-extractor-report.current.json",
|
|
112
|
+
"ci:build:api-reports:legacy": "api-extractor run --config api-extractor/api-extractor-report.legacy.json",
|
|
113
|
+
"ci:build:docs": "api-extractor run --config api-extractor/api-extractor-model.json",
|
|
126
114
|
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
127
115
|
"eslint": "eslint --quiet --format stylish src",
|
|
128
116
|
"eslint:fix": "eslint --quiet --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
129
117
|
"format": "npm run format:biome",
|
|
130
118
|
"format:biome": "biome check . --write",
|
|
131
119
|
"lint": "fluid-build . --task lint",
|
|
132
|
-
"lint:fix": "fluid-build . --task eslint:fix --task format"
|
|
133
|
-
"tsc": "fluid-tsc commonjs --project ./tsconfig.cjs.json && copyfiles -f ../../../common/build/build-common/src/cjs/package.json ./dist"
|
|
120
|
+
"lint:fix": "fluid-build . --task eslint:fix --task format"
|
|
134
121
|
}
|
|
135
122
|
}
|