Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into w/#WIK-16196
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa committed Jul 31, 2024
2 parents 96d97a5 + bd7bf6b commit aede6ff
Show file tree
Hide file tree
Showing 6 changed files with 1,308 additions and 225 deletions.
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
# AITable

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.0.3.
## Development

## Development server
安装依赖

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files.
```
npm install --force
```

## Code scaffolding
前端启动

Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`.
```
npm run start
```

## Build
协同服务启动

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory.

## Running unit tests

Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io).

## Running end-to-end tests

Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.

## Further help

To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
```
npm run start-ws
```
43 changes: 43 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as Y from 'yjs';
import * as WebSocket from 'ws';
import http, { Server } from 'http';
const ywsUtils = require('y-websocket/bin/utils');
const setupWSConnection = ywsUtils.setupWSConnection;
const docs = ywsUtils.docs as Map<string, Y.Doc & { conns: Map<any, any> }>;
const port = (process.env['PORT'] || 3000) as number;

const server: Server = http.createServer((request, response) => {
if (request.url === '/health') {
response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(
JSON.stringify({
response: 'ok'
})
);
return;
}
});
const wss = new WebSocket.Server({ server });

wss.on('connection', (conn, req) => {
setupWSConnection(conn, req, { gc: false });
});

// log some stats
setInterval(() => {
let conns = 0;
docs.forEach((doc) => {
conns += doc.conns.size;
});
const stats = {
conns,
docs: docs.size,
websocket: `ws://localhost:${port}`,
http: `http://localhost:${port}`
};
console.log(`${new Date().toISOString()} Stats: ${JSON.stringify(stats)}`);
}, 10000);

server.listen(port, '0.0.0.0');

console.log(`Listening to http://localhost:${port}`);
Loading

0 comments on commit aede6ff

Please sign in to comment.