subscribe method

int subscribe(
  1. String uri,
  2. String contract,
  3. void onSuccess(
    1. String,
    2. int
    ),
  4. void onError(
    1. String,
    2. int
    ),
  5. void onNotification(
    1. String
    ),
  6. void onSubscriptionError(
    1. String,
    2. int
    ),
)

Implementation

int subscribe(
    String uri,
    String contract,
    void Function(String, int) onSuccess,
    void Function(String, int) onError,
    void Function(String) onNotification,
    void Function(String, int) onSubscriptionError) {
  _idCounter++;
  _subscriptionCounter++;
  _requestResultCbMap[_idCounter] = onSuccess;
  _requestErrorCbMap[_idCounter] = onError;
  _notifyCbMap[_subscriptionCounter] = onNotification;
  _subscriptionErrorCbMap[_subscriptionCounter] = onSubscriptionError;

  String mdsUri = uri;
  String mdsContract = contract;

  if (defaultTargetPlatform == TargetPlatform.android) {
    mdsUri = "suunto://MDS/EventListener";
    Map<String, dynamic> contractMap = jsonDecode(mdsContract);
    contractMap["Uri"] = uri;
    mdsContract = json.encode(contractMap);
  }

  _channel.invokeMethod('subscribe', <String, dynamic>{
    "uri": mdsUri,
    "contract": mdsContract,
    "requestId": _idCounter,
    "subscriptionId": _subscriptionCounter
  });
  return _subscriptionCounter;
}