Skip to content

Commit

Permalink
working on new vm_loader / chat integration
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbuick committed Jan 4, 2025
1 parent 77257dc commit b6957d2
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 22 deletions.
10 changes: 6 additions & 4 deletions cafe/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
PlaneGeometry,
Points,
} from 'three'
import { vm_loadfile } from 'zss/device/api'
import { vm_loader } from 'zss/device/api'
import { registerreadplayer } from 'zss/device/register'
import { enableaudio } from 'zss/device/synth'
import { Terminal } from 'zss/gadget/terminal'
Expand Down Expand Up @@ -57,7 +57,7 @@ window.addEventListener('paste', (event) => {

// read files from clipboardData
const files = [...event.clipboardData.files]
files.forEach((file) => vm_loadfile('loadfile', file, registerreadplayer()))
files.forEach((file) => vm_loader('app', 'file', file, registerreadplayer()))
})

window.addEventListener('drop', (event) => {
Expand All @@ -72,14 +72,16 @@ window.addEventListener('drop', (event) => {
if (item.kind === 'file') {
const file = item.getAsFile()
if (ispresent(file)) {
vm_loadfile('loadfile', file, registerreadplayer())
vm_loader('app', 'file', file, registerreadplayer())
}
}
})
} else {
// Use DataTransfer interface to access the file(s)
const files = [...(event.dataTransfer?.files ?? [])]
files.forEach((file) => vm_loadfile('loadfile', file, registerreadplayer()))
files.forEach((file) =>
vm_loader('app', 'file', file, registerreadplayer()),
)
}
})

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@react-three/postprocessing": "^2.16.3",
"@syncedstore/core": "^0.6.0",
"@syncedstore/react": "^0.6.0",
"@twurple/auth": "^7.2.1",
"@twurple/chat": "^7.2.1",
"@types/is-hotkey": "^0.1.10",
"@types/jest": "^29.5.5",
"@types/lodash": "^4.17.13",
Expand Down Expand Up @@ -79,7 +81,6 @@
"source-map": "^0.7.4",
"stats.js": "^0.17.0",
"three": "0.170.0",
"tmi.js": "^1.8.5",
"tone": "^15.0.4",
"ts-extras": "^0.13.0",
"ts-jest": "^29.1.3",
Expand Down
171 changes: 160 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,91 @@
resolved "https://registry.npmjs.org/@chevrotain/utils/-/utils-11.0.3.tgz#e39999307b102cff3645ec4f5b3665f5297a2224"
integrity sha512-YslZMgtJUyuMbZ+aKvfF3x1f5liK4mWNxghFRv7jqRR9C3R3fAOGTTKvxXDa2Y1s9zSbcpuO0cAxDYsc9SrXoQ==

"@d-fischer/cache-decorators@^4.0.0":
version "4.0.1"
resolved "https://registry.npmjs.org/@d-fischer/cache-decorators/-/cache-decorators-4.0.1.tgz#a2daaa20467255653114655bf416a0d4dc1ef0ef"
integrity sha512-HNYLBLWs/t28GFZZeqdIBqq8f37mqDIFO6xNPof94VjpKvuP6ROqCZGafx88dk5zZUlBfViV9jD8iNNlXfc4CA==
dependencies:
"@d-fischer/shared-utils" "^3.6.3"
tslib "^2.6.2"

"@d-fischer/connection@^9.0.0":
version "9.0.0"
resolved "https://registry.npmjs.org/@d-fischer/connection/-/connection-9.0.0.tgz#8e684bdbc08330380de98d9cc3a61329b603d932"
integrity sha512-Mljp/EbaE+eYWfsFXUOk+RfpbHgrWGL/60JkAvjYixw6KREfi5r17XdUiXe54ByAQox6jwgdN2vebdmW1BT+nQ==
dependencies:
"@d-fischer/isomorphic-ws" "^7.0.0"
"@d-fischer/logger" "^4.2.1"
"@d-fischer/shared-utils" "^3.5.0"
"@d-fischer/typed-event-emitter" "^3.3.0"
"@types/ws" "^8.5.4"
tslib "^2.4.1"
ws "^8.11.0"

