package com.sd.cavphmi.websockets

import org.java_websocket.client.WebSocketClient
import org.java_websocket.drafts.Draft
import org.java_websocket.handshake.ServerHandshake
import java.net.URI
import java.nio.ByteBuffer

/*****感知目标物**/
class FeelTargetWSClient : WebSocketClient {

    private val TAG = "-----FeelTargetWSClient"

    constructor(serverUri: URI) : super(serverUri)

    constructor(serverUri: URI?, protocolDraft: Draft?) : super(serverUri, protocolDraft)

    constructor(serverUri: URI?, httpHeaders: MutableMap<String, String>?) : super(
        serverUri,
        httpHeaders
    )

    override fun onOpen(handshakedata: ServerHandshake?) {
        println(TAG + "------------Hello, 感知目标物")
//        System.out.println(TAG + "new connection opened")
    }

    override fun onMessage(message: String?) {
        println(TAG + " : " + message)
        if (message.isNullOrEmpty())
            return
        onDataCb?.onMsg(message)
//        onSocketCb?.onMessage(message)

    }

    override fun onMessage(bytes: ByteBuffer?) {
        System.out.println(TAG + "  received ByteBuffer")

    }

    override fun onClose(code: Int, reason: String?, remote: Boolean) {
        System.out.println(TAG + "  closed with exit code " + code + " additional info: " + reason);

    }

    override fun onError(ex: Exception?) {
        System.err.println(TAG + "an error occurred:" + ex)

    }

    var onDataCb: OnDataCb? = null

    interface OnDataCb {
        fun onMsg(str: String)
    }


}