|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'package:http/io_client.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
import 'package:mc_common_app/main.dart';
|
|
|
|
|
import 'package:signalr_core/signalr_core.dart';
|
|
|
|
|
|
|
|
|
|
abstract class ChatRepo {
|
|
|
|
|
Future<HubConnection> getHubConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ChatRepoImp implements ChatRepo {
|
|
|
|
|
@override
|
|
|
|
|
Future<HubConnection> getHubConnection() async {
|
|
|
|
|
final userId = AppState().getUser.data!.userInfo!.userId ?? "";
|
|
|
|
|
final hubUrl = "https://ms.hmg.com/McHub?userID=$userId";
|
|
|
|
|
logger.i("Connecting with Hub ($hubUrl)");
|
|
|
|
|
|
|
|
|
|
HubConnection hub;
|
|
|
|
|
hub = HubConnectionBuilder()
|
|
|
|
|
.withUrl(
|
|
|
|
|
hubUrl,
|
|
|
|
|
HttpConnectionOptions(
|
|
|
|
|
client: IOClient(HttpClient()
|
|
|
|
|
..badCertificateCallback = (x, y, z) => true),
|
|
|
|
|
logging: (level, message) {
|
|
|
|
|
print(message);
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.build();
|
|
|
|
|
return hub;
|
|
|
|
|
}
|
|
|
|
|
}
|