Use shared BGS viewer and chat protocol (#10)
* Use shared BGS viewer and chat protocol * Use shared chat panel with Container styling * Update shared chat visibility and show date separators * Keep typing after completing a chat mention
This commit is contained in:
parent
ff733404c2
commit
70e14de86c
12 changed files with 542 additions and 347 deletions
6
.github/workflows/viewer-test.yml
vendored
6
.github/workflows/viewer-test.yml
vendored
|
|
@ -18,6 +18,8 @@ defaults:
|
|||
jobs:
|
||||
test_and_build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
NODE_OPTIONS: --openssl-legacy-provider
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
|
|
@ -30,3 +32,7 @@ jobs:
|
|||
# - run: pnpm lint
|
||||
# - run: pnpm test
|
||||
- run: pnpm build
|
||||
- run: pnpm --dir ../engine build
|
||||
- run: pnpm package
|
||||
- run: pnpm exec playwright install --with-deps chromium
|
||||
- run: pnpm test:browser
|
||||
|
|
|
|||
176
pnpm-lock.yaml
generated
176
pnpm-lock.yaml
generated
|
|
@ -85,6 +85,9 @@ importers:
|
|||
|
||||
viewer:
|
||||
dependencies:
|
||||
'@boardgamers/protocol':
|
||||
specifier: 0.2.2
|
||||
version: 0.2.2
|
||||
container-engine:
|
||||
specifier: workspace:../engine
|
||||
version: link:../engine
|
||||
|
|
@ -107,9 +110,12 @@ importers:
|
|||
specifier: ^7.2.3
|
||||
version: 7.2.6(vue@2.7.16)
|
||||
vue-property-decorator:
|
||||
specifier: ^8.4.2
|
||||
version: 8.5.1(vue@2.7.16)
|
||||
specifier: ^9.1.2
|
||||
version: 9.1.2(vue-class-component@7.2.6(vue@2.7.16))(vue@2.7.16)
|
||||
devDependencies:
|
||||
'@babel/plugin-transform-export-namespace-from':
|
||||
specifier: 7.29.7
|
||||
version: 7.29.7(@babel/core@7.29.7(supports-color@7.2.0))
|
||||
'@types/assert':
|
||||
specifier: ^1.4.7
|
||||
version: 1.5.11
|
||||
|
|
@ -130,19 +136,19 @@ importers:
|
|||
version: 13.13.52
|
||||
'@typescript-eslint/parser':
|
||||
specifier: ^4.26.1
|
||||
version: 4.33.0(eslint@7.32.0(supports-color@6.1.0))(supports-color@6.1.0)(typescript@4.9.5)
|
||||
version: 4.33.0(eslint@7.32.0(supports-color@6.1.0))(supports-color@6.1.0)(typescript@5.9.3)
|
||||
'@vue/cli-plugin-babel':
|
||||
specifier: ~4.4.0
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(core-js@3.50.0)(supports-color@7.2.0)(vue@2.7.16)
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(core-js@3.50.0)(supports-color@7.2.0)(vue@2.7.16)
|
||||
'@vue/cli-plugin-typescript':
|
||||
specifier: ~4.4.0
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-plugin-unit-mocha':
|
||||
specifier: ~4.4.0
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(supports-color@7.2.0)(webpack@4.47.0(supports-color@7.2.0))
|
||||
version: 4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(supports-color@7.2.0)(webpack@4.47.0(supports-color@7.2.0))
|
||||
'@vue/cli-service':
|
||||
specifier: ~4.4.0
|
||||
version: 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
version: 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/test-utils':
|
||||
specifier: ^1.0.3
|
||||
version: 1.3.6(vue-template-compiler@2.7.16)(vue@2.7.16)
|
||||
|
|
@ -158,6 +164,9 @@ importers:
|
|||
eslint-plugin-vue:
|
||||
specifier: ^7.11.0
|
||||
version: 7.20.0(eslint@7.32.0(supports-color@6.1.0))(supports-color@6.1.0)
|
||||
playwright:
|
||||
specifier: 1.62.1
|
||||
version: 1.62.1
|
||||
sass:
|
||||
specifier: ^1.26.5
|
||||
version: 1.102.0
|
||||
|
|
@ -165,8 +174,8 @@ importers:
|
|||
specifier: ^8.0.2
|
||||
version: 8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0))
|
||||
typescript:
|
||||
specifier: ^4.3.5
|
||||
version: 4.9.5
|
||||
specifier: ^5.9.3
|
||||
version: 5.9.3
|
||||
vue-template-compiler:
|
||||
specifier: ^2.6.11
|
||||
version: 2.7.16
|
||||
|
|
@ -1027,6 +1036,12 @@ packages:
|
|||
}
|
||||
engines: { node: '>=6.9.0' }
|
||||
|
||||
'@boardgamers/protocol@0.2.2':
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-5o5nPZW6CN6PysF0i90OR+B30djiFhAGutCZe5RKJV6h3RgqE36HA7l0pOpvhdHz8uYtqE0nmaPlc+2ZtYiM/A==,
|
||||
}
|
||||
|
||||
'@cspotcode/source-map-support@0.8.1':
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -5067,6 +5082,14 @@ packages:
|
|||
os: [darwin]
|
||||
deprecated: Upgrade to fsevents v2 to mitigate potential security issues
|
||||
|
||||
fsevents@2.3.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==,
|
||||
}
|
||||
engines: { node: ^8.16.0 || ^10.6.0 || >=11.0.0 }
|
||||
os: [darwin]
|
||||
|
||||
fsevents@2.3.3:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -7910,6 +7933,22 @@ packages:
|
|||
}
|
||||
engines: { node: '>=8' }
|
||||
|
||||
playwright-core@1.62.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-wPYSwEBJY9GHraISXqyqtx0na0LpO3XEX7jNDhntbex7tzUS7kLnZsOlFruFJB4Hi/rhDMjXGqHewDZ68nYZVw==,
|
||||
}
|
||||
engines: { node: '>=20' }
|
||||
hasBin: true
|
||||
|
||||
playwright@1.62.1:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-0M+L3LAD8/nm554LOla9Ayx0j0tmFZ0FBcoQ7F1VuVHpM/XpiC8RcDzBQB8W5+hA8L22THxELzeF+2WcUzvcLg==,
|
||||
}
|
||||
engines: { node: '>=20' }
|
||||
hasBin: true
|
||||
|
||||
please-upgrade-node@3.2.0:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -10043,6 +10082,14 @@ packages:
|
|||
engines: { node: '>=4.2.0' }
|
||||
hasBin: true
|
||||
|
||||
typescript@5.9.3:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==,
|
||||
}
|
||||
engines: { node: '>=14.17' }
|
||||
hasBin: true
|
||||
|
||||
uglify-js@3.4.10:
|
||||
resolution:
|
||||
{
|
||||
|
|
@ -10360,13 +10407,14 @@ packages:
|
|||
vue-template-compiler:
|
||||
optional: true
|
||||
|
||||
vue-property-decorator@8.5.1:
|
||||
vue-property-decorator@9.1.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-O6OUN2OMsYTGPvgFtXeBU3jPnX5ffQ9V4I1WfxFQ6dqz6cOUbR3Usou7kgFpfiXDvV7dJQSFcJ5yUPgOtPPm1Q==,
|
||||
integrity: sha512-xYA8MkZynPBGd/w5QFJ2d/NM0z/YeegMqYTphy7NJQXbZcuU6FC6AOdUAcy4SXP+YnkerC6AfH+ldg7PDk9ESQ==,
|
||||
}
|
||||
peerDependencies:
|
||||
vue: '*'
|
||||
vue-class-component: '*'
|
||||
|
||||
vue-style-loader@4.1.3:
|
||||
resolution:
|
||||
|
|
@ -10797,6 +10845,12 @@ packages:
|
|||
}
|
||||
engines: { node: '>=4' }
|
||||
|
||||
zod@4.6.2:
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-lh5RCAGFa1Cm2hjtNwLQhSs/AsqdWnTQaBER9fEwN/88pSh7KOtJavtBx/0VlkN/uFd61SwYmljLMDAsHlvzBQ==,
|
||||
}
|
||||
|
||||
snapshots:
|
||||
'@achrinza/node-ipc@9.2.2':
|
||||
dependencies:
|
||||
|
|
@ -11526,6 +11580,10 @@ snapshots:
|
|||
'@babel/helper-string-parser': 7.29.7
|
||||
'@babel/helper-validator-identifier': 7.29.7
|
||||
|
||||
'@boardgamers/protocol@0.2.2':
|
||||
dependencies:
|
||||
zod: 4.6.2
|
||||
|
||||
'@cspotcode/source-map-support@0.8.1':
|
||||
dependencies:
|
||||
'@jridgewell/trace-mapping': 0.3.9
|
||||
|
|
@ -11793,15 +11851,15 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/parser@4.33.0(eslint@7.32.0(supports-color@6.1.0))(supports-color@6.1.0)(typescript@4.9.5)':
|
||||
'@typescript-eslint/parser@4.33.0(eslint@7.32.0(supports-color@6.1.0))(supports-color@6.1.0)(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/scope-manager': 4.33.0
|
||||
'@typescript-eslint/types': 4.33.0
|
||||
'@typescript-eslint/typescript-estree': 4.33.0(supports-color@6.1.0)(typescript@4.9.5)
|
||||
'@typescript-eslint/typescript-estree': 4.33.0(supports-color@6.1.0)(typescript@5.9.3)
|
||||
debug: 4.4.3(supports-color@6.1.0)
|
||||
eslint: 7.32.0(supports-color@6.1.0)
|
||||
optionalDependencies:
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
|
|
@ -11840,7 +11898,7 @@ snapshots:
|
|||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@typescript-eslint/typescript-estree@4.33.0(supports-color@6.1.0)(typescript@4.9.5)':
|
||||
'@typescript-eslint/typescript-estree@4.33.0(supports-color@6.1.0)(typescript@5.9.3)':
|
||||
dependencies:
|
||||
'@typescript-eslint/types': 4.33.0
|
||||
'@typescript-eslint/visitor-keys': 4.33.0
|
||||
|
|
@ -11848,9 +11906,9 @@ snapshots:
|
|||
globby: 11.1.0
|
||||
is-glob: 4.0.3
|
||||
semver: 7.8.5
|
||||
tsutils: 3.21.0(typescript@4.9.5)
|
||||
tsutils: 3.21.0(typescript@5.9.3)
|
||||
optionalDependencies:
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
|
|
@ -11984,11 +12042,11 @@ snapshots:
|
|||
|
||||
'@vue/cli-overlay@4.5.19': {}
|
||||
|
||||
'@vue/cli-plugin-babel@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(core-js@3.50.0)(supports-color@7.2.0)(vue@2.7.16)':
|
||||
'@vue/cli-plugin-babel@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(core-js@3.50.0)(supports-color@7.2.0)(vue@2.7.16)':
|
||||
dependencies:
|
||||
'@babel/core': 7.29.7(supports-color@7.2.0)
|
||||
'@vue/babel-preset-app': 4.5.19(core-js@3.50.0)(supports-color@7.2.0)(vue@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-shared-utils': 4.5.19
|
||||
babel-loader: 8.4.1(@babel/core@7.29.7(supports-color@7.2.0))(webpack@4.47.0(supports-color@7.2.0))
|
||||
cache-loader: 4.1.0(webpack@4.47.0(supports-color@7.2.0))
|
||||
|
|
@ -12001,26 +12059,26 @@ snapshots:
|
|||
- webpack-cli
|
||||
- webpack-command
|
||||
|
||||
'@vue/cli-plugin-router@4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))':
|
||||
'@vue/cli-plugin-router@4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))':
|
||||
dependencies:
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-shared-utils': 4.5.19
|
||||
|
||||
'@vue/cli-plugin-typescript@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)':
|
||||
'@vue/cli-plugin-typescript@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)':
|
||||
dependencies:
|
||||
'@babel/core': 7.29.7(supports-color@7.2.0)
|
||||
'@types/webpack-env': 1.18.8
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-shared-utils': 4.5.19
|
||||
'@vue/compiler-sfc': 3.5.41
|
||||
babel-loader: 8.4.1(@babel/core@7.29.7(supports-color@7.2.0))(webpack@4.47.0(supports-color@7.2.0))
|
||||
cache-loader: 4.1.0(webpack@4.47.0(supports-color@7.2.0))
|
||||
fork-ts-checker-webpack-plugin: 3.1.1(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)(webpack@4.47.0(supports-color@7.2.0))
|
||||
fork-ts-checker-webpack-plugin: 3.1.1(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)(webpack@4.47.0(supports-color@7.2.0))
|
||||
globby: 9.2.0(supports-color@7.2.0)
|
||||
thread-loader: 2.1.3(webpack@4.47.0(supports-color@7.2.0))
|
||||
ts-loader: 6.2.2(typescript@4.9.5)
|
||||
tslint: 5.20.1(typescript@4.9.5)
|
||||
typescript: 4.9.5
|
||||
ts-loader: 6.2.2(typescript@5.9.3)
|
||||
tslint: 5.20.1(typescript@5.9.3)
|
||||
typescript: 5.9.3
|
||||
webpack: 4.47.0(supports-color@7.2.0)
|
||||
yorkie: 2.0.0
|
||||
optionalDependencies:
|
||||
|
|
@ -12031,9 +12089,9 @@ snapshots:
|
|||
- webpack-cli
|
||||
- webpack-command
|
||||
|
||||
'@vue/cli-plugin-unit-mocha@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))(supports-color@7.2.0)(webpack@4.47.0(supports-color@7.2.0))':
|
||||
'@vue/cli-plugin-unit-mocha@4.4.6(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))(supports-color@7.2.0)(webpack@4.47.0(supports-color@7.2.0))':
|
||||
dependencies:
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-shared-utils': 4.5.19
|
||||
jsdom: 15.2.1
|
||||
jsdom-global: 3.0.2(jsdom@15.2.1)
|
||||
|
|
@ -12046,18 +12104,18 @@ snapshots:
|
|||
- utf-8-validate
|
||||
- webpack
|
||||
|
||||
'@vue/cli-plugin-vuex@4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))':
|
||||
'@vue/cli-plugin-vuex@4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))':
|
||||
dependencies:
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)
|
||||
'@vue/cli-service': 4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)
|
||||
|
||||
'@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)':
|
||||
'@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)':
|
||||
dependencies:
|
||||
'@intervolga/optimize-cssnano-plugin': 1.0.6(webpack@4.47.0(supports-color@7.2.0))
|
||||
'@soda/friendly-errors-webpack-plugin': 1.8.1(webpack@4.47.0(supports-color@7.2.0))
|
||||
'@soda/get-current-script': 1.0.2
|
||||
'@vue/cli-overlay': 4.5.19
|
||||
'@vue/cli-plugin-router': 4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))
|
||||
'@vue/cli-plugin-vuex': 4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16))
|
||||
'@vue/cli-plugin-router': 4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))
|
||||
'@vue/cli-plugin-vuex': 4.5.19(@vue/cli-service@4.4.6(@vue/compiler-sfc@3.5.41)(bluebird@3.7.2)(lodash@4.18.1)(prettier@2.8.8)(sass-loader@8.0.2(sass@1.102.0)(webpack@4.47.0(supports-color@7.2.0)))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16))
|
||||
'@vue/cli-shared-utils': 4.5.19
|
||||
'@vue/component-compiler-utils': 3.3.0(lodash@4.18.1)
|
||||
'@vue/preload-webpack-plugin': 1.1.2(html-webpack-plugin@3.2.0(webpack@4.47.0(supports-color@7.2.0)))(webpack@4.47.0(supports-color@7.2.0))
|
||||
|
|
@ -12090,7 +12148,7 @@ snapshots:
|
|||
lodash.transform: 4.6.0
|
||||
mini-css-extract-plugin: 0.9.0(webpack@4.47.0(supports-color@7.2.0))
|
||||
minimist: 1.2.8
|
||||
pnp-webpack-plugin: 1.7.0(typescript@4.9.5)
|
||||
pnp-webpack-plugin: 1.7.0(typescript@5.9.3)
|
||||
portfinder: 1.0.38(supports-color@6.1.0)
|
||||
postcss-loader: 3.0.0
|
||||
ssri: 7.1.1
|
||||
|
|
@ -14590,7 +14648,7 @@ snapshots:
|
|||
|
||||
forever-agent@0.6.1: {}
|
||||
|
||||
fork-ts-checker-webpack-plugin@3.1.1(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@4.9.5)(vue-template-compiler@2.7.16)(webpack@4.47.0(supports-color@7.2.0)):
|
||||
fork-ts-checker-webpack-plugin@3.1.1(eslint@7.32.0(supports-color@6.1.0))(supports-color@7.2.0)(typescript@5.9.3)(vue-template-compiler@2.7.16)(webpack@4.47.0(supports-color@7.2.0)):
|
||||
dependencies:
|
||||
babel-code-frame: 6.26.0
|
||||
chalk: 2.4.2
|
||||
|
|
@ -14599,7 +14657,7 @@ snapshots:
|
|||
minimatch: 3.1.5
|
||||
semver: 5.7.2
|
||||
tapable: 1.1.3
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
webpack: 4.47.0(supports-color@7.2.0)
|
||||
worker-rpc: 0.1.1
|
||||
optionalDependencies:
|
||||
|
|
@ -14652,6 +14710,9 @@ snapshots:
|
|||
nan: 2.28.0
|
||||
optional: true
|
||||
|
||||
fsevents@2.3.2:
|
||||
optional: true
|
||||
|
||||
fsevents@2.3.3:
|
||||
optional: true
|
||||
|
||||
|
|
@ -16404,15 +16465,23 @@ snapshots:
|
|||
dependencies:
|
||||
find-up: 4.1.0
|
||||
|
||||
playwright-core@1.62.1: {}
|
||||
|
||||
playwright@1.62.1:
|
||||
dependencies:
|
||||
playwright-core: 1.62.1
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.2
|
||||
|
||||
please-upgrade-node@3.2.0:
|
||||
dependencies:
|
||||
semver-compare: 1.0.0
|
||||
|
||||
pn@1.1.0: {}
|
||||
|
||||
pnp-webpack-plugin@1.7.0(typescript@4.9.5):
|
||||
pnp-webpack-plugin@1.7.0(typescript@5.9.3):
|
||||
dependencies:
|
||||
ts-pnp: 1.2.0(typescript@4.9.5)
|
||||
ts-pnp: 1.2.0(typescript@5.9.3)
|
||||
transitivePeerDependencies:
|
||||
- typescript
|
||||
|
||||
|
|
@ -17746,14 +17815,14 @@ snapshots:
|
|||
|
||||
tryer@1.0.1: {}
|
||||
|
||||
ts-loader@6.2.2(typescript@4.9.5):
|
||||
ts-loader@6.2.2(typescript@5.9.3):
|
||||
dependencies:
|
||||
chalk: 2.4.2
|
||||
enhanced-resolve: 4.5.0
|
||||
loader-utils: 1.4.2
|
||||
micromatch: 4.0.8
|
||||
semver: 6.3.1
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
|
||||
ts-node@10.9.2(@types/node@13.13.52)(typescript@4.9.5):
|
||||
dependencies:
|
||||
|
|
@ -17773,9 +17842,9 @@ snapshots:
|
|||
v8-compile-cache-lib: 3.0.1
|
||||
yn: 3.1.1
|
||||
|
||||
ts-pnp@1.2.0(typescript@4.9.5):
|
||||
ts-pnp@1.2.0(typescript@5.9.3):
|
||||
optionalDependencies:
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
|
||||
tsconfig-paths@3.15.0:
|
||||
dependencies:
|
||||
|
|
@ -17788,7 +17857,7 @@ snapshots:
|
|||
|
||||
tslib@2.8.1: {}
|
||||
|
||||
tslint@5.20.1(typescript@4.9.5):
|
||||
tslint@5.20.1(typescript@5.9.3):
|
||||
dependencies:
|
||||
'@babel/code-frame': 7.29.7
|
||||
builtin-modules: 1.1.1
|
||||
|
|
@ -17802,19 +17871,24 @@ snapshots:
|
|||
resolve: 1.22.12
|
||||
semver: 5.7.2
|
||||
tslib: 1.14.1
|
||||
tsutils: 2.29.0(typescript@4.9.5)
|
||||
typescript: 4.9.5
|
||||
tsutils: 2.29.0(typescript@5.9.3)
|
||||
typescript: 5.9.3
|
||||
|
||||
tsutils@2.29.0(typescript@4.9.5):
|
||||
tsutils@2.29.0(typescript@5.9.3):
|
||||
dependencies:
|
||||
tslib: 1.14.1
|
||||
typescript: 4.9.5
|
||||
typescript: 5.9.3
|
||||
|
||||
tsutils@3.21.0(typescript@4.9.5):
|
||||
dependencies:
|
||||
tslib: 1.14.1
|
||||
typescript: 4.9.5
|
||||
|
||||
tsutils@3.21.0(typescript@5.9.3):
|
||||
dependencies:
|
||||
tslib: 1.14.1
|
||||
typescript: 5.9.3
|
||||
|
||||
tty-browserify@0.0.0: {}
|
||||
|
||||
tunnel-agent@0.6.0:
|
||||
|
|
@ -17883,6 +17957,8 @@ snapshots:
|
|||
|
||||
typescript@4.9.5: {}
|
||||
|
||||
typescript@5.9.3: {}
|
||||
|
||||
uglify-js@3.4.10:
|
||||
dependencies:
|
||||
commander: 2.19.0
|
||||
|
|
@ -18112,7 +18188,7 @@ snapshots:
|
|||
- walrus
|
||||
- whiskers
|
||||
|
||||
vue-property-decorator@8.5.1(vue@2.7.16):
|
||||
vue-property-decorator@9.1.2(vue-class-component@7.2.6(vue@2.7.16))(vue@2.7.16):
|
||||
dependencies:
|
||||
vue: 2.7.16
|
||||
vue-class-component: 7.2.6(vue@2.7.16)
|
||||
|
|
@ -18484,3 +18560,5 @@ snapshots:
|
|||
is-ci: 1.2.1
|
||||
normalize-path: 1.0.0
|
||||
strip-indent: 2.0.0
|
||||
|
||||
zod@4.6.2: {}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ allowBuilds:
|
|||
'@parcel/watcher': false
|
||||
core-js: false
|
||||
ejs: false
|
||||
fsevents: false
|
||||
nodent-runtime: false
|
||||
yorkie: false
|
||||
|
||||
|
|
@ -16,6 +17,9 @@ allowBuilds:
|
|||
# fresh installs). vue-template-compiler is the correct vue2 path.
|
||||
autoInstallPeers: false
|
||||
|
||||
minimumReleaseAgeExclude:
|
||||
- '@boardgamers/protocol@0.2.2'
|
||||
|
||||
# The cli-plugin-typescript fork-ts-checker shim does a bare
|
||||
# require('@vue/compiler-sfc') expecting the vue-3 parse shape ({descriptor}).
|
||||
# It declares no such dependency, so resolution falls back to pnpm's hidden
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = {
|
||||
presets: ['@vue/cli-plugin-babel/preset'],
|
||||
plugins: ['@babel/plugin-transform-export-namespace-from'],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@
|
|||
"build": "vue-cli-service build",
|
||||
"test:unit": "vue-cli-service test:unit",
|
||||
"package": "vue-cli-service build --target lib --name container-viewer src/wrapper.ts",
|
||||
"prepublishOnly": "npm run package"
|
||||
"prepublishOnly": "npm run package",
|
||||
"test:browser": "node scripts/protocol-smoke.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.2.2",
|
||||
"container-engine": "workspace:../engine",
|
||||
"core-js": "^3.6.5",
|
||||
"lodash": "^4.17.19",
|
||||
|
|
@ -21,9 +23,10 @@
|
|||
"tslib": "^2.2.0",
|
||||
"vue": "^2.6.11",
|
||||
"vue-class-component": "^7.2.3",
|
||||
"vue-property-decorator": "^8.4.2"
|
||||
"vue-property-decorator": "^9.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/plugin-transform-export-namespace-from": "7.29.7",
|
||||
"@types/assert": "^1.4.7",
|
||||
"@types/chai": "^4.2.11",
|
||||
"@types/events": "^3.0.0",
|
||||
|
|
@ -40,9 +43,10 @@
|
|||
"csstype": "^3.2.3",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-plugin-vue": "^7.11.0",
|
||||
"playwright": "1.62.1",
|
||||
"sass": "^1.26.5",
|
||||
"sass-loader": "^8.0.2",
|
||||
"typescript": "^4.3.5",
|
||||
"typescript": "^5.9.3",
|
||||
"vue-template-compiler": "^2.6.11"
|
||||
},
|
||||
"files": [
|
||||
|
|
|
|||
217
viewer/scripts/protocol-smoke.mjs
Normal file
217
viewer/scripts/protocol-smoke.mjs
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { createServer } from 'node:http';
|
||||
import { createRequire } from 'node:module';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { chromium } from 'playwright';
|
||||
|
||||
const game = 'container';
|
||||
const require = createRequire(import.meta.url);
|
||||
const repo = new URL('../../', import.meta.url);
|
||||
const engine = require(fileURLToPath(new URL('engine/dist/index.js', repo)));
|
||||
const html =
|
||||
'<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/bundle.css"><div id="app"></div><script src="/vue.js"></script>' +
|
||||
'<script src="/bundle.js"></script>';
|
||||
const server = createServer(async (req, res) => {
|
||||
try {
|
||||
const bundle = `viewer/dist/${game}-viewer.umd.min.js`;
|
||||
const css = `viewer/dist/${game}-viewer.css`;
|
||||
const files = {
|
||||
'/bundle.js': fileURLToPath(new URL(bundle, repo)),
|
||||
'/bundle.css': fileURLToPath(new URL(css, repo)),
|
||||
'/vue.js': require.resolve('vue/dist/vue.min.js'),
|
||||
};
|
||||
if (req.url === '/') {
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.end(html);
|
||||
} else if (files[req.url]) {
|
||||
res.setHeader('Content-Type', req.url.endsWith('.css') ? 'text/css' : 'text/javascript; charset=utf-8');
|
||||
res.end(await readFile(files[req.url]));
|
||||
} else {
|
||||
res.statusCode = 404;
|
||||
res.end();
|
||||
}
|
||||
} catch (error) {
|
||||
res.statusCode = 500;
|
||||
res.end(String(error));
|
||||
}
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const browser = await chromium.launch({ executablePath: process.env.CHROMIUM_EXECUTABLE });
|
||||
try {
|
||||
for (const width of [390, 1400]) {
|
||||
const page = await browser.newPage({ viewport: { width, height: 900 } });
|
||||
const errors = [];
|
||||
page.on('pageerror', (error) => errors.push(error.message));
|
||||
await page.goto(`http://127.0.0.1:${server.address().port}/`);
|
||||
assert.deepEqual(errors, [], 'bundle loads without browser errors');
|
||||
let state = engine.setup(3, {}, '17');
|
||||
state = JSON.parse(JSON.stringify(state));
|
||||
state.players.forEach((player, index) => {
|
||||
player.name = ['You', 'Ada Lovelace', 'Bob'][index];
|
||||
});
|
||||
const id = (value) => value.toString(16).padStart(24, '0');
|
||||
const messages = Array.from({ length: 35 }, (_, i) => ({
|
||||
_id: id(i + 1),
|
||||
type: 'text',
|
||||
author: 'Bob',
|
||||
playerIndex: 2,
|
||||
text: `Earlier message ${i + 1}`,
|
||||
createdAt: '2026-09-13T12:00:00Z',
|
||||
}));
|
||||
await page.evaluate(
|
||||
({ game, state, messages }) => {
|
||||
window.globalName = game;
|
||||
window.readyCount = 0;
|
||||
window.receipts = [];
|
||||
window.sent = [];
|
||||
window.playerClicks = [];
|
||||
window.fetches = 0;
|
||||
window.host = window[window.globalName].launch('#app');
|
||||
host.on('ready', () => readyCount++);
|
||||
host.on('fetchState', () => fetches++);
|
||||
host.on('chat:read', (payload) => receipts.push(payload));
|
||||
host.on('chat:send', (payload) => sent.push(payload));
|
||||
host.on('player:clicked', (payload) => playerClicks.push(payload));
|
||||
host.emit('preferences', { sound: false });
|
||||
host.emit('player', { index: 0 });
|
||||
host.emit('state', state);
|
||||
host.emit('chat:state', {
|
||||
canSend: true,
|
||||
mentions: [
|
||||
{ id: 'self', name: 'You', playerIndex: 0 },
|
||||
{ id: 'ada', name: 'Ada Lovelace', playerIndex: 1 },
|
||||
{ id: 'bob', name: 'Bob', playerIndex: 2 },
|
||||
],
|
||||
});
|
||||
host.emit('chat:messages', messages);
|
||||
},
|
||||
{ game, state, messages }
|
||||
);
|
||||
await page.waitForFunction(() => readyCount === 1);
|
||||
const panel = page.locator('.bgs-game-chat');
|
||||
const input = panel.locator('input');
|
||||
const list = panel.locator('.chat-messages');
|
||||
await panel.scrollIntoViewIfNeeded();
|
||||
await page.waitForFunction(() => {
|
||||
const el = document.querySelector('.chat-messages');
|
||||
return el && Math.abs(el.scrollHeight - el.scrollTop - el.clientHeight) < 3;
|
||||
});
|
||||
assert.equal(await panel.locator('summary').textContent(), 'Chat', 'old history is not unread');
|
||||
await input.fill('@');
|
||||
assert.deepEqual(await panel.locator('.chat-suggestions button').allTextContents(), ['@Ada Lovelace', '@Bob']);
|
||||
await input.press('Enter');
|
||||
assert.equal(await input.inputValue(), '@"Ada Lovelace" ');
|
||||
assert.equal(await page.evaluate(() => sent.length), 0, 'selecting a mention does not send');
|
||||
await input.fill('@"Ada Lovelace" hello');
|
||||
await input.press('Enter');
|
||||
assert.equal(await page.evaluate(() => sent.length), 1);
|
||||
await input.fill('next draft');
|
||||
await page.evaluate(() => host.emit('chat:result', { requestId: sent[0].requestId, ok: true }));
|
||||
assert.equal(await input.inputValue(), 'next draft', 'ack preserves a newer draft');
|
||||
await input.press('Enter');
|
||||
await page.evaluate(() =>
|
||||
host.emit('chat:result', { requestId: sent[1].requestId, ok: false, error: 'Try again' })
|
||||
);
|
||||
assert.equal(await input.inputValue(), 'next draft');
|
||||
assert.match(await panel.locator('.chat-status').textContent(), /Try again/);
|
||||
await panel.evaluate((el) => {
|
||||
el.open = false;
|
||||
});
|
||||
await page.evaluate(() => window.scrollTo(0, 0));
|
||||
const incoming = {
|
||||
_id: id(40),
|
||||
type: 'text',
|
||||
author: 'Ada Lovelace',
|
||||
playerIndex: 1,
|
||||
text: '@You see https://example.com',
|
||||
segments: [
|
||||
{ kind: 'mention', name: 'You', id: 'self' },
|
||||
{ kind: 'text', text: ' see ' },
|
||||
{ kind: 'link', text: 'example', url: 'https://example.com' },
|
||||
],
|
||||
};
|
||||
await page.evaluate((incoming) => {
|
||||
host.emit('chat:appended', [incoming]);
|
||||
host.emit('chat:appended', [incoming]);
|
||||
}, incoming);
|
||||
assert.match(await panel.locator('summary').textContent(), /1 unread/);
|
||||
assert.equal(await list.locator('article').count(), 36, 'duplicate append is ignored');
|
||||
await page.evaluate((messages) => host.emit('chat:messages', messages), [...messages, incoming]);
|
||||
assert.match(
|
||||
await panel.locator('summary').textContent(),
|
||||
/1 unread/,
|
||||
'history refresh preserves known unread'
|
||||
);
|
||||
const link = list.locator('a');
|
||||
assert.equal(await link.getAttribute('href'), 'https://example.com');
|
||||
assert.match(await link.getAttribute('rel'), /noopener/);
|
||||
await page.evaluate(
|
||||
(incoming) =>
|
||||
host.emit('chat:updated', [{ ...incoming, text: '<img src=x onerror=alert(1)>', segments: undefined }]),
|
||||
incoming
|
||||
);
|
||||
assert.equal(await list.locator('article').last().locator('img').count(), 0);
|
||||
assert.match(await list.locator('article').last().textContent(), /<img/);
|
||||
await page.evaluate((incoming) => host.emit('chat:updated', [incoming]), incoming);
|
||||
await panel.evaluate((el) => {
|
||||
el.open = true;
|
||||
});
|
||||
await panel.scrollIntoViewIfNeeded();
|
||||
await list.evaluate((el) => {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
el.dispatchEvent(new Event('scroll'));
|
||||
});
|
||||
await list.locator('.chat-mention').click();
|
||||
assert.deepEqual(await page.evaluate(() => playerClicks), [{ index: 0 }]);
|
||||
await page.waitForFunction(() => receipts.some((r) => r.messageId === '000000000000000000000028'));
|
||||
const receiptCount = await page.evaluate(() => receipts.length);
|
||||
await list.evaluate((el) => {
|
||||
el.scrollTop = 0;
|
||||
el.dispatchEvent(new Event('scroll'));
|
||||
el.scrollTop = el.scrollHeight;
|
||||
el.dispatchEvent(new Event('scroll'));
|
||||
});
|
||||
await page.waitForTimeout(650);
|
||||
assert.equal(await page.evaluate(() => receipts.length), receiptCount, 'scrolling does not repeat read events');
|
||||
await page.evaluate(() => host.emit('chat:deleted', ['000000000000000000000028']));
|
||||
assert.equal(await list.locator('article').count(), 35);
|
||||
await page.evaluate((state) => {
|
||||
host.emit('state', state);
|
||||
host.emit('state:updated');
|
||||
}, state);
|
||||
await page.waitForFunction(() => fetches > 0);
|
||||
assert.equal(await page.evaluate(() => readyCount), 1, 'ready fires once');
|
||||
await page.evaluate(
|
||||
(state) => host.emit('gamelog', { start: 0, data: { state: { ...state, newTurn: false } } }),
|
||||
state
|
||||
);
|
||||
await page.waitForTimeout(100);
|
||||
assert.equal(
|
||||
await page.evaluate(() => fetches),
|
||||
1,
|
||||
'tentative move state is rendered without fetching a committed state'
|
||||
);
|
||||
await page.screenshot({ path: `/tmp/${game}-protocol-${width}.png`, fullPage: true });
|
||||
await page.evaluate(
|
||||
({ state, incoming }) => {
|
||||
const old = host;
|
||||
host = window[globalName].launch('#app');
|
||||
host.emit('preferences', { sound: false });
|
||||
host.emit('player', { index: 0 });
|
||||
host.emit('state', state);
|
||||
host.emit('chat:state', { canSend: true });
|
||||
old.emit('chat:appended', [incoming]);
|
||||
},
|
||||
{ state, incoming }
|
||||
);
|
||||
assert.equal(await page.locator('.bgs-game-chat').count(), 1);
|
||||
assert.equal(await page.locator('.chat-messages article').count(), 0, 'relaunch detaches old chat');
|
||||
assert.deepEqual(errors, [], 'no browser errors');
|
||||
await page.close();
|
||||
console.log(`${game} ${width}px: protocol/chat smoke passed`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
await new Promise((resolve) => server.close(resolve));
|
||||
}
|
||||
|
|
@ -1,21 +1,22 @@
|
|||
import { ChatController, chatSegments, type ChatMessage } from '@boardgamers/protocol/chat';
|
||||
import { mountChat } from '@boardgamers/protocol/chat/dom';
|
||||
import { attachChat, type ViewerEmitter } from '@boardgamers/protocol/viewer';
|
||||
import { playerColors } from 'container-engine/src/engine';
|
||||
type ChatMessage = { _id?: string; author?: string; text: string; createdAt?: string; playerIndex?: number };
|
||||
type ChatEmitter = {
|
||||
on: (event: string, fn: (data: any) => void) => unknown;
|
||||
emit: (event: string, data: any) => unknown;
|
||||
};
|
||||
export function mountGameChat(emitter: ChatEmitter, host: Element): void {
|
||||
const panel = document.createElement('details');
|
||||
panel.className = 'bgs-game-chat';
|
||||
panel.open = true;
|
||||
panel.innerHTML =
|
||||
'<summary>Chat</summary><div class="chat-messages" role="log" aria-label="Game chat"></div><div class="chat-composer"><input type="text" aria-label="Chat message" placeholder="Message…" autocomplete="off"><button type="button">Send</button></div><div class="chat-status" role="status"></div>';
|
||||
type ChatEmitter = Pick<ViewerEmitter<any, any>, 'on' | 'emit'>;
|
||||
export function mountGameChat(emitter: ViewerEmitter<any, any>, host: Element): () => void {
|
||||
const chat = new ChatController();
|
||||
const detach = attachChat(emitter, chat);
|
||||
const slot = host.querySelector<HTMLElement>('.chat-host') || document.createElement('div');
|
||||
if (!slot.parentElement) host.insertAdjacentElement('afterend', slot);
|
||||
const style = document.createElement('style');
|
||||
style.textContent = `
|
||||
.bgs-game-chat{box-sizing:border-box;font:14px/1.4 Arial,sans-serif;border:1px solid #9eb4b5;border-radius:3px;margin:8px 0;padding:8px 12px;background:var(--bg-panel,#e5eeea);color:var(--text,#203a45)}
|
||||
.bgs-game-chat summary{cursor:pointer;font-weight:650;border-radius:3px;width:fit-content;padding:2px 4px;margin:-2px -4px}
|
||||
.bgs-game-chat summary:hover{color:#126778}
|
||||
.bgs-game-chat summary:focus-visible,.bgs-game-chat button:focus-visible{outline:2px solid #247d8c;outline-offset:3px}
|
||||
.bgs-game-chat .chat-day{display:flex;align-items:center;gap:8px;margin:12px 0 6px;font-size:.85em;opacity:.8}
|
||||
.bgs-game-chat .chat-day::before,.bgs-game-chat .chat-day::after{content:"";flex:1;border-top:1px solid currentColor;opacity:.3}
|
||||
.bgs-game-chat .chat-day time{margin:0;color:inherit;font-size:inherit}
|
||||
.bgs-game-chat .chat-messages{max-height:250px;overflow:auto;overscroll-behavior:contain;margin:6px 0 8px}
|
||||
.bgs-game-chat article{padding:5px 0;border-bottom:1px solid #75818d26;white-space:pre-wrap;overflow-wrap:anywhere}
|
||||
.bgs-game-chat article strong{padding:0 3px;font-weight:bold}
|
||||
|
|
@ -28,6 +29,11 @@ export function mountGameChat(emitter: ChatEmitter, host: Element): void {
|
|||
.bgs-game-chat button{box-sizing:border-box;height:30px;cursor:pointer;border:1px solid #7f8c8d;border-radius:3px;background:#dddeda;color:#172d34;padding:3px 12px;font:14px Arial,sans-serif}
|
||||
.bgs-game-chat button:hover:not(:disabled){background:#c8d3d0}
|
||||
.bgs-game-chat button:disabled{color:#788786;border-color:#b0bcb8;background:#dce3df;cursor:default}
|
||||
.bgs-game-chat .chat-mention{height:auto;padding:0 2px;border:0;background:transparent;color:inherit;font:inherit;font-weight:bold;text-decoration:underline}
|
||||
.bgs-game-chat article a{color:inherit;text-decoration:underline}
|
||||
.chat-suggestions{display:flex;flex-wrap:wrap;gap:4px;margin-top:4px}
|
||||
.chat-suggestions:empty{display:none}
|
||||
.chat-suggestions button[aria-pressed="true"]{outline:2px solid #527f89}
|
||||
.bgs-game-chat .chat-status{font-size:12px;margin-top:6px}
|
||||
.bgs-game-chat .chat-status:empty{display:none}
|
||||
.chat-shortcut{position:fixed;left:16px;bottom:max(16px,env(safe-area-inset-bottom));z-index:900;padding:7px 12px;border:1px solid #6a8589;border-radius:3px;background:#203a45;color:#fff;font:600 14px Arial,sans-serif;cursor:pointer;box-shadow:0 2px 6px #0003}
|
||||
|
|
@ -36,264 +42,92 @@ export function mountGameChat(emitter: ChatEmitter, host: Element): void {
|
|||
.chat-shortcut:focus-visible{outline:2px solid #fff;outline-offset:2px}
|
||||
|
||||
`;
|
||||
panel.append(style);
|
||||
const slot = host.querySelector('.chat-host');
|
||||
if (slot) slot.append(panel);
|
||||
else host.insertAdjacentElement('afterend', panel);
|
||||
const list = panel.querySelector('.chat-messages') as HTMLDivElement;
|
||||
const input = panel.querySelector('input') as HTMLInputElement;
|
||||
const button = panel.querySelector('button') as HTMLButtonElement;
|
||||
const status = panel.querySelector('.chat-status') as HTMLDivElement;
|
||||
let messages: ChatMessage[] = [];
|
||||
let players: { id: number; name: string }[] = [];
|
||||
slot.append(style);
|
||||
let players: { id: number; name: string; color?: string; faction?: string }[] = [];
|
||||
let localPlayer: number | undefined;
|
||||
emitter.on('state', (state) => {
|
||||
players = state?.players || [];
|
||||
render();
|
||||
});
|
||||
emitter.on('player', (player) => {
|
||||
localPlayer = player?.index;
|
||||
render();
|
||||
});
|
||||
let canSend = false;
|
||||
let disabled = false;
|
||||
let reason = 'Chat is connecting…';
|
||||
let pending: { id: string; text: string } | undefined;
|
||||
let timeout: ReturnType<typeof setTimeout> | undefined;
|
||||
let readTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let watermark = '';
|
||||
let candidate = '';
|
||||
let following = true;
|
||||
const unread = new Set<string>();
|
||||
const summary = panel.querySelector('summary')!;
|
||||
let chatVisible = false;
|
||||
const shortcut = document.createElement('button');
|
||||
shortcut.type = 'button';
|
||||
shortcut.className = 'chat-shortcut';
|
||||
shortcut.hidden = true;
|
||||
panel.insertAdjacentElement('afterend', shortcut);
|
||||
let chatVisible = false;
|
||||
function updateShortcut(): void {
|
||||
const count = unread.size;
|
||||
slot.append(shortcut);
|
||||
const view = mountChat(slot, {
|
||||
chat,
|
||||
styles: false,
|
||||
openPlayer: (index) => emitter.emit('player:clicked', { index }),
|
||||
renderAuthor,
|
||||
onVisibilityChange(visible) {
|
||||
chatVisible = visible;
|
||||
updateShortcut();
|
||||
},
|
||||
});
|
||||
function renderAuthor(message: ChatMessage): Node {
|
||||
const author = document.createElement('strong');
|
||||
author.textContent = message.author || 'Game';
|
||||
const index =
|
||||
message.playerIndex ??
|
||||
(message.author === 'You' ? localPlayer : players.find((p) => p.name === message.author)?.id);
|
||||
if (index !== undefined && playerColors[index]) {
|
||||
author.style.backgroundColor = playerColors[index];
|
||||
author.style.color = author.style.backgroundColor === 'brown' ? '#fff' : '#111';
|
||||
}
|
||||
return author;
|
||||
}
|
||||
function updateShortcut() {
|
||||
const count = chat.unread;
|
||||
const label = count ? `Chat · ${count} unread` : 'Chat';
|
||||
shortcut.textContent = label;
|
||||
shortcut.setAttribute('aria-label', `Open ${label}`);
|
||||
summary.textContent = label;
|
||||
shortcut.hidden = chatVisible;
|
||||
shortcut.setAttribute('aria-label', `Open ${label}`);
|
||||
}
|
||||
shortcut.onclick = () => {
|
||||
panel.open = true;
|
||||
requestAnimationFrame(() => {
|
||||
const firstUnread = Array.from(list.children).find((row) =>
|
||||
unread.has((row as HTMLElement).dataset.id || '')
|
||||
);
|
||||
if (firstUnread) firstUnread.scrollIntoView({ block: 'center' });
|
||||
else panel.scrollIntoView({ block: 'center' });
|
||||
summary.focus({ preventScroll: true });
|
||||
read();
|
||||
});
|
||||
view.open();
|
||||
};
|
||||
const visibility = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const entry of entries) {
|
||||
if (entry.target === panel) {
|
||||
chatVisible =
|
||||
entry.isIntersecting &&
|
||||
entry.intersectionRect.height >=
|
||||
Math.min(panel.open ? 80 : 20, entry.boundingClientRect.height);
|
||||
}
|
||||
const dispose = [
|
||||
detach,
|
||||
chat.subscribe(updateShortcut),
|
||||
emitter.on('state', (state) => {
|
||||
players = (state?.players || []).map((player: any, index: number) => ({ ...player, id: index }));
|
||||
view.refresh();
|
||||
}),
|
||||
emitter.on('gamelog', ({ data }: any) => {
|
||||
if (data?.state) {
|
||||
players = (data.state.players || []).map((player: any, index: number) => ({ ...player, id: index }));
|
||||
view.refresh();
|
||||
}
|
||||
updateShortcut();
|
||||
read();
|
||||
},
|
||||
{ threshold: Array.from({ length: 21 }, (_, i) => i / 20) }
|
||||
);
|
||||
visibility.observe(panel);
|
||||
function controls(): void {
|
||||
button.disabled = !canSend || disabled || !!pending || !input.value.trim();
|
||||
input.disabled = !canSend || disabled;
|
||||
}
|
||||
function read(): void {
|
||||
if (!panel.open || document.visibilityState !== 'visible' || !document.hasFocus()) {
|
||||
return;
|
||||
}
|
||||
const bounds = list.getBoundingClientRect();
|
||||
const visible = Array.from(list.children).filter((el) => {
|
||||
const r = el.getBoundingClientRect();
|
||||
return r.bottom <= Math.min(bounds.bottom, window.innerHeight) + 1 && r.top >= Math.max(bounds.top, 0);
|
||||
});
|
||||
for (const row of visible) unread.delete((row as HTMLElement).dataset.id || '');
|
||||
updateShortcut();
|
||||
const id = (visible[visible.length - 1] as HTMLElement)?.dataset.id || '';
|
||||
if (!/^[a-f0-9]{24}$/i.test(id) || id.toLowerCase() <= watermark) {
|
||||
return;
|
||||
}
|
||||
candidate = candidate > id.toLowerCase() ? candidate : id.toLowerCase();
|
||||
if (!readTimer) {
|
||||
readTimer = setTimeout(() => {
|
||||
readTimer = undefined;
|
||||
if (
|
||||
panel.open &&
|
||||
document.visibilityState === 'visible' &&
|
||||
document.hasFocus() &&
|
||||
candidate > watermark
|
||||
) {
|
||||
watermark = candidate;
|
||||
emitter.emit('chat:read', { messageId: watermark });
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
function render(): void {
|
||||
list.textContent = '';
|
||||
for (const message of messages) {
|
||||
const row = document.createElement('article');
|
||||
row.dataset.id = message._id || '';
|
||||
const author = document.createElement('strong');
|
||||
author.textContent = message.author || 'Game';
|
||||
const index =
|
||||
message.playerIndex ??
|
||||
(message.author === 'You' ? localPlayer : players.find((p) => p.name === message.author)?.id);
|
||||
if (index !== undefined && playerColors[index]) {
|
||||
author.style.backgroundColor = playerColors[index];
|
||||
author.style.color = '#111';
|
||||
}
|
||||
row.append(author, document.createTextNode(' '), document.createTextNode(message.text));
|
||||
if (message.createdAt) {
|
||||
const time = document.createElement('time');
|
||||
const date = new Date(message.createdAt);
|
||||
if (!isNaN(date.getTime())) {
|
||||
time.textContent = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
time.title = date.toLocaleString();
|
||||
row.append(time);
|
||||
}
|
||||
}
|
||||
|
||||
list.append(row);
|
||||
}
|
||||
if (following) {
|
||||
list.scrollTop = list.scrollHeight;
|
||||
}
|
||||
updateShortcut();
|
||||
read();
|
||||
}
|
||||
emitter.on('chat:messages', (data: ChatMessage[]) => {
|
||||
messages = data || [];
|
||||
unread.clear();
|
||||
render();
|
||||
});
|
||||
emitter.on('chat:appended', (data: ChatMessage[]) => {
|
||||
for (const message of data || []) {
|
||||
if (!message._id || !messages.some((m) => m._id === message._id)) {
|
||||
messages.push(message);
|
||||
const own = message.playerIndex !== undefined && message.playerIndex === localPlayer;
|
||||
if (message._id && !own && message.author !== 'You') unread.add(message._id);
|
||||
}
|
||||
}
|
||||
render();
|
||||
});
|
||||
emitter.on('chat:updated', (data: ChatMessage[]) => {
|
||||
for (const message of data || []) {
|
||||
const index = messages.findIndex((m) => m._id === message._id);
|
||||
if (index >= 0) {
|
||||
messages[index] = message;
|
||||
}
|
||||
}
|
||||
render();
|
||||
});
|
||||
emitter.on('chat:deleted', (ids: string[]) => {
|
||||
messages = messages.filter((m) => !ids.includes(m._id || ''));
|
||||
ids.forEach((id) => unread.delete(id));
|
||||
render();
|
||||
});
|
||||
emitter.on('chat:disabled', (value: boolean) => {
|
||||
disabled = value;
|
||||
status.textContent = value ? 'Chat disabled' : reason;
|
||||
controls();
|
||||
});
|
||||
emitter.on('chat:state', (value: { canSend: boolean; reason?: string }) => {
|
||||
canSend = value.canSend;
|
||||
reason = canSend
|
||||
? ''
|
||||
: (
|
||||
{
|
||||
'not-logged-in': 'Sign in to chat',
|
||||
'not-confirmed': 'Confirm your account to chat',
|
||||
'not-a-player': 'Only players can send messages',
|
||||
'chat-disabled': 'Chat disabled',
|
||||
'no-game': 'Chat will be available when the game starts',
|
||||
} as Record<string, string>
|
||||
)[value.reason || ''] || 'Chat is read-only';
|
||||
status.textContent = reason;
|
||||
controls();
|
||||
});
|
||||
emitter.on('chat:result', (result: { requestId: string; ok: boolean; error?: string }) => {
|
||||
if (pending?.id !== result.requestId) {
|
||||
return;
|
||||
}
|
||||
if (timeout) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
if (result.ok && input.value === pending.text) {
|
||||
input.value = '';
|
||||
}
|
||||
status.textContent = result.ok ? '' : result.error || 'Message could not be sent. Your draft is kept.';
|
||||
pending = undefined;
|
||||
controls();
|
||||
});
|
||||
function sendMessage(): void {
|
||||
if (button.disabled) {
|
||||
return;
|
||||
}
|
||||
pending = { id: `${Date.now()}-${Math.random().toString(36).slice(2)}`, text: input.value };
|
||||
controls();
|
||||
status.textContent = 'Sending…';
|
||||
const sending = pending;
|
||||
timeout = setTimeout(() => {
|
||||
if (pending) {
|
||||
pending = undefined;
|
||||
status.textContent = 'No confirmation received. Check the conversation before sending again.';
|
||||
controls();
|
||||
}
|
||||
}, 20000);
|
||||
emitter.emit('chat:send', { text: sending.text.trim(), requestId: sending.id });
|
||||
}
|
||||
button.onclick = sendMessage;
|
||||
input.oninput = controls;
|
||||
input.onkeydown = (event) => {
|
||||
if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
sendMessage();
|
||||
}
|
||||
}),
|
||||
emitter.on('player', (player) => {
|
||||
localPlayer = player?.index;
|
||||
view.refresh();
|
||||
}),
|
||||
];
|
||||
return () => {
|
||||
dispose.forEach((cleanup) => cleanup());
|
||||
view.destroy();
|
||||
shortcut.remove();
|
||||
style.remove();
|
||||
};
|
||||
list.onscroll = () => {
|
||||
following = list.scrollHeight - list.scrollTop - list.clientHeight < 32;
|
||||
read();
|
||||
};
|
||||
panel.ontoggle = () => {
|
||||
if (panel.open && following) {
|
||||
list.scrollTop = list.scrollHeight;
|
||||
}
|
||||
read();
|
||||
};
|
||||
window.addEventListener('scroll', read, { passive: true });
|
||||
window.addEventListener('focus', read);
|
||||
window.addEventListener('resize', read);
|
||||
const sizing = new ResizeObserver(() => {
|
||||
updateShortcut();
|
||||
read();
|
||||
});
|
||||
sizing.observe(panel);
|
||||
document.addEventListener('visibilitychange', read);
|
||||
status.textContent = reason;
|
||||
controls();
|
||||
}
|
||||
|
||||
export function installLocalChat(emitter: ChatEmitter): void {
|
||||
let seat = 0;
|
||||
let roster: { id: string; name: string; playerIndex: number }[] = [];
|
||||
emitter.on('player', (player) => {
|
||||
seat = player.index ?? 0;
|
||||
});
|
||||
emitter.on('state', (state) => {
|
||||
roster = (state?.players || []).map((player: any, index: number) => ({
|
||||
id: String(index),
|
||||
name: player.name || `Player ${index + 1}`,
|
||||
playerIndex: index,
|
||||
}));
|
||||
emitter.emit('chat:state', { canSend: true, mentions: roster.filter((player) => player.playerIndex !== seat) });
|
||||
});
|
||||
emitter.emit('chat:state', { canSend: true });
|
||||
emitter.emit('chat:messages', [
|
||||
{
|
||||
_id: '000000000000000000000001',
|
||||
type: 'system',
|
||||
author: 'Playtest',
|
||||
text: 'Local chat preview. Messages stay in this browser.',
|
||||
createdAt: new Date().toISOString(),
|
||||
|
|
@ -302,7 +136,15 @@ export function installLocalChat(emitter: ChatEmitter): void {
|
|||
let next = 2;
|
||||
emitter.on('chat:send', ({ text, requestId }) => {
|
||||
emitter.emit('chat:appended', [
|
||||
{ _id: (next++).toString(16).padStart(24, '0'), author: 'You', text, createdAt: new Date().toISOString() },
|
||||
{
|
||||
_id: (next++).toString(16).padStart(24, '0'),
|
||||
type: 'text',
|
||||
author: 'You',
|
||||
playerIndex: seat,
|
||||
text,
|
||||
segments: chatSegments(text, new Map(roster.map((player) => [player.name, player.id])), true),
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
]);
|
||||
emitter.emit('chat:result', { requestId, ok: true });
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { createViewer } from '@boardgamers/protocol/viewer';
|
||||
import type { GameState, Move } from 'container-engine';
|
||||
import { EventEmitter } from 'events';
|
||||
import Vue from 'vue';
|
||||
|
|
@ -6,7 +7,14 @@ import { mountGameChat } from './game-chat';
|
|||
import { installActionSounds } from './sounds';
|
||||
import type { Preferences } from './types/ui-data';
|
||||
|
||||
let dispose: (() => void) | undefined;
|
||||
|
||||
function launch(selector: string) {
|
||||
const target = document.querySelector(selector);
|
||||
if (!target) throw new Error(`Viewer mount point not found: ${selector}`);
|
||||
dispose?.();
|
||||
const mountPoint = document.createElement('div');
|
||||
target.append(mountPoint);
|
||||
let params: {
|
||||
state: null | GameState;
|
||||
player?: number;
|
||||
|
|
@ -27,48 +35,50 @@ function launch(selector: string) {
|
|||
|
||||
const app = new Vue({
|
||||
render: (h) => h(Game, { props: params }, []),
|
||||
}).$mount(selector);
|
||||
}).$mount(mountPoint);
|
||||
|
||||
const item: EventEmitter = new EventEmitter();
|
||||
|
||||
// The move payload is the whole current turn so far (an array of atomic moves),
|
||||
// replayed by the engine wrapper from the last committed state.
|
||||
params.emitter.on('move', (moves: Move[]) => item.emit('move', moves));
|
||||
params.emitter.on('addLog', (data: string[]) => item.emit('addLog', data));
|
||||
params.emitter.on('replaceLog', (data: string[]) => item.emit('replaceLog', data));
|
||||
params.emitter.on('update:preference', (data: { name: string; value: any }) =>
|
||||
item.emit('update:preference', data)
|
||||
);
|
||||
|
||||
item.addListener('state', (data) => {
|
||||
params.state = data;
|
||||
app.$forceUpdate();
|
||||
app.$nextTick().then(() => item.emit('ready'));
|
||||
});
|
||||
item.addListener('state:updated', () => item.emit('fetchState'));
|
||||
item.addListener('player', (data) => {
|
||||
params.player = data.index;
|
||||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('preferences', (data) => {
|
||||
// Mutate (don't replace) the observable object so the update stays reactive
|
||||
Object.assign(params.preferences, data);
|
||||
app.$forceUpdate();
|
||||
});
|
||||
item.addListener('gamelog', (logData) => {
|
||||
if (logData?.data?.state) {
|
||||
// Move responses carry the (possibly tentative) resulting state. Tentative
|
||||
// states are never persisted or broadcast by the platform — this is the only
|
||||
// way they reach the acting player's viewer.
|
||||
params.state = logData.data.state;
|
||||
const viewer = createViewer<GameState, Move[]>({
|
||||
async onState(data) {
|
||||
params.state = data;
|
||||
app.$forceUpdate();
|
||||
} else {
|
||||
item.emit('fetchState');
|
||||
}
|
||||
await app.$nextTick();
|
||||
},
|
||||
onPlayer(data) {
|
||||
params.player = data.index;
|
||||
app.$forceUpdate();
|
||||
},
|
||||
onPreferences(data) {
|
||||
Object.assign(params.preferences, data);
|
||||
app.$forceUpdate();
|
||||
},
|
||||
async onLog(logData) {
|
||||
const data = logData.data as { state?: GameState } | undefined;
|
||||
// Tentative purchases are echoed only to the acting viewer.
|
||||
if (data?.state) {
|
||||
params.state = data.state;
|
||||
app.$forceUpdate();
|
||||
await app.$nextTick();
|
||||
} else viewer.fetchState();
|
||||
},
|
||||
});
|
||||
|
||||
const item = viewer.emitter;
|
||||
params.emitter.on('move', (moves: Move[]) => viewer.move(moves));
|
||||
params.emitter.on('fetchState', () => viewer.fetchState());
|
||||
params.emitter.on('addLog', (data: string[]) => viewer.addLog(data));
|
||||
params.emitter.on('replaceLog', (data: string[]) => viewer.replaceLog(data));
|
||||
params.emitter.on('replay:info', (info) => viewer.setReplayInfo(info));
|
||||
params.emitter.on('update:preference', ({ name, value }) => viewer.updatePreference(name, value));
|
||||
installActionSounds(item);
|
||||
mountGameChat(item, app.$el);
|
||||
const removeChat = mountGameChat(item, app.$el);
|
||||
app.$once('hook:beforeDestroy', () => {
|
||||
removeChat();
|
||||
viewer.destroy();
|
||||
params.emitter.removeAllListeners();
|
||||
});
|
||||
dispose = () => {
|
||||
app.$destroy();
|
||||
target.replaceChildren();
|
||||
};
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ function launchSelfContained(selector = '#app') {
|
|||
console.log('available moves', gameState.players[playerIndex].availableMoves);
|
||||
});
|
||||
|
||||
emitter.on('fetchSate', () =>
|
||||
emitter.on('fetchState', () =>
|
||||
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState))
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import type { ViewerEmitter } from '@boardgamers/protocol/viewer';
|
||||
type Note = [number, number, number, number, number?, number?];
|
||||
type Cue = { label: string; notes: Note[] };
|
||||
export const soundCues: Record<string, Cue> = {
|
||||
|
|
@ -111,7 +112,7 @@ export function playSound(name: string): void {
|
|||
.catch(() => undefined);
|
||||
}
|
||||
|
||||
export function installActionSounds(emitter: { on: (event: string, fn: (value: any) => void) => unknown }): void {
|
||||
export function installActionSounds(emitter: Pick<ViewerEmitter<any, any>, 'on'>): void {
|
||||
let previous: string[] | undefined;
|
||||
let replaying = false;
|
||||
emitter.on('update:preference', (pref) => {
|
||||
|
|
@ -153,13 +154,14 @@ export function installActionSounds(emitter: { on: (event: string, fn: (value: a
|
|||
};
|
||||
emitter.on('state', receiveState);
|
||||
emitter.on('gamelog', (event) => {
|
||||
if (event?.data?.state) {
|
||||
receiveState(event.data.state);
|
||||
const data = event?.data as { state?: any } | undefined;
|
||||
if (data?.state) {
|
||||
receiveState(data.state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function mountSoundTests(emitter: { emit: (event: string, value: any) => unknown }): void {
|
||||
export function mountSoundTests(emitter: Pick<ViewerEmitter<any, any>, 'emit'>): void {
|
||||
const panel = document.createElement('details');
|
||||
panel.style.cssText =
|
||||
'position:relative;z-index:5;padding:10px 16px;margin:8px;background:#172638;color:#f0f4f8;border:1px solid #56718a;border-radius:8px;font:14px system-ui';
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"importHelpers": true,
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "bundler",
|
||||
"experimentalDecorators": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
|
@ -17,7 +17,9 @@
|
|||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
|
||||
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
|
||||
"skipLibCheck": true,
|
||||
"useDefineForClassFields": false
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
|
|
|
|||
|
|
@ -4,12 +4,41 @@
|
|||
// every static asset must be inlined into the bundles as a data URI.
|
||||
const INLINE_ASSETS_LIMIT = 10 * 1024 * 1024;
|
||||
|
||||
const { dirname, join } = require('path');
|
||||
const protocolDist = dirname(require.resolve('@boardgamers/protocol/viewer'));
|
||||
|
||||
module.exports = {
|
||||
transpileDependencies: ['@boardgamers/protocol', 'zod'],
|
||||
devServer: {
|
||||
// For gitpod, it needs to be disabled
|
||||
disableHostCheck: true,
|
||||
},
|
||||
chainWebpack: (config) => {
|
||||
// App and library builds use different Vue import transforms.
|
||||
for (const name of ['js', 'ts', 'tsx', 'vue']) {
|
||||
const rule = config.module.rule(name);
|
||||
if (rule.uses.has('cache-loader')) {
|
||||
rule.use('cache-loader').tap((options) => ({
|
||||
...options,
|
||||
cacheIdentifier: `${options.cacheIdentifier}:${process.env.VUE_CLI_BUILD_TARGET || 'app'}`,
|
||||
}));
|
||||
}
|
||||
}
|
||||
// Engine sources have their own tsconfig; every viewer worker must use
|
||||
// the Vue config, including its legacy-decorator setting.
|
||||
for (const name of ['ts', 'tsx']) {
|
||||
config.module
|
||||
.rule(name)
|
||||
.use('ts-loader')
|
||||
.tap((options) => ({
|
||||
...options,
|
||||
configFile: join(__dirname, 'tsconfig.json'),
|
||||
}));
|
||||
}
|
||||
// Webpack 4 predates package exports; resolve the published ESM entry points.
|
||||
config.resolve.alias.set('@boardgamers/protocol/viewer', join(protocolDist, 'viewer.js'));
|
||||
config.resolve.alias.set('@boardgamers/protocol/chat/dom$', join(protocolDist, 'chat-dom.js'));
|
||||
config.resolve.alias.set('@boardgamers/protocol/chat$', join(protocolDist, 'chat.js'));
|
||||
// vue-cli's svg rule uses plain file-loader (always emits files); replace it
|
||||
// with url-loader so the icons are inlined. Reuse the url-loader already
|
||||
// resolved for the images rule (it is not hoisted to our node_modules).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue