Untitled

mail@pastecode.io avatar
unknown
java
a month ago
1.4 kB
37
Indexable
Never
    @UniJSMethod(uiThread = true)
    public void connect() {
        // debug toast
        if (mWXSDKInstance != null && mWXSDKInstance.getContext() instanceof Activity) {
            Toast.makeText(mWXSDKInstance.getContext(), "execute connect before", Toast.LENGTH_SHORT).show();
        }
        // 连接 wireguard
        Tunnel tunnel = new WgTunnel();
        Context context = (Activity) mUniSDKInstance.getContext();
        Interface.Builder interfaceBuilder = new Interface.Builder();
        Peer.Builder peerBuilder = new Peer.Builder();
        Backend backend = new GoBackend(context);
        AsyncTask.execute(() -> {
            try {
                backend.setState(tunnel, UP, new Config.Builder()
                        .setInterface(interfaceBuilder.addAddress(InetNetwork.parse("10.0.0.1/32")).parsePrivateKey("xxx").build())
                        .addPeer(peerBuilder.addAllowedIp(InetNetwork.parse("10.0.0.0/24")).setEndpoint(InetEndpoint.parse("xxx:51820")).parsePublicKey("xxx").build())
                        .build());

            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        // debug toast
        if (mWXSDKInstance != null && mWXSDKInstance.getContext() instanceof Activity) {
            Toast.makeText(mWXSDKInstance.getContext(), "execute connect after", Toast.LENGTH_SHORT).show();
        }
    }
Leave a Comment