Publish websocket
This commit is contained in:
parent
b1d580fdd2
commit
e5acc33350
18 changed files with 85 additions and 114 deletions
|
@ -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();
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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<Data> {
|
|
@ -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'(^/)|(/+$)');
|
||||
|
|
|
@ -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'(^/)|(/+$)');
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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].
|
||||
///
|
||||
|
|
|
@ -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'(^/)|(/+$)');
|
||||
|
||||
|
|
|
@ -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<AuthToken>(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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
part of angel_websocket.server;
|
||||
part of angel3_websocket.server;
|
||||
|
||||
/// Marks a method as available to WebSockets.
|
||||
class ExposeWs {
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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';
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue