init static method

Future<WebSocketConnection> init({
  1. required String jwtToken,
  2. required String websocketServerURL,
})

Initializes a new WebSocketConnection instance and connects it to the server using the given jwtToken.

This method takes a JWT token as input, parses it to extract the necessary data, and uses it to create a new Client instance with the Centrifuge package. It then connects the client to the server and returns a new WebSocketConnection instance.

Implementation

static Future<WebSocketConnection> init({
  required String jwtToken,
  required String websocketServerURL,
}) async {
  final Map<String, dynamic> data = JwtParser.parseJwt(jwtToken);

  final Client client = createClient(
    websocketServerURL,
    ClientConfig(name: data['sub'], token: jwtToken),
  );

  await client.connect();
  await client.ready();
  _instance = WebSocketConnection(client);

  return _instance!;
}