package com.ez.ertc.meeting.presenter;

import android.os.Handler;

import com.ez.ertc.meeting.EnterRoomUtil;
import com.ez.ertc.meeting.EzmCallback;
import com.ez.ertc.meeting.constant.MtSets;
import com.ez.ertc.meeting.contract.JoinMeetingContract;

/**
 * @author xiezuoyuan
 * @time 2020/5/8 15:24
 */
public class JoinMeetingPresenter implements JoinMeetingContract.Presenter {

    private JoinMeetingContract.View mView;

    public JoinMeetingPresenter(JoinMeetingContract.View mView) {
        this.mView = mView;
        mView.setPresenter(this);
    }

    @Override
    public void onEnter() {
        EnterRoomUtil.enter(mView.getActivity(), mView.getRoomNo(), mView.getUserId(), mView.isAudioOn(), mView.isVideoOn(), new EzmCallback() {
            @Override
            public void onError(String code, String message) {
                mView.showToast("message：" + message + " code:" + code);
            }

            @Override
            public void onSuccess(Object data) {
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        mView.enter((String) data);
                    }
                });
            }
        });
    }

    @Override
    public void start() {
//        mView.switchAudio(MtSets.getJoinAudioState());
//        mView.switchVideo(MtSets.getJoinVideoState());
        mView.setRoomNo(MtSets.getSavedRoomId());
        mView.setUserId(MtSets.getSavedAccountId());
    }
}
