package com.ttstd.controlled.webrtc;

import android.util.Log;

import org.webrtc.SdpObserver;
import org.webrtc.SessionDescription;

public class AppSdpObserver implements SdpObserver {

    private static final String TAG = "AppSdpObserver";

    private final SdpEventListener listener;

    public interface SdpEventListener {
        void onCreateSuccess(SessionDescription sdp);
        void onSetSuccess();
        void onCreateFailure(String error);
        void onSetFailure(String error);
    }

    public AppSdpObserver(SdpEventListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreateSuccess(SessionDescription sdp) {
        Log.d(TAG, "SDP created: " + sdp.type);
        if (listener != null) listener.onCreateSuccess(sdp);
    }

    @Override
    public void onSetSuccess() {
        Log.d(TAG, "SDP set success");
        if (listener != null) listener.onSetSuccess();
    }

    @Override
    public void onCreateFailure(String error) {
        Log.e(TAG, "SDP create failure: " + error);
        if (listener != null) listener.onCreateFailure(error);
    }

    @Override
    public void onSetFailure(String error) {
        Log.e(TAG, "SDP set failure: " + error);
        if (listener != null) listener.onSetFailure(error);
    }
}
