authenticate method Null safety

Future<BaseResponse?> authenticate(
  1. AuthRequiredResponse requirements,
  2. String passwd
)

Returns a BaseResponse object, requirements are provided by the AuthRequiredResponse object and passwd is the password assigned in the OBS interface for websockets. If OBS returns an error in the response, then an Exception will be thrown.

Implementation

Future<BaseResponse?> authenticate(
    AuthRequiredResponse requirements, String passwd) async {
  final secret = _base64Hash(passwd + requirements.salt!);
  final auth_response = _base64Hash(secret + requirements.challenge!);

  BaseResponse? response;

  var messageId =
      sendCommand({'request-type': 'Authenticate', 'auth': auth_response});

  await for (String message in broadcast) {
    response = BaseResponse.fromJson(jsonDecode(message));

    if (!response.status) {
      throw Exception(
          'Server returned error to Authenticate request\n: ${response.error}');
    }

    if (response.messageId == messageId) {
      break;
    }
  }

  return response;
}