Skip to content

Commit

Permalink
docs: update TypeScript example
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Apr 26, 2024
1 parent 14d4997 commit b25e728
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -50,7 +50,8 @@ jobs:
matrix:
example:
- custom-parsers
- typescript
- typescript-example/cjs
- typescript-example/esm
- webpack-build
- webpack-build-server
- basic-crud-application/angular-client
Expand Down
File renamed without changes.
Expand Up @@ -2,6 +2,7 @@
"name": "typescript-example",
"version": "1.0.0",
"description": "An example with TypeScript",
"type": "commonjs",
"private": true,
"scripts": {
"build": "tsc",
Expand All @@ -11,9 +12,9 @@
"author": "Damien Arrachequesne",
"license": "MIT",
"dependencies": {
"socket.io": "^4.0.0",
"socket.io-client": "^4.0.0",
"ts-node": "^9.0.0",
"typescript": "^4.0.5"
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions examples/typescript-example/cjs/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext"
}
}
18 changes: 18 additions & 0 deletions examples/typescript-example/esm/client.ts
@@ -0,0 +1,18 @@
import { io } from "socket.io-client";

const socket = io("ws://localhost:8080/", {});

socket.on("connect", () => {
console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
console.log(`disconnect`);
});

setInterval(() => {
const start = Date.now();
socket.emit("ping", () => {
console.log(`pong (latency: ${Date.now() - start} ms)`);
});
}, 1000);
20 changes: 20 additions & 0 deletions examples/typescript-example/esm/package.json
@@ -0,0 +1,20 @@
{
"name": "typescript-example",
"version": "1.0.0",
"description": "An example with TypeScript",
"type": "module",
"private": true,
"scripts": {
"build": "tsc",
"start:server": "node --no-warnings=ExperimentalWarning --loader ts-node/esm server.ts",
"start:client": "node --no-warnings=ExperimentalWarning --loader ts-node/esm client.ts"
},
"author": "Damien Arrachequesne",
"license": "MIT",
"dependencies": {
"socket.io": "^4.7.5",
"socket.io-client": "^4.7.5",
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
16 changes: 16 additions & 0 deletions examples/typescript-example/esm/server.ts
@@ -0,0 +1,16 @@
import { Server } from "socket.io";

const io = new Server(8080);

io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);

socket.on("ping", (cb) => {
console.log("ping");
cb();
});

socket.on("disconnect", () => {
console.log(`disconnect ${socket.id}`);
});
});
8 changes: 8 additions & 0 deletions examples/typescript-example/esm/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"outDir": "dist",
"target": "es2022",
"module": "esnext",
"moduleResolution": "node"
}
}
9 changes: 0 additions & 9 deletions examples/typescript/tsconfig.json

This file was deleted.

0 comments on commit b25e728

Please sign in to comment.