WIP ws messages, TODO backend receiving frontend messages
This commit is contained in:
@@ -57,7 +57,7 @@ JWTBody? jwtBody(Ref ref) {
|
||||
final payload = JwtDecoder.tryDecode(jwtString);
|
||||
if (payload == null) {
|
||||
logger.fine('Failed to decode JWT, removing key.');
|
||||
ref.read(jwtNotifierProvider.notifier).eraseJwt();
|
||||
Future.delayed(const Duration(), () => ref.read(jwtNotifierProvider.notifier).eraseJwt());
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
@@ -66,6 +66,7 @@ JWTBody? jwtBody(Ref ref) {
|
||||
} catch (e) {
|
||||
logger.shout(
|
||||
'Failed to parse JWT payload to JWTBody, something is wrong.\nPayload: $payload', e, StackTrace.current);
|
||||
Future.delayed(const Duration(), () => ref.read(jwtNotifierProvider.notifier).eraseJwt());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ Dio dio(Ref ref) {
|
||||
baseUrl: 'http://localhost:8080',
|
||||
connectTimeout: const Duration(seconds: 5),
|
||||
receiveTimeout: const Duration(seconds: 3),
|
||||
validateStatus: (status) => true,
|
||||
));
|
||||
|
||||
final jwt = ref.watch(jwtNotifierProvider).valueOrNull;
|
||||
|
||||
@@ -30,7 +30,7 @@ class GameMessageNotifier extends _$GameMessageNotifier {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
_logger.severe('Error parsing message: `${message.runtimeType}` $message', e, StackTrace.current);
|
||||
_logger.severe('Error parsing message: Type `${message.runtimeType}` $message', e, StackTrace.current);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:frontend/providers/auth.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
||||
import 'package:shared_models/room.dart';
|
||||
|
||||
part 'web_socket.g.dart';
|
||||
|
||||
@@ -41,18 +43,19 @@ class WebSocketNotifier extends _$WebSocketNotifier {
|
||||
_logger.warning('Error occurred creating web socket: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @riverpod
|
||||
// class WebSocketStreamNotifier extends _$WebSocketStreamNotifier {
|
||||
// @override
|
||||
// Stream<dynamic> build() {
|
||||
// final connection = ref.watch(webSocketNotifierProvider).valueOrNull;
|
||||
// if (connection == null) return Stream.empty();
|
||||
// _logger.finest('Created broadcast stream from ws connection');
|
||||
// return connection.asBroadcastStream();
|
||||
// }
|
||||
// }
|
||||
void sendMessage(GameRoomMessage message) {
|
||||
final msgStr = jsonEncode(message.toJson());
|
||||
final socket = state.valueOrNull;
|
||||
if (socket == null) {
|
||||
// TODO add queue
|
||||
_logger.info('Socket unavailable... adding to queue');
|
||||
throw UnimplementedError('No queue available');
|
||||
}
|
||||
_logger.finest('Sending message $message on websocket');
|
||||
socket.add(msgStr);
|
||||
}
|
||||
}
|
||||
|
||||
@riverpod
|
||||
Raw<Stream<dynamic>> webSocketStream(Ref ref) {
|
||||
|
||||
Reference in New Issue
Block a user