willSendVideo method

void willSendVideo(
  1. int status, {
  2. int? newTime,
})

Implementation

void willSendVideo(int status, {int? newTime}) async {
  try {
    printLog('willSendVideo: $status');
    if (widget.delegate?.onWillCheckSendVideo() == false) {
      leaveChannel();
      return;
    }
    if (status == 0) {
      if (callStatus < 0 && call) {
        return;
      }
      var message = CallEntity();
      message.callId = callId;
      message.userName = widget.name;
      message.userImage = widget.portraitUri;
      message.callPackage = Address.packageName;
      message.callType = type;
      if (type == 1) {
        message.callMatch = true;
        message.matchCostUserId = widget.matchEntity!.matchCostUserId;
        message.callCostUserId = widget.matchEntity!.callCostUserId;
        message.callCost = widget.matchEntity!.callCost;
        message.matchTime = widget.matchEntity!.matchTime;
      } else if (type == 2) {
        message.toyCost = widget.toyCost;
      }
      await widget.rtmClient.sendLocalInvitation({
        'calleeId': widget.userId,
        'channelId': channelId,
        'content': jsonEncode(message.toJson())
      });
      isSendConnect = true;
    } else if (status == 1 && (isConnect ?? false) == false) {
      if (callStatus < 0 && call) {
        return;
      }
      if (call) {
        var message = CallEntity();
        message.callId = callId;
        message.userName = widget.name;
        message.userImage = widget.portraitUri;
        message.callPackage = Address.packageName;
        await widget.rtmClient.cancelLocalInvitation({
          'calleeId': widget.userId,
          'channelId': channelId,
          'content': jsonEncode(message.toJson())
        });
      } else {
        await widget.rtmClient
            .refuseRemoteInvitation({'callerId': widget.userId});
      }
    } else {
      if (status == 1 && callStatus == 1) {
        return;
      }
      VideoMessage videoMsg = VideoMessage();
      videoMsg.userId = '${widget.meUid}';
      videoMsg.status = status;
      videoMsg.newTime = newTime;
      AgoraRtmMessage message =
          AgoraRtmMessage.fromText(jsonEncode(videoMsg.toJson()));
      await widget.rtmClient.sendMessageToPeer(widget.userId, message, true);
    }
  } catch (e) {
    printLog(e);
  }
}