Skip to content

Commit

Permalink
update websocket events
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Jan 12, 2025
1 parent 76b4726 commit c3b1480
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
16 changes: 8 additions & 8 deletions src/pages/Home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ export default function Home() {
const handleWebsockets = () => {
const req = {
event_type: 'graph_update',
id: 1337,
id: 9000,
type: 'subscribe_event'
}
// console.log("Send");
;(ws as any).send(JSON.stringify(++req.id && req))
ws.send(JSON.stringify(req.id && req))
}
document.addEventListener('subs_device_created', handleWebsockets)
return () => {
const removeGetWs = async () => {
const request = {
id: 1337,
id: 9000,
type: 'unsubscribe_event',
event_type: 'graph_update'
}
;(ws as any).send(JSON.stringify(++request.id && request))
ws.send(JSON.stringify(request.id && request))
}
// console.log("Clean Up");
removeGetWs()
Expand All @@ -93,21 +93,21 @@ export default function Home() {
const handleWebsockets = () => {
const req = {
event_type: 'device_created',
id: 1337,
id: 9001,
type: 'subscribe_event'
}
// console.log("Send");
;(ws as any).send(JSON.stringify(++req.id && req))
ws.send(JSON.stringify(req.id && req))
}
document.addEventListener('subs_device_created', handleWebsockets)
return () => {
const removeGetWs = async () => {
const request = {
id: 1337,
id: 9001,
type: 'unsubscribe_event',
event_type: 'device_created'
}
;(ws as any).send(JSON.stringify(++request.id && request))
ws.send(JSON.stringify(request.id && request))
}
// console.log("Clean Up");
removeGetWs()
Expand Down
22 changes: 10 additions & 12 deletions src/pages/Settings/Webaudio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ const Webaudio = ({ style }: { style: CSSProperties }) => {
: {})
},
client: webAudName,
id: i,
id: 8000 + i,
type: 'audio_stream_config'
}
;(ws as any).ws.send(JSON.stringify(++request.id && request))
ws.ws.send(JSON.stringify(++request.id && request))
}
sendWs()
}
Expand All @@ -150,20 +150,20 @@ const Webaudio = ({ style }: { style: CSSProperties }) => {
const request = {
data: base64String,
client: webAudName,
id: i,
id: 8500 + i,
type: 'audio_stream_data_v2'
}
;(ws as any).ws.send(JSON.stringify(++request.id && request))
ws.ws.send(JSON.stringify(++request.id && request))
}
const sendWsV1 = async () => {
const i = 0
const request = {
data: e.inputBuffer.getChannelData(0),
client: webAudName,
id: i,
id: 8000 + i,
type: 'audio_stream_data'
}
;(ws as any).ws.send(JSON.stringify(++request.id && request))
ws.ws.send(JSON.stringify(++request.id && request))
}
if (webAudType === 'audio_stream_data_v2') {
sendWsV2()
Expand Down Expand Up @@ -200,10 +200,10 @@ const Webaudio = ({ style }: { style: CSSProperties }) => {
const i = 0
const request = {
client: webAudName,
id: i,
id: 8200 + i,
type: 'audio_stream_stop'
}
;(ws as any).ws.send(JSON.stringify(++request.id && request))
ws.ws.send(JSON.stringify(++request.id && request))
}
sendWs().then(() => getSchemas())
setWebAud(false)
Expand Down Expand Up @@ -356,12 +356,10 @@ const Webaudio = ({ style }: { style: CSSProperties }) => {
const request = {
data: {},
client: webAudName,
id: 1,
id: 8499,
type: 'audio_stream_start'
}
;(ws as any).ws.send(
JSON.stringify(++request.id && request)
)
ws.ws.send(JSON.stringify(request.id && request))
}
sendWs()
setTimeout(() => {
Expand Down
20 changes: 10 additions & 10 deletions src/utils/Websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,34 @@ function createSocket() {
ws.ws = e.target as WebSocket
const req = {
event_type: 'devices_updated',
id: 1,
id: 9002,
type: 'subscribe_event'
}
ws.send(JSON.stringify(++req.id && req))
ws.send(JSON.stringify(req.id && req))
const requ = {
event_type: 'device_created',
id: 1,
id: 9001,
type: 'subscribe_event'
}
ws.send(JSON.stringify(++requ.id && requ))
ws.send(JSON.stringify(requ.id && requ))
const reque = {
event_type: 'graph_update',
id: 1,
id: 9000,
type: 'subscribe_event'
}
ws.send(JSON.stringify(++reque.id && reque))
ws.send(JSON.stringify(reque.id && reque))
const reqs = {
event_type: 'scene_activated',
id: 1,
id: 9003,
type: 'subscribe_event'
}
ws.send(JSON.stringify(++reqs.id && reqs))
ws.send(JSON.stringify(reqs.id && reqs))
const reqst = {
event_type: 'effect_set',
id: 1,
id: 9004,
type: 'subscribe_event'
}
ws.send(JSON.stringify(++reqst.id && reqst))
ws.send(JSON.stringify(reqst.id && reqst))
},
onmessage: (event) => {
if (JSON.parse(event.data).event_type === 'visualisation_update') {
Expand Down

0 comments on commit c3b1480

Please sign in to comment.