Skip to content

Commit

Permalink
Refactor ProtobufReplyDecoder to handle different reply types
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed May 10, 2024
1 parent f31f0f1 commit 2044c8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/src/protobuf/protobuf_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,8 @@ final class ProtobufReplyDecoder extends Converter<List<int>, SpinifyReply> {
//}
if (reply.hasPush()) {
return _decodePush(reply.push);
} else if (reply.hasPing()) {
return SpinifyPingResult(
id: reply.id,
timestamp: DateTime.now(),
);
} else if (reply.hasId() && reply.id > 0) {
return _decodeReply(reply);
} else if (reply.hasError()) {
final error = reply.error;
return SpinifyError(
Expand All @@ -148,9 +145,8 @@ final class ProtobufReplyDecoder extends Converter<List<int>, SpinifyReply> {
message: error.message,
temporary: error.temporary,
);
} else if (reply.hasId() && reply.id > 0) {
return _decodeReply(reply);
} else {
// TODO(plugfox): Implement ping reply
throw UnimplementedError('Unsupported reply type');
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/smoke/smoke_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,17 @@ void main() {
await client.close();
expect(client.state, isA<SpinifyState$Closed>());
});

test('Connect_and_refresh', () async {
final client = Spinify();
await client.connect(url);
expect(client.state, isA<SpinifyState$Connected>());
//await client.ping();
await Future<void>.delayed(const Duration(seconds: 360));
await client.disconnect();
expect(client.state, isA<SpinifyState$Disconnected>());
await client.close();
expect(client.state, isA<SpinifyState$Closed>());
});
});
}

0 comments on commit 2044c8b

Please sign in to comment.