"@d-fischer/cross-fetch@^5.0.1":
version "5.0.5"
resolved "https://registry.npmjs.org/@d-fischer/cross-fetch/-/cross-fetch-5.0.5.tgz#5905ac512e8e14110de8d4b92c0c4e7da0e6b5d9"
integrity sha512-symjDUPInTrkfIsZc2n2mo9hiAJLcTJsZkNICjZajEWnWpJ3s3zn50/FY8xpNUAf5w3eFuQii2wxztTGpvG1Xg==
dependencies:
node-fetch "^2.6.12"

"@d-fischer/deprecate@^2.0.2":
version "2.0.2"
resolved "https://registry.npmjs.org/@d-fischer/deprecate/-/deprecate-2.0.2.tgz#d1f0d40acc881edd771cace7992a1070460608c8"
integrity sha512-wlw3HwEanJFJKctwLzhfOM6LKwR70FPfGZGoKOhWBKyOPXk+3a9Cc6S9zhm6tka7xKtpmfxVIReGUwPnMbIaZg==

"@d-fischer/detect-node@^3.0.1":
version "3.0.1"
resolved "https://registry.npmjs.org/@d-fischer/detect-node/-/detect-node-3.0.1.tgz#7b051a86611b0396ba205aabae805b18cc642a78"
integrity sha512-0Rf3XwTzuTh8+oPZW9SfxTIiL+26RRJ0BRPwj5oVjZFyFKmsj9RGfN2zuTRjOuA3FCK/jYm06HOhwNK+8Pfv8w==

"@d-fischer/escape-string-regexp@^5.0.0":
version "5.0.0"
resolved "https://registry.npmjs.org/@d-fischer/escape-string-regexp/-/escape-string-regexp-5.0.0.tgz#40b1d52529c5674caf510213efc9c982877d01c4"
integrity sha512-7eoxnxcto5eVPW5h1T+ePnVFukmI9f/ZR9nlBLh1t3kyzJDUNor2C+YW9H/Terw3YnbZSDgDYrpCJCHtOtAQHw==

"@d-fischer/isomorphic-ws@^7.0.0":
version "7.0.2"
resolved "https://registry.npmjs.org/@d-fischer/isomorphic-ws/-/isomorphic-ws-7.0.2.tgz#444eeb82c2f79566ec5e055fab1e2e43b578330c"
integrity sha512-xK+qIJUF0ne3dsjq5Y3BviQ4M+gx9dzkN+dPP7abBMje4YRfow+X9jBgeEoTe5e+Q6+8hI9R0b37Okkk8Vf0hQ==

"@d-fischer/logger@^4.2.1", "@d-fischer/logger@^4.2.3":
version "4.2.3"
resolved "https://registry.npmjs.org/@d-fischer/logger/-/logger-4.2.3.tgz#1c8f64a2dd560eb623b00eadffbd033a290fcc38"
integrity sha512-mJUx9OgjrNVLQa4od/+bqnmD164VTCKnK5B4WOW8TX5y/3w2i58p+PMRE45gUuFjk2BVtOZUg55JQM3d619fdw==
dependencies:
"@d-fischer/detect-node" "^3.0.1"
"@d-fischer/shared-utils" "^3.2.0"
tslib "^2.0.3"

"@d-fischer/qs@^7.0.2":
version "7.0.2"
resolved "https://registry.npmjs.org/@d-fischer/qs/-/qs-7.0.2.tgz#21942f51590e20954086bdc32fb3e608d3525659"
integrity sha512-yAu3xDooiL+ef84Jo8nLjDjWBRk7RXk163Y6aTvRB7FauYd3spQD/dWvgT7R4CrN54Juhrrc3dMY7mc+jZGurQ==

"@d-fischer/rate-limiter@^1.0.0":
version "1.0.1"
resolved "https://registry.npmjs.org/@d-fischer/rate-limiter/-/rate-limiter-1.0.1.tgz#e25ac89972b2ebbde53e748bc155dc910962533a"
integrity sha512-Mq+0pAJsx92hP83cjmsrXQZVQJ+/+u1JFT6fjH8pj3yfUrbT3eDBsA+6J63eat+QaC+Mci78HdiBfpsdBkdwog==
dependencies:
"@d-fischer/logger" "^4.2.3"
"@d-fischer/shared-utils" "^3.6.3"
tslib "^2.6.2"

