diff --git a/cmd/server/main.go b/cmd/server/main.go index a034499..7ad9a18 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -22,5 +22,9 @@ func main() { router.GET("/api/rooms", func(c *gin.Context) { c.JSON(200, gin.H{"rooms": "TODO"}) }) + router.Static("/static", "./static") + router.GET("/", func(c *gin.Context) { + c.File("./static/index.html") + }) router.Run(":8080") } diff --git a/project_context.txt b/project_context.txt index 50d4c7f..443baeb 100644 --- a/project_context.txt +++ b/project_context.txt @@ -23,6 +23,10 @@ func main() { router.GET("/api/rooms", func(c *gin.Context) { c.JSON(200, gin.H{"rooms": "TODO"}) }) + router.Static("/static", "./static") + router.GET("/", func(c *gin.Context) { + c.File("./static/index.html") + }) router.Run(":8080") } @@ -349,3 +353,93 @@ SQLite format 3@  ))=indexsqlite_autoindex_rooms_1rooms generalGeneral   general   +--- static/index.html --- + + + + Shagram Chat + + + +

📱 Shagram Chat

+ +
+ + +
+ +
+ +
+ + +
+ + + + + +--- static/js/chat.js --- +let ws = null; +const messagesDiv = document.getElementById('messages'); +const messageInput = document.getElementById('messageInput'); +const roomInput = document.getElementById('roomInput'); + +function connectRoom() { + const room = roomInput.value || 'general'; + const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; + ws = new WebSocket(`${protocol}//localhost:8080/ws/${room}`); + + ws.onopen = function() { + console.log('Connected to room: ' + room); + messagesDiv.innerHTML = '
✅ Connected to ' + room + '
'; + }; + + ws.onmessage = function(event) { + const msgDiv = document.createElement('div'); + msgDiv.className = 'message'; + msgDiv.textContent = event.data; + messagesDiv.appendChild(msgDiv); + messagesDiv.scrollTop = messagesDiv.scrollHeight; + }; + + ws.onerror = function(error) { + console.error('WebSocket error:', error); + messagesDiv.innerHTML += '
❌ Error: ' + error + '
'; + }; + + ws.onclose = function() { + messagesDiv.innerHTML += '
⛔ Disconnected
'; + }; +} + +function sendMessage() { + const text = messageInput.value.trim(); + if (!text || !ws || ws.readyState !== WebSocket.OPEN) { + alert('Not connected or empty message'); + return; + } + + ws.send(JSON.stringify({text: text})); + messageInput.value = ''; +} diff --git a/static/index.html b/static/index.html index 97921a1..5e58725 100644 --- a/static/index.html +++ b/static/index.html @@ -39,6 +39,6 @@ - +