mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-09 06:58:02 -05:00
docs: update TypeScript example
This commit is contained in:
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
@@ -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
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
"name": "typescript-example",
|
||||
"version": "1.0.0",
|
||||
"description": "An example with TypeScript",
|
||||
"type": "commonjs",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
8
examples/typescript-example/cjs/tsconfig.json
Normal file
8
examples/typescript-example/cjs/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "es2022",
|
||||
"module": "nodenext",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
||||
18
examples/typescript-example/esm/client.ts
Normal file
18
examples/typescript-example/esm/client.ts
Normal file
@@ -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
examples/typescript-example/esm/package.json
Normal file
20
examples/typescript-example/esm/package.json
Normal file
@@ -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
examples/typescript-example/esm/server.ts
Normal file
16
examples/typescript-example/esm/server.ts
Normal file
@@ -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
examples/typescript-example/esm/tsconfig.json
Normal file
8
examples/typescript-example/esm/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"target": "es2022",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node"
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es5"
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user