"@d-fischer/shared-utils@^3.2.0", "@d-fischer/shared-utils@^3.5.0", "@d-fischer/shared-utils@^3.6.1", "@d-fischer/shared-utils@^3.6.3":
version "3.6.4"
resolved "https://registry.npmjs.org/@d-fischer/shared-utils/-/shared-utils-3.6.4.tgz#e372d1d53646ff60b631cc472686b9cdcbd943e2"
integrity sha512-BPkVLHfn2Lbyo/ENDBwtEB8JVQ+9OzkjJhUunLaxkw4k59YFlQxUUwlDBejVSFcpQT0t+D3CQlX+ySZnQj0wxw==
dependencies:
tslib "^2.4.1"

"@d-fischer/typed-event-emitter@^3.3.0", "@d-fischer/typed-event-emitter@^3.3.1":
version "3.3.3"
resolved "https://registry.npmjs.org/@d-fischer/typed-event-emitter/-/typed-event-emitter-3.3.3.tgz#d65fcf7756f3503bd56ed41bc916dc181d30597a"
integrity sha512-OvSEOa8icfdWDqcRtjSEZtgJTFOFNgTjje7zaL0+nAtu2/kZtRCSK5wUMrI/aXtCH8o0Qz2vA8UqkhWUTARFQQ==
dependencies:
tslib "^2.4.0"

"@esbuild/[email protected]":
version "0.21.5"
resolved "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz#c7184a326533fcdf1b8ee0733e21c713b975575f"
Expand Down Expand Up @@ -1178,6 +1263,53 @@
resolved "https://registry.npmjs.org/@tweenjs/tween.js/-/tween.js-23.1.3.tgz#eff0245735c04a928bb19c026b58c2a56460539d"
integrity sha512-vJmvvwFxYuGnF2axRtPYocag6Clbb5YS7kLL+SO/TeVFzHqDIWrNKYtcsPMibjDx9O+bu+psAy9NKfWklassUA==

"@twurple/[email protected]":
version "7.2.1"
resolved "https://registry.npmjs.org/@twurple/api-call/-/api-call-7.2.1.tgz#2aa95625a8517586d23a740970903ec153be1420"
integrity sha512-x+p6fMleFA/pJHVu8tFpkDkARGGt30EAUA+cLc+dEtU1EpH1mv7nv5LLHh9NW9vdZpYp0jk5TyY/TSbHdj7Ggw==
dependencies:
"@d-fischer/cross-fetch" "^5.0.1"
"@d-fischer/qs" "^7.0.2"
"@d-fischer/shared-utils" "^3.6.1"
"@twurple/common" "7.2.1"
tslib "^2.0.3"

"@twurple/auth@^7.2.1":
version "7.2.1"
resolved "https://registry.npmjs.org/@twurple/auth/-/auth-7.2.1.tgz#ae90cd3b13eeaf23fd9ec6832d69f288d882ec1b"
integrity sha512-IGHsJ/g0RblRSBC59XKA9277rE5w1dAKdhCPQz1QwkWnt6fsUyVoD1ut+qZvjuh7ssX1SBtNzFqohydfmWZytg==
dependencies:
"@d-fischer/logger" "^4.2.1"
"@d-fischer/shared-utils" "^3.6.1"
"@d-fischer/typed-event-emitter" "^3.3.1"
"@twurple/api-call" "7.2.1"
"@twurple/common" "7.2.1"
tslib "^2.0.3"

"@twurple/chat@^7.2.1":
version "7.2.1"
resolved "https://registry.npmjs.org/@twurple/chat/-/chat-7.2.1.tgz#a25d0c4b8cf27d7ce6d0013141ff1dcdd36e2c38"
integrity sha512-crhU7WcE/9xiLfYjh371SFsqvx2fIVp+af1BcmbwmowOOF3BG311op8EOOAXUfblIcKRuqVqAoMlq4pquYYQ7Q==
dependencies:
"@d-fischer/cache-decorators" "^4.0.0"
"@d-fischer/deprecate" "^2.0.2"
"@d-fischer/logger" "^4.2.1"
"@d-fischer/rate-limiter" "^1.0.0"
"@d-fischer/shared-utils" "^3.6.1"
"@d-fischer/typed-event-emitter" "^3.3.0"
"@twurple/common" "7.2.1"
ircv3 "^0.33.0"
tslib "^2.0.3"

