From e5acc333504ea6eea87ea3b3d0c0ec83225207b6 Mon Sep 17 00:00:00 2001 From: thomashii Date: Sat, 15 May 2021 15:19:35 +0800 Subject: [PATCH] Publish websocket --- packages/websocket/README.md | 31 ++++++----- packages/websocket/example/main.dart | 8 +-- ...l_websocket.dart => angel3_websocket.dart} | 2 +- .../websocket/lib/base_websocket_client.dart | 8 +-- packages/websocket/lib/browser.dart | 8 +-- packages/websocket/lib/flutter.dart | 6 +-- packages/websocket/lib/hooks.dart | 2 +- packages/websocket/lib/io.dart | 8 +-- packages/websocket/lib/server.dart | 22 ++++---- packages/websocket/lib/websocket_context.dart | 2 +- .../websocket/lib/websocket_controller.dart | 2 +- packages/websocket/pubspec.yaml | 54 ++++--------------- packages/websocket/test/auth_test.dart | 12 ++--- .../websocket/test/controller/common.dart | 4 +- .../websocket/test/controller/io_test.dart | 10 ++-- packages/websocket/test/service/common.dart | 8 +-- packages/websocket/test/service/io_test.dart | 10 ++-- packages/websocket/web/main.dart | 2 +- 18 files changed, 85 insertions(+), 114 deletions(-) rename packages/websocket/lib/{angel_websocket.dart => angel3_websocket.dart} (97%) diff --git a/packages/websocket/README.md b/packages/websocket/README.md index 3f09a41e..6f1a2fde 100644 --- a/packages/websocket/README.md +++ b/packages/websocket/README.md @@ -1,6 +1,9 @@ -# angel_websocket -[![Pub](https://img.shields.io/pub/v/angel_websocket.svg)](https://pub.dartlang.org/packages/angel_websocket) -[![build status](https://travis-ci.org/angel-dart/websocket.svg)](https://travis-ci.org/angel-dart/websocket) +# angel3_websocket +[![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_websocket) +[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety) +[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion) + +[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/websocket/LICENSE) WebSocket plugin for Angel. @@ -17,13 +20,13 @@ WebSocket contexts are add to `req.properties` as `'socket'`. **Server-side** ```dart -import "package:angel_framework/angel_framework.dart"; -import "package:angel_websocket/server.dart"; +import "package:angel3_framework/angel3_framework.dart"; +import "package:angel3_websocket/server.dart"; main() async { - var app = new Angel(); + var app = Angel(); - var ws = new AngelWebSocket(); + var ws = AngelWebSocket(); // This is a plug-in. It hooks all your services, // to automatically broadcast events. @@ -78,7 +81,7 @@ class MyController extends WebSocketController { // Event filtering @ExposeWs("foo") void foo() { - broadcast(new WebSocketEvent(...), filter: (socket) async => ...); + broadcast( WebSocketEvent(...), filter: (socket) async => ...); } } ``` @@ -86,7 +89,7 @@ class MyController extends WebSocketController { **Client Use** This repo also provides two client libraries `browser` and `io` that extend the base -`angel_client` interface, and allow you to use a very similar API on the client to that of +`angel3_client` interface, and allow you to use a very similar API on the client to that of the server. The provided clients also automatically try to reconnect their WebSockets when disconnected, @@ -99,10 +102,10 @@ Clients can even perform authentication over WebSockets. **In the Browser** ```dart -import "package:angel_websocket/browser.dart"; +import "package:angel3_websocket/browser.dart"; main() async { - Angel app = new WebSockets("/ws"); + Angel app = WebSockets("/ws"); await app.connect(); var Cars = app.service("api/cars"); @@ -127,8 +130,8 @@ main() async { **CLI Client** ```dart -import "package:angel_framework/common.dart"; -import "package:angel_websocket/io.dart"; +import "package:angel3_framework/common.dart"; +import "package:angel3_websocket/io.dart"; // You can include these in a shared file and access on both client and server class Car extends Model { @@ -141,7 +144,7 @@ class Car extends Model { } main() async { - Angel app = new WebSockets("/ws"); + Angel app = WebSockets("/ws"); // Wait for WebSocket connection... await app.connect(); diff --git a/packages/websocket/example/main.dart b/packages/websocket/example/main.dart index f5d8e13f..6c9502c6 100644 --- a/packages/websocket/example/main.dart +++ b/packages/websocket/example/main.dart @@ -1,8 +1,8 @@ import 'dart:io'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_framework/http.dart'; -import 'package:angel_framework/http2.dart'; -import 'package:angel_websocket/server.dart'; +import 'package:angel3_framework/angel3_framework.dart'; +import 'package:angel3_framework/http.dart'; +import 'package:angel3_framework/http2.dart'; +import 'package:angel3_websocket/server.dart'; import 'package:file/local.dart'; import 'package:logging/logging.dart'; diff --git a/packages/websocket/lib/angel_websocket.dart b/packages/websocket/lib/angel3_websocket.dart similarity index 97% rename from packages/websocket/lib/angel_websocket.dart rename to packages/websocket/lib/angel3_websocket.dart index 720e6282..5aa38192 100644 --- a/packages/websocket/lib/angel_websocket.dart +++ b/packages/websocket/lib/angel3_websocket.dart @@ -1,5 +1,5 @@ /// WebSocket plugin for Angel. -library angel_websocket; +library angel3_websocket; /// A notification from the server that something has occurred. class WebSocketEvent { diff --git a/packages/websocket/lib/base_websocket_client.dart b/packages/websocket/lib/base_websocket_client.dart index fc60bad7..716e4b6e 100644 --- a/packages/websocket/lib/base_websocket_client.dart +++ b/packages/websocket/lib/base_websocket_client.dart @@ -1,13 +1,13 @@ import 'dart:async'; import 'dart:collection'; import 'dart:convert'; -import 'package:angel_client/angel_client.dart'; -import 'package:angel_client/base_angel_client.dart'; -import 'package:angel_http_exception/angel_http_exception.dart'; +import 'package:angel3_client/angel3_client.dart'; +import 'package:angel3_client/base_angel_client.dart'; +import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:http/src/base_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/status.dart' as status; -import 'angel_websocket.dart'; +import 'angel3_websocket.dart'; import 'constants.dart'; final RegExp _straySlashes = RegExp(r'(^/)|(/+$)'); diff --git a/packages/websocket/lib/browser.dart b/packages/websocket/lib/browser.dart index e598748c..1cdb08c2 100644 --- a/packages/websocket/lib/browser.dart +++ b/packages/websocket/lib/browser.dart @@ -1,15 +1,15 @@ /// Browser WebSocket client library for the Angel framework. -library angel_websocket.browser; +library angel3_websocket.browser; import 'dart:async'; import 'dart:html'; -import 'package:angel_client/angel_client.dart'; -import 'package:angel_http_exception/angel_http_exception.dart'; +import 'package:angel3_client/angel3_client.dart'; +import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:http/browser_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/html.dart'; import 'base_websocket_client.dart'; -export 'angel_websocket.dart'; +export 'angel3_websocket.dart'; final RegExp _straySlashes = RegExp(r'(^/)|(/+$)'); diff --git a/packages/websocket/lib/flutter.dart b/packages/websocket/lib/flutter.dart index bb7ad9ff..94210e4e 100644 --- a/packages/websocket/lib/flutter.dart +++ b/packages/websocket/lib/flutter.dart @@ -7,10 +7,10 @@ import 'package:http/io_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/io.dart'; import 'base_websocket_client.dart'; -export 'package:angel_client/angel_client.dart'; -export 'angel_websocket.dart'; +export 'package:angel3_client/angel3_client.dart'; +export 'angel3_websocket.dart'; -// final RegExp _straySlashes = new RegExp(r"(^/)|(/+$)"); +// final RegExp _straySlashes = RegExp(r"(^/)|(/+$)"); /// Queries an Angel server via WebSockets. class WebSockets extends BaseWebSocketClient { diff --git a/packages/websocket/lib/hooks.dart b/packages/websocket/lib/hooks.dart index fd7154dc..668dd198 100644 --- a/packages/websocket/lib/hooks.dart +++ b/packages/websocket/lib/hooks.dart @@ -1,4 +1,4 @@ -import 'package:angel_framework/angel_framework.dart'; +import 'package:angel3_framework/angel3_framework.dart'; /// Prevents a WebSocket event from being broadcasted, to any client from the given [provider]. /// diff --git a/packages/websocket/lib/io.dart b/packages/websocket/lib/io.dart index 982ee11c..1423c1fb 100644 --- a/packages/websocket/lib/io.dart +++ b/packages/websocket/lib/io.dart @@ -1,15 +1,15 @@ /// Command-line WebSocket client library for the Angel framework. -library angel_websocket.io; +library angel3_websocket.io; import 'dart:async'; import 'dart:io'; -import 'package:angel_client/angel_client.dart'; +import 'package:angel3_client/angel3_client.dart'; import 'package:http/io_client.dart' as http; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:web_socket_channel/io.dart'; import 'base_websocket_client.dart'; -export 'package:angel_client/angel_client.dart'; -export 'angel_websocket.dart'; +export 'package:angel3_client/angel3_client.dart'; +export 'angel3_websocket.dart'; final RegExp _straySlashes = RegExp(r'(^/)|(/+$)'); diff --git a/packages/websocket/lib/server.dart b/packages/websocket/lib/server.dart index 1bc00b9c..0e0ea46f 100644 --- a/packages/websocket/lib/server.dart +++ b/packages/websocket/lib/server.dart @@ -1,22 +1,22 @@ /// Server-side support for WebSockets. -library angel_websocket.server; +library angel3_websocket.server; import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'dart:mirrors'; -import 'package:angel_auth/angel_auth.dart'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_framework/http.dart'; -import 'package:angel_framework/http2.dart'; -import 'package:merge_map/merge_map.dart'; +import 'package:angel3_auth/angel3_auth.dart'; +import 'package:angel3_framework/angel3_framework.dart'; +import 'package:angel3_framework/http.dart'; +import 'package:angel3_framework/http2.dart'; +import 'package:angel3_merge_map/angel3_merge_map.dart'; import 'package:stream_channel/stream_channel.dart'; import 'package:web_socket_channel/io.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; import 'package:collection/collection.dart' show IterableExtension; -import 'angel_websocket.dart'; +import 'angel3_websocket.dart'; import 'constants.dart'; -export 'angel_websocket.dart'; +export 'angel3_websocket.dart'; part 'websocket_context.dart'; @@ -249,14 +249,14 @@ class AngelWebSocket { var jwt = action.params!['query']['jwt'] as String; AuthToken token; - token = AuthToken.validate(jwt, auth.hmac!); - var user = await auth.deserializer!(token.userId); + token = AuthToken.validate(jwt, auth.hmac); + var user = await auth.deserializer!(token.userId as Object); socket.request ..container!.registerSingleton(token) ..container!.registerSingleton(user, as: user.runtimeType); socket._onAuthenticated.add(null); socket.send(authenticatedEvent, - {'token': token.serialize(auth.hmac!), 'data': user}); + {'token': token.serialize(auth.hmac), 'data': user}); } catch (e, st) { catchError(e, st, socket); } diff --git a/packages/websocket/lib/websocket_context.dart b/packages/websocket/lib/websocket_context.dart index 3e11a3f8..e3681a91 100644 --- a/packages/websocket/lib/websocket_context.dart +++ b/packages/websocket/lib/websocket_context.dart @@ -1,4 +1,4 @@ -part of angel_websocket.server; +part of angel3_websocket.server; /// Represents a WebSocket session, with the original /// [RequestContext] and [ResponseContext] attached. diff --git a/packages/websocket/lib/websocket_controller.dart b/packages/websocket/lib/websocket_controller.dart index 3fe7eb9a..03e23b8b 100644 --- a/packages/websocket/lib/websocket_controller.dart +++ b/packages/websocket/lib/websocket_controller.dart @@ -1,4 +1,4 @@ -part of angel_websocket.server; +part of angel3_websocket.server; /// Marks a method as available to WebSockets. class ExposeWs { diff --git a/packages/websocket/pubspec.yaml b/packages/websocket/pubspec.yaml index cfa3b588..36f0d700 100644 --- a/packages/websocket/pubspec.yaml +++ b/packages/websocket/pubspec.yaml @@ -1,56 +1,24 @@ -name: angel_websocket +name: angel3_websocket description: Support for using pkg:angel_client with WebSockets. Designed for Angel. version: 4.0.0 -homepage: https://github.com/dukefirehawk/angel -publish_to: none +homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/websocket environment: sdk: '>=2.12.0 <3.0.0' dependencies: - angel_auth: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/auth - angel_client: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/client - angel_framework: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/framework - angel_http_exception: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/http_exception + angel3_auth: ^4.0.0 + angel3_client: ^4.0.0 + angel3_framework: ^4.0.0 + angel3_http_exception: ^3.0.0 + angel3_merge_map: ^2.0.0 http: ^0.13.1 - merge_map: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/merge_map meta: ^1.3.0 stream_channel: ^2.1.0 - web_socket_channel: ^2.0.0 + web_socket_channel: ^2.1.0 collection: ^1.15.0 dev_dependencies: - angel_container: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/container/angel_container - angel_model: - git: - url: https://github.com/dukefirehawk/angel.git - ref: sdk-2.12.x_nnbd - path: packages/model + angel3_container: ^3.0.0 + angel3_model: ^3.0.0 # logging: ^0.11.0 pedantic: ^1.11.0 - test: ^1.17.3 -#dependency_overrides: -# angel_framework: -# path: ../framework + test: ^1.17.4 \ No newline at end of file diff --git a/packages/websocket/test/auth_test.dart b/packages/websocket/test/auth_test.dart index 87d3d8f4..79e05dd7 100644 --- a/packages/websocket/test/auth_test.dart +++ b/packages/websocket/test/auth_test.dart @@ -1,9 +1,9 @@ -import 'package:angel_auth/angel_auth.dart'; -import 'package:angel_client/io.dart' as c; -import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_framework/http.dart'; -import 'package:angel_websocket/io.dart' as c; -import 'package:angel_websocket/server.dart'; +import 'package:angel3_auth/angel3_auth.dart'; +import 'package:angel3_client/io.dart' as c; +import 'package:angel3_framework/angel3_framework.dart'; +import 'package:angel3_framework/http.dart'; +import 'package:angel3_websocket/io.dart' as c; +import 'package:angel3_websocket/server.dart'; import 'package:logging/logging.dart'; import 'package:test/test.dart'; diff --git a/packages/websocket/test/controller/common.dart b/packages/websocket/test/controller/common.dart index eeb29bcb..df0c0cb1 100644 --- a/packages/websocket/test/controller/common.dart +++ b/packages/websocket/test/controller/common.dart @@ -1,5 +1,5 @@ -import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_websocket/server.dart'; +import 'package:angel3_framework/angel3_framework.dart'; +import 'package:angel3_websocket/server.dart'; class Game { final String? playerOne, playerTwo; diff --git a/packages/websocket/test/controller/io_test.dart b/packages/websocket/test/controller/io_test.dart index 7311c975..4e2bc784 100644 --- a/packages/websocket/test/controller/io_test.dart +++ b/packages/websocket/test/controller/io_test.dart @@ -1,9 +1,9 @@ import 'dart:io'; -import 'package:angel_container/mirrors.dart'; -import 'package:angel_framework/angel_framework.dart' as srv; -import 'package:angel_framework/http.dart' as srv; -import 'package:angel_websocket/io.dart' as ws; -import 'package:angel_websocket/server.dart' as srv; +import 'package:angel3_container/mirrors.dart'; +import 'package:angel3_framework/angel3_framework.dart' as srv; +import 'package:angel3_framework/http.dart' as srv; +import 'package:angel3_websocket/io.dart' as ws; +import 'package:angel3_websocket/server.dart' as srv; import 'package:logging/logging.dart'; import 'package:test/test.dart'; import 'common.dart'; diff --git a/packages/websocket/test/service/common.dart b/packages/websocket/test/service/common.dart index 5dc5bfa3..99d92dc2 100644 --- a/packages/websocket/test/service/common.dart +++ b/packages/websocket/test/service/common.dart @@ -1,9 +1,9 @@ import 'dart:async'; -import 'package:angel_framework/angel_framework.dart'; -import 'package:angel_model/angel_model.dart'; -import 'package:angel_websocket/base_websocket_client.dart'; -import 'package:angel_websocket/server.dart'; +import 'package:angel3_framework/angel3_framework.dart'; +import 'package:angel3_model/angel3_model.dart'; +import 'package:angel3_websocket/base_websocket_client.dart'; +import 'package:angel3_websocket/server.dart'; import 'package:test/test.dart'; class Todo extends Model { diff --git a/packages/websocket/test/service/io_test.dart b/packages/websocket/test/service/io_test.dart index 47fa950c..a449b160 100644 --- a/packages/websocket/test/service/io_test.dart +++ b/packages/websocket/test/service/io_test.dart @@ -1,9 +1,9 @@ import 'dart:io'; -import 'package:angel_container/mirrors.dart'; -import 'package:angel_framework/angel_framework.dart' as srv; -import 'package:angel_framework/http.dart' as srv; -import 'package:angel_websocket/io.dart' as ws; -import 'package:angel_websocket/server.dart' as srv; +import 'package:angel3_container/mirrors.dart'; +import 'package:angel3_framework/angel3_framework.dart' as srv; +import 'package:angel3_framework/http.dart' as srv; +import 'package:angel3_websocket/io.dart' as ws; +import 'package:angel3_websocket/server.dart' as srv; import 'package:logging/logging.dart'; import 'package:test/test.dart'; import 'common.dart'; diff --git a/packages/websocket/web/main.dart b/packages/websocket/web/main.dart index 2bb42277..8f1a9f17 100644 --- a/packages/websocket/web/main.dart +++ b/packages/websocket/web/main.dart @@ -1,5 +1,5 @@ import 'dart:html'; -import 'package:angel_websocket/browser.dart'; +import 'package:angel3_websocket/browser.dart'; /// Dummy app to ensure client works with DDC. void main() {