Skip to content

Commit

Permalink
fix: ensure websockets work by fixing casting issue (#25)
Browse files Browse the repository at this point in the history
* fix: export common resources

Ensures permissions are included when importing nitric

* fix: rename sendMessage to send for websockets

* fix: rename closeConnection to close

* fix: ensure websocker handler client is defined

* fix imports
  • Loading branch information
davemooreuws authored Apr 25, 2024
1 parent 126e47d commit 790ca49
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
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

0 comments on commit 790ca49

Please sign in to comment.