To utilize `@api.global/typedsocket` effectively, let's explore how to integrate it into a project with TypeScript. This guide provides comprehensive usage scenarios, highlighting all features of the module. `@api.global/typedsocket` extends the capabilities of `typedrequest` by integrating websocket support, allowing for real-time, bidirectional communication between a client and server.
### Getting Started
#### Prerequisites
Before diving into examples, ensure you have the following:
- A basic understanding of TypeScript and Node.js.
- An existing project set up with TypeScript.
-`@api.global/typedrequest` and its dependencies installed in your project.
#### Initialization
First, let's import the required modules and initialize our server and client instances.
**Server Side:**
Within your server-side code, import and set up `TypedSocket` to create a websocket server.
```typescript
import { TypedSocket } from '@api.global/typedsocket';
import * as typedrequest from '@api.global/typedrequest';
// Initialize your TypedRouter
const typedRouter = new typedrequest.TypedRouter();
// Create the TypedSocket server
const server = await TypedSocket.createServer(typedRouter);
// Optionally, you can provide a smartexpressServerArg if you have an existing SmartExpress server
```
**Client Side:**
On the client side, initialize `TypedSocket` to connect to the websocket server.
```typescript
import { TypedSocket } from '@api.global/typedsocket';
`TypedSocket` automatically attempts to reconnect in the event of connection loss. Ensure your server and client logic accounts for reconnection, especially for maintaining state or re-subscribing to necessary events.
### Conclusion
Implementing `@api.global/typedsocket` provides a type-safe, real-time communication layer for your TypeScript applications, extending the functionality of `typedrequest` into the realm of websockets. This guide covered initialization, defining typed requests, sending requests, and advanced usage patterns like tagging connections and handling reconnections.
Integrating `@api.global/typedsocket` into your project harnesses the power of websockets with the benefits of type safety and structured request/response patterns, enabling more reliable and maintainable real-time applications.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.