summaryrefslogtreecommitdiffstats
path: root/lib/vehicle-signals/vehicle_config.dart
blob: 59682c4921fb7109d4424b9028d7b093163275fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: Apache-2.0
import 'dart:convert';
import 'dart:io';

import 'package:dashboard_app/config.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart' as http;



final sockConnectprovider = FutureProvider.family<WebSocket, HttpClient>(
    (ref, client) => connect(client,ref));



Future<HttpClient> initializeClient() async {


  SecurityContext ctx = SecurityContext.defaultContext;

  HttpClient client = HttpClient(context: ctx)
    ..findProxy = null
    ..badCertificateCallback = (cert, host, port) {
      return true;
    };
  return client;
}



Future<WebSocket> connect(HttpClient client, ref) async {
  final config = ref.read(ConfigStateprovider);
  WebSocket socket = await WebSocket.connect(
      "wss://${config.hostname}:${config.port}",
      customClient: client);
  return socket;
}