diff --git a/lib/src/session.dart b/lib/src/session.dart index b2254e2..db4cc9b 100644 --- a/lib/src/session.dart +++ b/lib/src/session.dart @@ -3,6 +3,7 @@ import "dart:async"; import "package:wampproto/idgen.dart"; import "package:wampproto/messages.dart" as msg; import "package:wampproto/session.dart"; +import "package:wampproto/uris.dart"; import "package:xconn/src/exception.dart"; import "package:xconn/src/helpers.dart"; @@ -38,6 +39,7 @@ class Session { final Map _subscribeRequests = {}; final Map _subscriptions = {}; final Map _unsubscribeRequests = {}; + final Completer _goodbyeRequest = Completer(); void _processIncomingMessage(msg.Message message) { if (message is msg.Result) { @@ -135,6 +137,8 @@ class Session { default: throw ProtocolError(wampErrorString(message)); } + } else if (message is msg.Goodbye) { + _goodbyeRequest.complete(); } else { throw ProtocolError("Unexpected message type ${message.runtimeType}"); } @@ -221,4 +225,12 @@ class Session { return completer.future; } + + Future leave() { + var goodbyeMsg = msg.Goodbye({}, closeRealm); + var data = _wampSession.sendMessage(goodbyeMsg); + _baseSession.send(data); + + return _goodbyeRequest.future.timeout(const Duration(seconds: 10)); + } }