Skip to content

Commit

Permalink
Create websocket.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Seven Du committed Sep 25, 2023
1 parent 1465c47 commit 59929e3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/spry/lib/websocket.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library spry.websocket;

import 'dart:io';

import 'spry.dart';

class WebSocketHandler {
Future<void> call(Context context) async {
final HttpRequest request = context[HttpRequest];

if (!WebSocketTransformer.isUpgradeRequest(request)) {
throw Exception('Not a WebSocket upgrade request');
}

final websocket = await WebSocketTransformer.upgrade(request);
websocket.listen((event) {
print(event);
});

await websocket.done;
}
}

final handler = WebSocketHandler();
final spry = Spry();

void main() async {
await spry.listen(handler, port: 3030);
}

1 comment on commit 59929e3

@vercel
Copy link

@vercel vercel bot commented on 59929e3 Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.