Skip to content

Commit

Permalink
Merge pull request #9 from xconnio/organize
Browse files Browse the repository at this point in the history
Reduce min sdk requirement and adjust code for it
  • Loading branch information
om26er authored May 8, 2024
2 parents 95b6eb7 + 3f05ed2 commit 64475eb
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 25 deletions.
1 change: 1 addition & 0 deletions lib/exports.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export "src/client.dart" show Client;
export "src/router.dart" show Router;
export "src/server.dart" show Server;
export "src/session.dart" show Session;
export "src/types.dart" show Event, Invocation, Registration, Result, Subscription;
7 changes: 4 additions & 3 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import "package:wamp/src/session.dart";
import "package:wamp/src/types.dart";
import "package:wamp/src/wsjoiner.dart";
import "package:wampproto/auth.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/src/session.dart";
import "package:xconn/src/types.dart";
import "package:xconn/src/wsjoiner.dart";

class Client {
Client({IClientAuthenticator? authenticator, Serializer? serializer}) {
_authenticator = authenticator;
Expand Down
16 changes: 13 additions & 3 deletions lib/src/realm.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import "package:wamp/src/types.dart";
import "package:wampproto/broker.dart";
import "package:wampproto/dealer.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/types.dart";

import "package:xconn/src/types.dart";

class Realm {
final Dealer _dealer = Dealer();
final Broker _broker = Broker();
Expand All @@ -28,10 +29,14 @@ class Realm {

Future<void> receiveMessage(int sessionID, Message msg) async {
switch (msg.messageType()) {
case Call.id || Yield.id || Register.id || UnRegister.id:
case Call.id:
case Yield.id:
case Register.id:
case UnRegister.id:
MessageWithRecipient recipient = _dealer.receiveMessage(sessionID, msg);
var client = _clients[recipient.recipient];
client?.sendMessage(recipient.message);
break;

case Publish.id:
List<MessageWithRecipient>? recipients = _broker.receiveMessage(sessionID, msg);
Expand All @@ -44,21 +49,26 @@ class Realm {
client?.sendMessage(recipient.message);
}

case Subscribe.id || UnSubscribe.id:
break;

case Subscribe.id:
case UnSubscribe.id:
List<MessageWithRecipient>? recipients = _broker.receiveMessage(sessionID, msg);
if (recipients == null) {
throw Exception("recipients null");
}
MessageWithRecipient recipient = recipients[0];
var client = _clients[recipient.recipient];
client?.sendMessage(recipient.message);
break;

case Goodbye.id:
_dealer.removeSession(sessionID);
_broker.removeSession(sessionID);
var client = _clients[sessionID];
await client?.close();
_clients.remove(sessionID);
break;
}
}
}
5 changes: 3 additions & 2 deletions lib/src/router.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import "package:wamp/src/realm.dart";
import "package:wamp/src/types.dart";
import "package:wampproto/messages.dart";

import "package:xconn/src/realm.dart";
import "package:xconn/src/types.dart";

class Router {
final Map<String, Realm> _realms = {};

Expand Down
8 changes: 4 additions & 4 deletions lib/src/server.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import "dart:async";
import "dart:io";

import "package:wamp/exports.dart";
import "package:wamp/src/helpers.dart";
import "package:wamp/src/types.dart";
import "package:wamp/src/wsacceptor.dart";
import "package:xconn/exports.dart";
import "package:xconn/src/helpers.dart";
import "package:xconn/src/types.dart";
import "package:xconn/src/wsacceptor.dart";

class Server {
Server(this._router);
Expand Down
10 changes: 8 additions & 2 deletions lib/src/session.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import "dart:async";

import "package:wamp/src/helpers.dart";
import "package:wamp/src/types.dart";
import "package:wampproto/idgen.dart";
import "package:wampproto/messages.dart" as msg;
import "package:wampproto/session.dart";

import "package:xconn/src/helpers.dart";
import "package:xconn/src/types.dart";

class Session {
Session(this._baseSession) {
_wampSession = WAMPSession(serializer: _baseSession.serializer);
Expand Down Expand Up @@ -90,18 +91,23 @@ class Session {
switch (message.msgType) {
case msg.Call.id:
_callRequests.remove(message.requestID);
break;

case msg.Register.id:
_registerRequests.remove(message.requestID);
break;

case msg.UnRegister.id:
_unregisterRequests.remove(message.requestID);
break;

case msg.Subscribe.id:
_subscribeRequests.remove(message.requestID);
break;

case msg.UnSubscribe.id:
_unsubscribeRequests.remove(message.requestID);
break;

case msg.Publish.id:
_publishRequests.remove(message.requestID);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/wsacceptor.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "dart:async";
import "dart:io";

import "package:wamp/src/helpers.dart";
import "package:wamp/src/types.dart";
import "package:wampproto/acceptor.dart";
import "package:wampproto/auth.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/src/helpers.dart";
import "package:xconn/src/types.dart";

class WAMPSessionAcceptor {
WAMPSessionAcceptor({IServerAuthenticator? authenticator}) {
_authenticator = authenticator;
Expand Down
5 changes: 3 additions & 2 deletions lib/src/wsjoiner.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "dart:async";
import "dart:io";

import "package:wamp/src/helpers.dart";
import "package:wamp/src/types.dart";
import "package:wampproto/auth.dart";
import "package:wampproto/joiner.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/src/helpers.dart";
import "package:xconn/src/types.dart";

class WAMPSessionJoiner {
WAMPSessionJoiner({IClientAuthenticator? authenticator, Serializer? serializer}) {
_serializer = serializer ?? JSONSerializer();
Expand Down
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: wamp
description: WAMP v2 Client for Dart.
version: 1.0.0
repository: https://github.com/xconnio/wamp.dart
name: xconn
description: WAMP v2 Client and Router for Dart.
version: 0.1.0
repository: https://github.com/xconnio/wamp-dart
publish_to: none

environment:
sdk: ^3.3.0
sdk: ^2.17.0

# Add regular dependencies here.
dependencies:
wampproto:
git: https://github.com/xconnio/wampproto.dart
git: https://github.com/xconnio/wampproto-dart

dev_dependencies:
lints: ^3.0.0
Expand Down
3 changes: 2 additions & 1 deletion test/wamp_session_joiner_test.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import "dart:typed_data";

import "package:test/test.dart";
import "package:wamp/src/helpers.dart";
import "package:wampproto/messages.dart";
import "package:wampproto/serializers.dart";

import "package:xconn/src/helpers.dart";

class TestSerializer implements Serializer {
@override
Uint8List serialize(final Message message) {
Expand Down

0 comments on commit 64475eb

Please sign in to comment.