package client

import (
	"log"
	"strings"
)

func (client *Client) handleIncoming(done chan struct{}) {
	defer close(done)
	for {
		_, message, err := client.conn.ReadMessage()
		if err != nil {
			log.Println("ERROR: read message - :", err)
			return
		}
		// Ignore printing keep alives
		if string(message) == "keep alive - staying alive" {
			continue
		}
		log.Printf("recv: %s", message)
		inputs := strings.Split(string(message), ";")
		if inputs[0] == "task" {
			client.task(inputs)
		}
	}
}
