File tree Expand file tree Collapse file tree 8 files changed +115
-1
lines changed
examples/typescript-client-example
packages/engine.io-client/lib/transports Expand file tree Collapse file tree 8 files changed +115
-1
lines changed Original file line number Diff line number Diff line change 1919 - custom-parsers
2020 - typescript-example/cjs
2121 - typescript-example/esm
22+ - typescript-client-example/cjs
23+ - typescript-client-example/esm
2224 - webpack-build
2325 - webpack-build-server
2426 - basic-crud-application/angular-client
Original file line number Diff line number Diff line change 1+ import { io , type Socket } from "socket.io-client" ;
2+
3+ interface ServerToClientEvents {
4+ hello : ( val : string ) => void ;
5+ }
6+
7+ interface ClientToServerEvents {
8+ ping : ( cb : ( ) => void ) => void ;
9+ }
10+
11+ const socket : Socket < ServerToClientEvents , ClientToServerEvents > = io ( "ws://localhost:8080/" ) ;
12+
13+ socket . on ( "connect" , ( ) => {
14+ console . log ( `connect ${ socket . id } ` ) ;
15+ } ) ;
16+
17+ socket . on ( "hello" , ( val ) => {
18+ console . log ( `got ${ val } ` ) ;
19+ } ) ;
20+
21+ socket . on ( "disconnect" , ( ) => {
22+ console . log ( `disconnect` ) ;
23+ } ) ;
24+
25+ setInterval ( ( ) => {
26+ const start = Date . now ( ) ;
27+ socket . emit ( "ping" , ( ) => {
28+ console . log ( `pong (latency: ${ Date . now ( ) - start } ms)` ) ;
29+ } ) ;
30+ } , 1000 ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " typescript-client-example-cjs" ,
3+ "version" : " 0.0.1" ,
4+ "description" : " An example with TypeScript" ,
5+ "type" : " commonjs" ,
6+ "private" : true ,
7+ "scripts" : {
8+ "build" : " tsc" ,
9+ "start" : " ts-node client.ts"
10+ },
11+ "license" : " MIT" ,
12+ "dependencies" : {
13+ "socket.io-client" : " ^4.8.0" ,
14+ "ts-node" : " ^10.9.2" ,
15+ "typescript" : " ^5.4.5"
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "outDir" : " dist" ,
4+ "target" : " es2022" ,
5+ "module" : " nodenext" ,
6+ "moduleResolution" : " nodenext" ,
7+ "strict" : true
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ import { io , type Socket } from "socket.io-client" ;
2+
3+ interface ServerToClientEvents {
4+ hello : ( val : string ) => void ;
5+ }
6+
7+ interface ClientToServerEvents {
8+ ping : ( cb : ( ) => void ) => void ;
9+ }
10+
11+ const socket : Socket < ServerToClientEvents , ClientToServerEvents > = io ( "ws://localhost:8080/" ) ;
12+
13+ socket . on ( "connect" , ( ) => {
14+ console . log ( `connect ${ socket . id } ` ) ;
15+ } ) ;
16+
17+ socket . on ( "hello" , ( val ) => {
18+ console . log ( `got ${ val } ` ) ;
19+ } ) ;
20+
21+ socket . on ( "disconnect" , ( ) => {
22+ console . log ( `disconnect` ) ;
23+ } ) ;
24+
25+ setInterval ( ( ) => {
26+ const start = Date . now ( ) ;
27+ socket . emit ( "ping" , ( ) => {
28+ console . log ( `pong (latency: ${ Date . now ( ) - start } ms)` ) ;
29+ } ) ;
30+ } , 1000 ) ;
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " typescript-client-example-esm" ,
3+ "version" : " 0.0.1" ,
4+ "description" : " An example with TypeScript" ,
5+ "type" : " module" ,
6+ "private" : true ,
7+ "scripts" : {
8+ "build" : " tsc" ,
9+ "start" : " node --no-warnings=ExperimentalWarning --loader ts-node/esm client.ts"
10+ },
11+ "license" : " MIT" ,
12+ "dependencies" : {
13+ "socket.io-client" : " ^4.8.0" ,
14+ "ts-node" : " ^10.9.2" ,
15+ "typescript" : " ^5.4.5"
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ {
2+ "compilerOptions" : {
3+ "outDir" : " dist" ,
4+ "target" : " es2022" ,
5+ "module" : " esnext" ,
6+ "moduleResolution" : " node" ,
7+ "strict" : true
8+ }
9+ }
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export class WS extends BaseWS {
1515 uri : string ,
1616 protocols : string | string [ ] | undefined ,
1717 opts : Record < string , any > ,
18- ) {
18+ ) : any {
1919 if ( this . socket ?. _cookieJar ) {
2020 opts . headers = opts . headers || { } ;
2121
You can’t perform that action at this time.
0 commit comments