MesaJugando.kt 1.63 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
package com.example.tolucagraphics

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.gson.Gson
import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener

12
class MesaJugando : AppCompatActivity() {
13 14 15 16 17
    val single = Socket
    val gson = Gson()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_mesa_en_juego)
18 19
        //val intentJoin = intent.getStringExtra("join")
        //Log.d("TAG", "Join from Intent: $intentJoin")
20 21 22 23
        //single.listener = Listener2()
        single.conectarconWS()
    }
    fun mensajeRecibido(text : String){
24
        Log.d("TAG", text)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
    }
    inner class Listener2 : WebSocketListener(){
        @SuppressLint("SetTextI18n")
        override fun onMessage(webSocket: WebSocket, text: String) {
            super.onMessage(webSocket, text)
            runOnUiThread {
                Log.d("TAG", "Undefined text -> $text")
                /*if (text.contains(KeysWebSocket.commandResponse,true) && text.contains(KeysWebSocket.commandGetRooms)){
                }*/
                mensajeRecibido(text)
            }
        }

        override fun onOpen(webSocket: WebSocket, response: Response) {
            super.onOpen(webSocket, response)
            Log.d("TAG", "established connection! Table Game!!! <3")
        }

        override fun onClosing(webSocket: WebSocket, code: Int, reason: String) {
            super.onClosing(webSocket, code, reason)
            Log.d("TAG", "$code $reason")
        }
    }
}