@epic-web/workshop-presence 4.5.0 → 4.5.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
CHANGED
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Welcome to the party, pal!
|
|
4
4
|
|
|
5
|
-
This is a [Partykit](https://partykit.io) project, which lets you create
|
|
5
|
+
This is a [Partykit](https://partykit.io) project, which lets you create
|
|
6
|
+
real-time collaborative applications with minimal coding effort.
|
|
6
7
|
|
|
7
|
-
[`server.ts`](./src/server.ts) is the server-side code, which is responsible for
|
|
8
|
+
[`server.ts`](./src/server.ts) is the server-side code, which is responsible for
|
|
9
|
+
handling WebSocket events and HTTP requests.
|
|
10
|
+
[`presence.tsx`](../workshop-app/app/utils/presence.tsx) is the client-side
|
|
11
|
+
code, which connects to the server and listens for events.
|
|
8
12
|
|
|
9
|
-
You can start developing by running `npm run dev` and opening
|
|
13
|
+
You can start developing by running `npm run dev` and opening
|
|
14
|
+
[http://localhost:1999](http://localhost:1999) in your browser. When you're
|
|
15
|
+
ready, you can deploy your application on to the PartyKit cloud with
|
|
16
|
+
`npm run deploy`.
|
|
10
17
|
|
|
11
|
-
Refer to our docs for more information:
|
|
18
|
+
Refer to our docs for more information:
|
|
19
|
+
https://github.com/partykit/partykit/blob/main/README.md. For more help, reach
|
|
20
|
+
out to us on [Discord](https://discord.gg/g5uqHQJc3z),
|
|
21
|
+
[GitHub](https://github.com/partykit/partykit), or
|
|
22
|
+
[Twitter](https://twitter.com/partykit_io).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presence.server.d.ts","sourceRoot":"","sources":["../../src/presence.server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,wCAAwC,CAAA;AAGrE,OAAO,
|
|
1
|
+
{"version":3,"file":"presence.server.d.ts","sourceRoot":"","sources":["../../src/presence.server.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,wCAAwC,CAAA;AAGrE,OAAO,EAIN,KAAK,IAAI,EACT,MAAM,eAAe,CAAA;AAEtB,eAAO,MAAM,aAAa;;;YAEpB,MAAM;mBACC,MAAM;cACX,MAAM,GAAG,IAAI,GAAG,SAAS;;YAF3B,MAAM;mBACC,MAAM;cACX,MAAM,GAAG,IAAI,GAAG,SAAS;;;YAF3B,MAAM;mBACC,MAAM;cACX,MAAM,GAAG,IAAI,GAAG,SAAS;;;CAEf,CAAA;AAElB,wBAAsB,eAAe,CACpC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,EAClB,EAAE,OAAO,EAAE,OAAO,EAAE,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO;;;;;;;;;;;;;KAgDnE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presence.server.js","sourceRoot":"","sources":["../../src/presence.server.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,kBAAkB,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACN,cAAc,
|
|
1
|
+
{"version":3,"file":"presence.server.js","sourceRoot":"","sources":["../../src/presence.server.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,SAAS,EACT,kBAAkB,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAA;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACN,cAAc,EACd,UAAU,EACV,eAAe,GAEf,MAAM,eAAe,C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U,EAAE,CAC9E,CAAA;gBACF,CAAC;gBACD,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;gBAC5D,MAAM,WAAW,GAAG,MAAM,cAAc,EAAE,CAAA;gBAC1C,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAA;gBAC5B,IAAI,WAAW,EAAE,QAAQ,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;oBAC3C,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,EAAE,CAAC,CAAC,CAAA;gBACzD,CAAC;qBAAM,CAAC;oBACP,OAAO,WAAW,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;gBACrC,CAAC;YACF,CAAC;YAAC,MAAM,CAAC;gBACR,qBAAqB;gBACrB,OAAO,CAAC,QAAQ,CAAC,GAAG,GAAG,GAAG,CAAA;gBAC1B,OAAO,EAAE,CAAA;YACV,CAAC;QACF,CAAC;KACD,CAAC,CAAA;AACH,CAAC;AAED,iDAAiD;AACjD,4CAA4C;AAC5C,SAAS,WAAW,CAAC,KAAkB;IACtC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IACtB,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QAC1B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;YACvB,OAAO,KAAK,CAAA;QACb,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACjB,OAAO,IAAI,CAAA;IACZ,CAAC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import {\n\tcachified,\n\tmakeSingletonCache,\n} from '@epic-web/workshop-utils/cache.server'\nimport { getPreferences } from '@epic-web/workshop-utils/db.server'\nimport { type Timings } from '@epic-web/workshop-utils/timing.server'\nimport { checkConnection } from '@epic-web/workshop-utils/utils.server'\nimport { z } from 'zod'\nimport {\n\tPresenceSchema,\n\tUserSchema,\n\tpartykitBaseUrl,\n\ttype User,\n} from './presence.js'\n\nexport const presenceCache = makeSingletonCache<\n\tArray<{\n\t\tid: string\n\t\tavatarUrl: string\n\t\tname: string | null | undefined\n\t}>\n>('PresenceCache')\n\nexport async function getPresentUsers(\n\tuser?: User | null,\n\t{ timings, request }: { timings?: Timings; request?: Request } = {},\n) {\n\treturn cachified({\n\t\tkey: 'presence',\n\t\tcache: presenceCache,\n\t\ttimings,\n\t\trequest,\n\t\tttl: 1000 * 60 * 5,\n\t\tswr: 1000 * 60 * 60 * 24,\n\t\tcheckValue: z.array(UserSchema),\n\t\tasync getFreshValue(context) {\n\t\t\ttry {\n\t\t\t\tconst response = await Promise.race([\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\tconst connected = await checkConnection()\n\t\t\t\t\t\tif (!connected) throw new Error(`No internet connection`)\n\t\t\t\t\t\treturn fetch(`${partykitBaseUrl}/presence`)\n\t\t\t\t\t})(),\n\t\t\t\t\tnew Promise<Response>(resolve =>\n\t\t\t\t\t\tsetTimeout(\n\t\t\t\t\t\t\t() => resolve(new Response('Timeout', { status: 500 })),\n\t\t\t\t\t\t\t200,\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t] as const)\n\t\t\t\tif (response.statusText === 'Timeout') {\n\t\t\t\t\tthrow new Error(`Timeout fetching partykit presence`)\n\t\t\t\t}\n\t\t\t\tif (!response.ok) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Unexpected response from partykit: ${response.status} ${response.statusText}`,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t\tconst presence = PresenceSchema.parse(await response.json())\n\t\t\t\tconst preferences = await getPreferences()\n\t\t\t\tconst users = presence.users\n\t\t\t\tif (preferences?.presence.optOut ?? !user) {\n\t\t\t\t\treturn uniqueUsers(users.filter(u => u.id !== user?.id))\n\t\t\t\t} else {\n\t\t\t\t\treturn uniqueUsers([...users, user])\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// console.error(err)\n\t\t\t\tcontext.metadata.ttl = 300\n\t\t\t\treturn []\n\t\t\t}\n\t\t},\n\t})\n}\n\n// A user maybe on the same page in multiple tabs\n// so let's make sure we only show them once\nfunction uniqueUsers(users: Array<User>) {\n\tconst seen = new Set()\n\treturn users.filter(user => {\n\t\tif (seen.has(user.id)) {\n\t\t\treturn false\n\t\t}\n\t\tseen.add(user.id)\n\t\treturn true\n\t})\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@epic-web/workshop-presence",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"deploy": "partykit deploy"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@epic-web/workshop-utils": "4.5.
|
|
14
|
+
"@epic-web/workshop-utils": "4.5.1",
|
|
15
15
|
"zod": "^3.23.8"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|