"@twurple/[email protected]":
version "7.2.1"
resolved "https://registry.npmjs.org/@twurple/common/-/common-7.2.1.tgz#a0c86362e223e8fa5cc59b7029c9474b0bcd5b54"
integrity sha512-veLY5laA00dPuekAcpHN6GDvnr6s1uH7yBDebLC1NhpcLkQgiAlGA50RdNS5YeA3xz7kfE2MOcYSi2S6Qoc7EA==
dependencies:
"@d-fischer/shared-utils" "^3.6.1"
klona "^2.0.4"
tslib "^2.0.3"

"@types/babel__core@^7.1.14":
version "7.20.5"
resolved "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz#3df15f27ba85319caa07ba08d0721889bb39c017"
Expand Down Expand Up @@ -1375,6 +1507,13 @@
resolved "https://registry.npmjs.org/@types/webxr/-/webxr-0.5.20.tgz#b16b681af314ec011b2e8221b0a072d691c04953"
integrity sha512-JGpU6qiIJQKUuVSKx1GtQnHJGxRjtfGIhzO2ilq43VZZS//f1h1Sgexbdk+Lq+7569a6EYhOWrUpIruR/1Enmg==

"@types/ws@^8.5.4":
version "8.5.13"
resolved "https://registry.npmjs.org/@types/ws/-/ws-8.5.13.tgz#6414c280875e2691d0d1e080b05addbf5cb91e20"
integrity sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==
dependencies:
"@types/node" "*"

"@types/yargs-parser@*":
version "21.0.3"
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
Expand Down Expand Up @@ -3056,6 +3195,19 @@ internal-slot@^1.0.7:
hasown "^2.0.0"
side-channel "^1.0.4"

ircv3@^0.33.0:
version "0.33.0"
resolved "https://registry.npmjs.org/ircv3/-/ircv3-0.33.0.tgz#13b7a308f8604c088579ebf9615bb0ad457a78aa"
integrity sha512-7rK1Aial3LBiFycE8w3MHiBBFb41/2GG2Ll/fR2IJj1vx0pLpn1s+78K+z/I4PZTqCCSp/Sb4QgKMh3NMhx0Kg==
dependencies:
"@d-fischer/connection" "^9.0.0"
"@d-fischer/escape-string-regexp" "^5.0.0"
"@d-fischer/logger" "^4.2.1"
"@d-fischer/shared-utils" "^3.5.0"
"@d-fischer/typed-event-emitter" "^3.3.0"
klona "^2.0.5"
tslib "^2.4.1"

is-array-buffer@^3.0.4:
version "3.0.4"
resolved "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz#7a1f92b3d61edd2bc65d24f130530ea93d7fae98"
Expand Down Expand Up @@ -3826,6 +3978,11 @@ kleur@^4.0.3:
resolved "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz#95106101795f7050c6c650f350c683febddb1780"
integrity sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==

klona@^2.0.4, klona@^2.0.5:
version "2.0.6"
resolved "https://registry.npmjs.org/klona/-/klona-2.0.6.tgz#85bffbf819c03b2f53270412420a4555ef882e22"
integrity sha512-dhG34DXATL5hSxJbIexCft8FChFXtmskoZYnoPWjXQuebWYCNkVeV3KkGegCK9CP1oswI/vQibS2GY7Em/sJJA==

lethargy-ts@^0.1.0:
version "0.1.0"
resolved "https://registry.npmjs.org/lethargy-ts/-/lethargy-ts-0.1.0.tgz#70c40c2e26ab0899e049eee8dd31b5fd07ff6640"
Expand Down Expand Up @@ -4494,7 +4651,7 @@ natural-compare@^1.4.0:
resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==

node-fetch@^2.6.1:
node-fetch@^2.6.12:
version "2.7.0"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d"
integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==
Expand Down Expand Up @@ -5413,14 +5570,6 @@ [email protected]:
resolved "https://registry.npmjs.org/three/-/three-0.170.0.tgz#6087f97aab79e9e9312f9c89fcef6808642dfbb7"
integrity sha512-FQK+LEpYc0fBD+J8g6oSEyyNzjp+Q7Ks1C568WWaoMRLW+TkNNWmenWeGgJjV105Gd+p/2ql1ZcjYvNiPZBhuQ==

