Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Commit 59271f8

Browse files
committed
Fix websocket communication
1 parent 4689a85 commit 59271f8

15 files changed

+54
-24
lines changed

.vscode/tasks.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"type": "shell",
5151
"args": [
5252
"-r",
53+
"--workspace-concurrency=1",
5354
"run",
5455
"build"
5556
]

@xoutput/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"author": "Ármin Csutorás",
2929
"license": "MIT",
3030
"dependencies": {
31-
"@xoutput/api": "workspace:../api"
31+
"@xoutput/api": "workspace:*"
3232
},
3333
"devDependencies": {
3434
"@typescript-eslint/eslint-plugin": "^6.10.0",

@xoutput/client/pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@xoutput/client/src/websocket/input/InputDeviceClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ export const inputDeviceClient = {
2626
return session;
2727
})
2828
.then(
29-
(session) =>
30-
({
31-
...session,
32-
sendInput: (input: InputDeviceInputRequest) => session.sendMessage(input),
33-
}) as WebSocketSession<InputDeviceMessageSender>
29+
(session) => {
30+
const enhancedSession = session as WebSocketSession<InputDeviceMessageSender>;
31+
enhancedSession.sendInput = (input: InputDeviceInputRequest) => session.sendMessage(input);
32+
return enhancedSession;
33+
}
3434
);
3535
},
3636
};

@xoutput/client/src/websocket/websocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { DebugRequest, MessageBase, PongResponse } from '@xoutput/api';
22

33
export class WebSocketService {
4-
connect(path: string, onMessage: (data: MessageBase) => void): Promise<WebSocketSessionImpl> {
4+
connect(path: string, onMessage: (data: MessageBase) => void): Promise<WSSession> {
55
return new Promise((resolve, reject) => {
6-
const url = `/websocket/${path}`;
6+
const url = `ws://${location.host}/websocket/${path}`;
77
const websocket = new WebSocket(url);
88
let session: WebSocketSessionImpl;
99
let pingInterval: number;

@xoutput/client/src/websocket/xbox/XboxDeviceClient.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ export const xboxDeviceClient = {
1414
}
1515
})
1616
.then(
17-
(session) =>
18-
({
19-
...session,
20-
sendInput: (input: XboxInputRequest) => session.sendMessage(input),
21-
}) as WebSocketSession<XboxInputMessageSender>
17+
(session) => {
18+
const enhancedSession = session as WebSocketSession<XboxInputMessageSender>;
19+
enhancedSession.sendInput = (input: XboxInputRequest) => session.sendMessage(input);
20+
return enhancedSession;
21+
}
2222
);
2323
},
2424
};

@xoutput/webapp/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"private": true,
66
"scripts": {
77
"build": "tsc && vite build",
8-
"watch": "vite dev",
8+
"watch": "vite",
99
"lint": "eslint",
1010
"fix-format": "eslint --fix && prettier --write \"src/**/*.{ts,tsx}\"",
1111
"test": "echo \"No test specified\""
@@ -21,8 +21,8 @@
2121
"@mui/material": "^5.14.17",
2222
"@mui/styled-engine": "^5.14.17",
2323
"@mui/system": "^5.14.17",
24-
"@xoutput/api": "workspace:../api",
25-
"@xoutput/client": "workspace:../client",
24+
"@xoutput/api": "workspace:*",
25+
"@xoutput/client": "workspace:*",
2626
"moment": "^2.29.4",
2727
"qrcode": "^1.5.3",
2828
"react": "^18.2.0",

@xoutput/webapp/pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@xoutput/webapp/src/gamepad/GamepadReader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class GamepadReader {
1616

1717
constructor(public gamepad: Gamepad) {}
1818

19-
start(intervalMs = 1): Promise<void> {
19+
start(intervalMs = 10): Promise<void> {
2020
if (this.intervalId) {
2121
return;
2222
}
@@ -75,9 +75,9 @@ export class GamepadReader {
7575

7676
stop(): void {
7777
if (this.intervalId) {
78-
clearInterval(this.intervalId);
7978
this.session.close();
8079
this.session = undefined;
80+
clearInterval(this.intervalId);
8181
this.intervalId = undefined;
8282
}
8383
}

@xoutput/webapp/src/ui/input/Gamepad.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ const GamepadComponent = ({ gamepad }: GamepadProps) => {
2424
() => {
2525
setRunning(true);
2626
},
27-
() => {
27+
(err) => {
28+
console.error(err);
2829
/*error handling*/
2930
}
3031
);

@xoutput/webapp/vite.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export default defineConfig({
1111
},
1212
plugins: [react()],
1313
server: {
14-
port: 8080,
14+
port: 8080,
15+
open: true,
1516
proxy: {
1617
'/api': 'http://localhost:8000',
1718
'/websocket': {

docs/browser-client.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,17 @@ The web application requires Node 20 to build it, you can [download it](https://
1111
```shell
1212
npm install --global pnpm
1313
```
14+
15+
Install dependencies and build the application.
16+
17+
```shell
18+
pnpm --recursive install
19+
pnpm --recursive run build
20+
```
21+
22+
For development, there is a development server and watch builds.
23+
24+
```shell
25+
pnpm --recursive run watch
26+
```
27+

docs/desktop-client.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ The 4.x version client is built with .NET 7, you will need to [download it](http
99
| Running the reader application | .NET Desktop Runtime |
1010
| Building the application | SDK |
1111

12-
However these runtimes and SDKs are cross platform the application is only compatible with Windows.
12+
The SDK is only compatible with Windows.
13+
14+
```shell
15+
dotnet restore
16+
dotnet run
17+
```
1318

1419
### Reader application
1520

docs/server.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ The 4.x version backend is built with .NET 7, you will need to [download it](htt
1111

1212
However these runtimes and SDKs are cross platform the application is only compatible with Windows.
1313

14+
```shell
15+
dotnet restore
16+
dotnet run
17+
```
18+
1419
## Server application
1520

1621
The server application is responsible for:

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"url": "https://github.com/csutorasa/XOutput/issues",
1212
"author": "Ármin Csutorás",
1313
"license": "MIT",
14+
"scripts": {
15+
"prdocution": "pnpm --recursive --workspace-concurrency=1 run build"
16+
},
1417
"engines": {
1518
"node": ">=20.0.0",
1619
"npm": "use-pnpm-instead",

0 commit comments

Comments
 (0)