Skip to content

Commit

Permalink
Merge pull request #51 from muzzammilshahid/basic-readme
Browse files Browse the repository at this point in the history
Add README.md with project overview and usage instructions
  • Loading branch information
muzzammilshahid authored Jul 5, 2024
2 parents 734e4cc + 5f6d572 commit f53b03a
Showing 1 changed file with 141 additions and 2 deletions.
143 changes: 141 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,141 @@
# wamp.dart
WAMP v2 Client for Dart.
# xconn

WAMP v2 Client and Router for Dart.

## Installation

To install `xconn`, use the following command:

**With Dart**

```shell
dart pub add xconn
```

**With Flutter**

```shell
flutter pub add xconn
```

## Client

Creating a client:

```dart
import "package:xconn/xconn.dart";
void main() async {
var client = Client();
var session = await client.connect("ws://localhost:8080/ws", "realm1");
}
```

Once the session is established, you can perform WAMP actions. Below are examples of all 4 WAMP
operations:

### Subscribe to a topic

```dart
void exampleSubscribe(Session session) async {
var subscription = await session.subscribe("io.xconn.example", eventHandler);
print("Subscribed to topic io.xconn.example");
}
void eventHandler(Event event) {
print("Received Event: args=${event.args}, kwargs=${event.kwargs}, details=${event.details}");
}
```

### Publish to a topic

```dart
void examplePublish(Session session) async {
await session.publish("io.xconn.example", args: ["Hello World!", 100], kwargs: {"xconn": "dart"});
print("Published to topic io.xconn.example");
}
```

### Register a procedure

```dart
void exampleRegister(Session session) async {
var registration = await session.register("io.xconn.echo", invocationHandler);
print("Registered procedure io.xconn.echo");
}
Result invocationHandler(Invocation invocation) {
return Result(args: invocation.args, kwargs: invocation.kwargs, details: invocation.details);
}
```

### Call a procedure

```dart
void exampleCall(Session session) async {
var result = await session.call("io.xconn.echo", args: ["Hello World!"], kwargs: {"number": 100});
print("Call result: args=${result.args}, kwargs=${result.kwargs}, details=${result.details}");
}
```

### Authentication

Authentication is straightforward. Simply create the object of the desired authenticator and pass it
to the Client.

**Ticket Auth**

```dart
void main() async {
var ticketAuthenticator = TicketAuthenticator(ticket, authid);
var client = Client(authenticator: ticketAuthenticator);
var session = await client.connect("ws://localhost:8080/ws", "realm1");
}
```

**Challenge Response Auth**

```dart
void main() async {
var craAuthenticator = WAMPCRAAuthenticator(secret, authid);
var client = Client(authenticator: craAuthenticator);
var session = await client.connect("ws://localhost:8080/ws", "realm1");
}
```

**Cryptosign Auth**

```dart
void main() async {
var cryptosignAuthenticator = CryptoSignAuthenticator(privateKey, authid);
var client = Client(authenticator: cryptosignAuthenticator);
var session = await client.connect("ws://localhost:8080/ws", "realm1");
}
```

For more detailed examples or usage, refer to the [example](./example) folder of the project.

## Server

Setting up a basic server is straightforward:

```dart
import 'package:xconn/xconn.dart';
void main() async {
var router = Router()
..addRealm('realm1');
var server = Server(router);
await server.start('localhost', 8080);
}
```

For more advanced usage, such as integrating an authenticator, refer to the sample tool available
in the [bin](./bin) folder of the project.

## Maintainer

For questions or issues, contact the maintainers:

- [[email protected]](mailto:[email protected])
- [[email protected]](mailto:[email protected])

0 comments on commit f53b03a

Please sign in to comment.