tmi.js@^1.8.5:
version "1.8.5"
resolved "https://registry.npmjs.org/tmi.js/-/tmi.js-1.8.5.tgz#8298821677599f163af075113f5d1bd51a648087"
integrity sha512-A9qrydfe1e0VWM9MViVhhxVgvLpnk7pFShVUWePsSTtoi+A1X+Zjdoa7OJd7/YsgHXGj3GkNEvnWop/1WwZuew==
dependencies:
node-fetch "^2.6.1"
ws "^8.2.0"

[email protected]:
version "1.0.5"
resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"
Expand Down Expand Up @@ -5488,7 +5637,7 @@ tsconfig-paths@^3.15.0:
minimist "^1.2.6"
strip-bom "^3.0.0"

tslib@^2.3.1, tslib@^2.6.2, tslib@^2.7.0, tslib@^2.8.1:
tslib@^2.0.3, tslib@^2.3.1, tslib@^2.4.0, tslib@^2.4.1, tslib@^2.6.2, tslib@^2.7.0, tslib@^2.8.1:
version "2.8.1"
resolved "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f"
integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==
Expand Down Expand Up @@ -5947,7 +6096,7 @@ ws@^7.2.0:
resolved "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz#58b5c20dc281633f6c19113f39b349bd8bd558d9"
integrity sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==

ws@^8.2.0:
ws@^8.11.0:
version "8.18.0"
resolved "https://registry.npmjs.org/ws/-/ws-8.18.0.tgz#0d7505a6eafe2b0e712d232b42279f53bc289bbc"
integrity sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==
Expand Down
17 changes: 15 additions & 2 deletions zss/device/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export function broadcast_stopstream(sender: string, player: string) {
hub.emit('broadcast:stopstream', sender, undefined, player)
}

export function chat_connect(sender: string, channel: string, player: string) {
hub.emit('chat:connect', sender, channel, player)
}

export function chat_disconnect(sender: string, player: string) {
hub.emit('chat:disconnect', sender, undefined, player)
}

export function gadgetclient_reset(
sender: string,
gadgetstate: GADGET_STATE,
Expand Down Expand Up @@ -283,6 +291,11 @@ export function vm_flush(sender: string, tag: string, player: string) {
hub.emit('vm:flush', sender, tag, player)
}

export function vm_loadfile(sender: string, file: File, player: string) {
hub.emit('vm:loadfile', sender, file, player)
export function vm_loader(
sender: string,
event: string,
content: any,
player: string,
) {
hub.emit('vm:loader', sender, [event, content], player)
}
36 changes: 36 additions & 0 deletions zss/device/chat.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,43 @@
import { ChatClient } from '@twurple/chat'
import { createdevice } from 'zss/device'
import { ispresent, isstring, MAYBE } from 'zss/mapping/types'
import { write } from 'zss/words/writeui'

import { api_error, vm_loader } from './api'
import { registerreadplayer } from './register'

let twitchchatclient: MAYBE<ChatClient>

const chat = createdevice('chat', [], (message) => {
switch (message.target) {
case 'connect':
if (ispresent(twitchchatclient)) {
api_error(chat.name(), 'connection', 'chat is already connected')
} else if (isstring(message.data)) {
write(chat.name(), 'connecting')
twitchchatclient = new ChatClient({ channels: [message.data] })
twitchchatclient.connect()
twitchchatclient.onConnect(() => {
write(chat.name(), 'connected')
})
twitchchatclient.onDisconnect(() => {
write(chat.name(), 'disconnected')
})
twitchchatclient.onMessage((_, user, text) => {
vm_loader(chat.name(), 'chat', [user, text], registerreadplayer())
})
}
break
case 'disconnect':
if (ispresent(twitchchatclient)) {
twitchchatclient.quit()
twitchchatclient = undefined
write(chat.name(), 'client quit')
} else {
api_error(chat.name(), 'connection', 'chat is already disconnected')
}
break

default:
break
}
Expand Down
9 changes: 5 additions & 4 deletions zss/device/vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ const vm = createdevice('vm', ['init', 'tick', 'second'], (message) => {
memorycli(message.player, message.data)
}
break
case 'loadfile':
case 'loader':
console.info(message.data)
// user input from built-in console
if (message.player === memorygetdefaultplayer()) {
memoryloadfile(message.player, message.data)
}
// if (message.player === memorygetdefaultplayer()) {
// memoryloadfile(message.player, message.data)
// }
break
default:
// running software messages
Expand Down
Loading

0 comments on commit b6957d2

Please sign in to comment.