<commit_before>package api

import (
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
	"github.com/jkomoros/boardgame"
	"log"
	"strconv"
	"time"
)

const (
	maxMessageSize = 512
	writeWait      = 10 * time.Second
	pongWait       = 60 * time.Second
	pingPeriod     = (pongWait * 9) / 10
)

const debugSockets = true

type gameVersionChanged struct {
	Id      string
	Version int
}

type versionNotifier struct {
	sockets       map[string]map[*socket]bool
	register      chan *socket
	unregister    chan *socket
	notifyVersion chan gameVersionChanged
	doneChan      chan bool
}

type socket struct {
	gameId   string
	notifier *versionNotifier
	conn     *websocket.Conn
	send     chan []byte
}

var upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
}

func (s *Server) socketHandler(c *gin.Context) {
	game := s.getGame(c)

	renderer := NewRenderer(c)

	if game == nil {
		renderer.Error("No such game")
		return
	}

	conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)

	if err != nil {
		renderer.Error("Couldn't upgrade socket: " + err.Error())
		return
	}
<commit_msg>Allow all origins for websockets to get it working. Left a TODO to check origin. Part of #401.<commit_after>package api

import (
	"github.com/gin-gonic/gin"
	"github.com/gorilla/websocket"
	"github.com/jkomoros/boardgame"
	"log"
	"net/http"
	"strconv"
	"time"
)

const (
	maxMessageSize = 512
	writeWait      = 10 * time.Second
	pongWait       = 60 * time.Second
	pingPeriod     = (pongWait * 9) / 10
)

const debugSockets = true

type gameVersionChanged struct {
	Id      string
	Version int
}

type versionNotifier struct {
	sockets       map[string]map[*socket]bool
	register      chan *socket
	unregister    chan *socket
	notifyVersion chan gameVersionChanged
	doneChan      chan bool
}

type socket struct {
	gameId   string
	notifier *versionNotifier
	conn     *websocket.Conn
	send     chan []byte
}

var upgrader = websocket.Upgrader{
	ReadBufferSize:  1024,
	WriteBufferSize: 1024,
	CheckOrigin: func(r *http.Request) bool {
		//TODO: lock this down to only allow origins
		return true
	},
}

func (s *Server) socketHandler(c *gin.Context) {

	game := s.getGame(c)

	renderer := NewRenderer(c)

	if game == nil {
		renderer.Error("No such game")
		return
	}

	conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)

	if err != nil {
		renderer.Error("Couldn't upgrade socket: " + err.Error())
		return
	}

{'fraction_non_alphanumeric': 0.10534979423868313, 'fraction_numerical': 0.016049382716049384, 'mean_word_length': 3.3723021582733814, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '628992', 'n_tokens_mistral': 923, 'n_tokens_neox': 851, 'n_words': 226}