Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure websockets work by fixing casting issue #25

Merged
merged 5 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/nitric.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ library;

export 'src/nitric.dart';
export 'src/context/common.dart';
export 'src/resources/common.dart';
11 changes: 8 additions & 3 deletions lib/src/resources/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ class Websocket extends Resource {
_websocketClient = websocketClient;
}

_websocketHandlerClient = websocketHandlerClient;
if (websocketHandlerClient == null) {
_websocketHandlerClient = $wp.WebsocketHandlerClient(
ClientChannelSingleton.instance.clientChannel);
} else {
_websocketHandlerClient = websocketHandlerClient;
}
}

@override
Expand All @@ -30,14 +35,14 @@ class Websocket extends Resource {
}

/// Send message [data] to a connection, referenced by its [connectionId].
Future<void> sendMessage(String connectionId, String data) async {
Future<void> send(String connectionId, String data) async {
var req = $wp.WebsocketSendRequest(
socketName: name, connectionId: connectionId, data: utf8.encode(data));
await _websocketClient.sendMessage(req);
}

/// Close a connection to the socket, referenced by its [connectionId].
Future<void> closeConnection(String connectionId) async {
Future<void> close(String connectionId) async {
var req = $wp.WebsocketCloseConnectionRequest(
socketName: name, connectionId: connectionId);
await _websocketClient.closeConnection(req);
Expand Down
1 change: 0 additions & 1 deletion lib/src/workers/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:grpc/grpc.dart';

import 'package:nitric_sdk/nitric.dart';
import 'package:nitric_sdk/resources.dart';
import 'package:nitric_sdk/src/api/api.dart';
import 'package:nitric_sdk/src/grpc_helper.dart';

Expand Down
1 change: 0 additions & 1 deletion test/src/resources/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:mocktail/mocktail.dart';
import 'package:nitric_sdk/nitric.dart';
import 'package:nitric_sdk/src/nitric/proto/apis/v1/apis.pbgrpc.dart' as $p;
import 'package:nitric_sdk/src/nitric/proto/resources/v1/resources.pb.dart';
import 'package:nitric_sdk/src/resources/common.dart';
import 'package:test/test.dart';

import '../common.dart';
Expand Down
2 changes: 0 additions & 2 deletions test/src/resources/bucket_test.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:mocktail/mocktail.dart';
import 'package:nitric_sdk/nitric.dart';
import 'package:nitric_sdk/resources.dart';
import 'package:nitric_sdk/src/nitric/proto/resources/v1/resources.pb.dart'
as $p;
import 'package:nitric_sdk/src/nitric/proto/storage/v1/storage.pbgrpc.dart'
as $sp;
import 'package:nitric_sdk/src/resources/common.dart';
import 'package:test/test.dart';

import '../common.dart';
Expand Down
4 changes: 2 additions & 2 deletions test/src/resources/websocket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void main() {
var websocket = Websocket("socketName",
client: resourceClient, websocketClient: websocketClient);

await websocket.sendMessage("connectionId", "hello world");
await websocket.send("connectionId", "hello world");

verify(() => websocketClient.sendMessage(req)).called(1);
});
Expand All @@ -90,7 +90,7 @@ void main() {
var websocket = Websocket("socketName",
client: resourceClient, websocketClient: websocketClient);

await websocket.closeConnection("connectionId");
await websocket.close("connectionId");

verify(() => websocketClient.closeConnection(req)).called(1);
});
Expand Down
Loading