package com.rnwalletman;

import android.util.Log;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;
import org.json.JSONObject;

public class TcpProxyModule extends ReactContextBaseJavaModule {
    private static final String TAG = "TcpProxyModule";

    public TcpProxyModule(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    @Override
    public String getName() {
        return "TcpProxyModule";
    }

    @ReactMethod
    public void startProxy(String wsUrl, String host, int port, String messageId, Promise promise) {
        try {
            Log.d(TAG, "启动代理: wsUrl=" + wsUrl + " host=" + host + " port=" + port);
            
            final TcpOverWebSocketClient client = new TcpOverWebSocketClient(wsUrl, host, port, messageId);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    client.start();
                }
            }).start();
            
            promise.resolve(true);
        } catch (Exception e) {
            Log.e(TAG, "启动代理失败", e);
            promise.reject("START_PROXY_ERROR", e.getMessage(), e);
        }
    }
}
