From 3e2bdbd964f44ca5a0a2c47af89125efdb8d5e3c Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Fri, 13 Dec 2019 08:44:40 -0800 Subject: [PATCH] Resolve static asset embedding issue --- .gitignore | 1 + CHANGELOG | 3 ++ goreleaser.yml | 4 ++ pkg/web/assets.go | 4 +- pkg/web/assets_embed.go | 7 --- pkg/web/channel.go | 14 ++++++ pkg/web/public/assets/css/harmony.css | 65 +++++++++++++++++++++------ pkg/web/public/assets/js/harmony.js | 29 ++++++++---- pkg/web/public/index.html | 48 +++++++++----------- pkg/web/web.go | 32 +++++++++++-- 10 files changed, 147 insertions(+), 60 deletions(-) delete mode 100644 pkg/web/assets_embed.go create mode 100644 pkg/web/channel.go diff --git a/.gitignore b/.gitignore index 04e5e3f..9e82d55 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ harmony !pkg/harmony/ harmony-server !cmd/harmony-server/ +pkg/web/assets_embed.go vendor/ diff --git a/CHANGELOG b/CHANGELOG index 8da6a6f..7d2b7e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,5 @@ +0.1.1: +- Fix static asset embedding issue + 0.1.0: - Initial release diff --git a/goreleaser.yml b/goreleaser.yml index 81b4ea7..b041960 100644 --- a/goreleaser.yml +++ b/goreleaser.yml @@ -3,6 +3,10 @@ project_name: harmony env: - GO111MODULE=on - CGO_ENABLED=1 +before: + hooks: + - go get github.com/omeid/go-resources/cmd/resources + - resources -output=./pkg/web/assets_embed.go -tag=embed -package=web -var=assets -trim=pkg/web/public/ pkg/web/public/* pkg/web/public/assets/* pkg/web/public/assets/css/* pkg/web/public/assets/js/* builds: - id: harmony-server diff --git a/pkg/web/assets.go b/pkg/web/assets.go index e8ece92..9d07ef9 100644 --- a/pkg/web/assets.go +++ b/pkg/web/assets.go @@ -4,4 +4,6 @@ package web import "github.com/omeid/go-resources/live" -var assets = live.Dir("./public") +func init() { + assets = live.Dir("./public") +} diff --git a/pkg/web/assets_embed.go b/pkg/web/assets_embed.go deleted file mode 100644 index 28b0e88..0000000 --- a/pkg/web/assets_embed.go +++ /dev/null @@ -1,7 +0,0 @@ -// +build embed - -package web - -import "net/http" - -var assets http.FileSystem diff --git a/pkg/web/channel.go b/pkg/web/channel.go new file mode 100644 index 0000000..6514092 --- /dev/null +++ b/pkg/web/channel.go @@ -0,0 +1,14 @@ +package web + +type Channel struct { + ID int + Name string + Topic string + Clients map[int]*Client +} + +func NewChannel(id int, name string, topic string) *Channel { + c := Channel{ID: id, Name: name, Topic: topic, Clients: make(map[int]*Client)} + + return &c +} diff --git a/pkg/web/public/assets/css/harmony.css b/pkg/web/public/assets/css/harmony.css index 7cd1678..e85b2a9 100644 --- a/pkg/web/public/assets/css/harmony.css +++ b/pkg/web/public/assets/css/harmony.css @@ -1,5 +1,6 @@ * { box-sizing: border-box; + font-family: Helvetica, arial, sans-serif; } html, body { @@ -24,6 +25,8 @@ nav ul, aside ul { overflow-x: auto; overflow-y: scroll; + + border-bottom: 1px solid #cecece; } .sideright { @@ -31,10 +34,16 @@ nav ul, aside ul { overflow-x: auto; overflow-y: scroll; + + border-bottom: 1px solid #cecece; } .status { grid-area: status; + + overflow-x: auto; + overflow-y: scroll; + border-bottom: 1px solid #cecece; } .footer { @@ -44,20 +53,23 @@ nav ul, aside ul { .wrapper { margin: 0; width: 100vw; - height: 100vh; + min-height: 100vh; display: grid; grid-gap: 0; - grid-template-areas: "sideleft" "sideright" "content" "status" "footer"; + grid-template-columns: 1fr; + grid-template-rows: min-content min-content min-content 1fr min-content min-content; + grid-template-areas: "sideleft" "sideright" "header" "content" "status" "footer"; - font: 1.2em Helvetica, arial, sans-serif; + font-size: 1.2em; } @media (min-width: 500px) { .wrapper { + height: 100vh; grid-template-columns: 1fr 4fr; - grid-template-rows: 1fr 1fr min-content min-content; - grid-template-areas: "sideleft content" "sideright content" "status content" "footer footer"; + grid-template-rows: min-content 1fr 1fr min-content min-content; + grid-template-areas: "sideleft header" "sideleft content" "sideright content" "status content" "footer footer"; } #voiceptt { @@ -71,9 +83,10 @@ nav ul, aside ul { @media (min-width: 750px) { .wrapper { + height: 100vh; grid-template-columns: 1fr 5fr 1fr; - grid-template-rows: 1fr min-content min-content; - grid-template-areas: "sideleft content sideright" "status content sideright" "footer footer footer" + grid-template-rows: min-content 1fr min-content min-content; + grid-template-areas: "sideleft header sideright" "sideleft content sideright" "status content sideright" "footer footer footer" } #voiceptt { @@ -85,10 +98,17 @@ nav ul, aside ul { } } -.sideleft, .sideright, .status, .content, .footer { +.sideleft, .sideright, .status, .content { padding: 7px; } +.header { + padding: 10px; + + overflow-x: auto; + overflow-y: scroll; +} + .content { padding-left: 10px; padding-right: 10px; @@ -99,10 +119,22 @@ button { padding: 7px; } -button, #chathistory, #chatinput { +#mainheader { + font-size: 1.5em; +} + +button, #subheader, #chathistory, #chatinput, .status { font-size: 1.25em; } +#header, #status { + vertical-align: center; +} + +.header { + border-right: 1px solid #cecece; +} + .headericon { display: inline-block; width: 25px; @@ -116,21 +148,26 @@ button, #chathistory, #chatinput { overflow-x: auto; overflow-y: scroll; - font-family: monospace; + min-height: 150px; + + border: 1px solid #cecece; } #chatinput { - width: 100%; + display:block; height: 100%; border: 0; resize: none; } +#voicepttcontainer { + border-top: 1px solid #cecece; +} + #voiceptt { width: 100%; height: 125px; - margin-top: 7px; - margin-bottom: 14px; + border: 0; } .voiceinactive { @@ -142,4 +179,4 @@ button, #chathistory, #chatinput { display: inline-block; width: 27px; padding-left: 4px; -} \ No newline at end of file +} diff --git a/pkg/web/public/assets/js/harmony.js b/pkg/web/public/assets/js/harmony.js index 6909b79..a3d7430 100644 --- a/pkg/web/public/assets/js/harmony.js +++ b/pkg/web/public/assets/js/harmony.js @@ -14,9 +14,13 @@ var numConnections = 3; var peerConnections = []; var RTCConstraints = { audio: { + channelCount: {exact: 2}, autoGainControl: false, echoCancellation: false, noiseSuppression: false, + sampleRate: 48000, + sampleSize: 16, + volume: 1.0 }, video: false }; @@ -51,10 +55,10 @@ var MessageTopic = 114; var MessageAction = 115; var MessageDisconnect = 119; var MessageChat = 120; -var MessageTypingStart = 121; -var MessageTypingStop = 122; +var MessageTypingStart = 121; +var MessageTypingStop = 122; var MessageTransmitStart = 123; -var MessageTransmitStop = 124; +var MessageTransmitStop = 124; var MessageUsers = 130; var tagsToReplace = { @@ -95,6 +99,8 @@ function HandleInput(e) { $(document).ready(function () { $("#togglevoice").on("click touchstart", function () { + $("#chatinput").focus(); + if (peerConnections.length > 0 || voice) { // Quit voice chat @@ -107,7 +113,6 @@ $(document).ready(function () { }); peerConnections = []; - $('#voicepttheader').css('display', 'none'); $('#voicepttcontainer').css('display', 'none'); updateStatus(); @@ -127,6 +132,8 @@ $(document).ready(function () { StartPTT(); + $("#chatinput").focus(); + return false; }); @@ -135,6 +142,8 @@ $(document).ready(function () { StartPTT(); + $("#chatinput").focus(); + return false; }); @@ -154,7 +163,7 @@ $(document).ready(function () { return false; }); - $("#inputheader, #voicepttheader").on("click touchstart", function (e) { + $("#chatinputcontainer,#voicepttcontainer").on("click touchstart", function (e) { $("#chatinput").focus(); return false; @@ -213,8 +222,7 @@ function createPeerConnection(id) { Log("Note: Push-to-talk is bound to <F8>"); } - $('#voicepttheader').css('display', 'table-row'); - $('#voicepttcontainer').css('display', 'table-row'); + $('#voicepttcontainer').css('display', 'block'); updateStatus(); }; @@ -275,6 +283,7 @@ function Connect() { return; } + userPing = 0; userListStatus = 'Connecting...'; updateStatus(); @@ -359,7 +368,7 @@ function Connect() { } Log(escapeEntities(p.N) + " disconnected"); - } else if (p.T == MessageNick) { + } else if (p.T == MessageNick) { if (p.N === undefined) { return; } @@ -459,6 +468,10 @@ function waitForSocketConnection(socket, callback) { } function Log(msg) { + if (msg.charAt(0) != '<' && msg.charAt(0) != '&' && msg.charAt(1) != '&' && msg.charAt(2) != 't' && msg.charAt(3) != ';') { + msg = '* ' + msg; + } + var date = new Date(); $('#chathistory').append(chatprefix + date.getHours() + ":" + (date.getMinutes() < 10 ? "0" : "") + date.getMinutes() + " " + msg + "\n") $('#chathistory').scrollTop($('#chathistory').prop("scrollHeight")); diff --git a/pkg/web/public/index.html b/pkg/web/public/index.html index 1b5ff46..0310143 100644 --- a/pkg/web/public/index.html +++ b/pkg/web/public/index.html @@ -11,12 +11,18 @@