package com.jld.vod.socket;

import android.content.Context;
import android.text.TextUtils;

import com.jld.vod.interfaces.OnMessageReceiveListener;

import org.json.JSONException;
import org.json.JSONObject;

public class ReceiveSocketManager {

    private static volatile ReceiveSocketManager instance = null;
    private ReceiveUDPSocket receiveUdpSocket;
    private Context mContext;

    private ReceiveSocketManager(Context context) {
        mContext = context.getApplicationContext();
    }

    public static ReceiveSocketManager getInstance(Context context) {
        // if already inited, no need to get lock everytime
        if (instance == null) {
            synchronized (ReceiveSocketManager.class) {
                if (instance == null) {
                    instance = new ReceiveSocketManager(context);
                }
            }
        }

        return instance;
    }

    /**
     * 开启UPD接收连接
     */
    public void startUdpConnection() {
        if (receiveUdpSocket == null) {
            receiveUdpSocket = new ReceiveUDPSocket(mContext);
        }
        receiveUdpSocket.startUDPSocket();
    }
    /**
     * 处理 udp 收到的消息
     *
     * @param message
     */
    private void handleUdpMessage(String message) {

    }
    public void stopSocket() {
        if (receiveUdpSocket != null) {
            receiveUdpSocket.stopUDPSocket();
            receiveUdpSocket = null;
        }
    }

}
