Initial commit

This commit is contained in:
Trevor Slocum 2019-11-24 02:38:48 -08:00
commit 6fd94fc38c
15 changed files with 366 additions and 0 deletions

24
.builds/amd64_freebsd.yml Normal file
View File

@ -0,0 +1,24 @@
arch: amd64
environment:
PROJECT_DIR: '~/go/src/git.sr.ht/~tslocum'
PROJECT_NAME: 'harmony'
CGO_ENABLED: '0'
GO111MODULE: 'on'
image: freebsd/latest
packages:
- go
sources:
- https://git.sr.ht/~tslocum/harmony
tasks:
- setup: |
mkdir -p $PROJECT_DIR
mv $PROJECT_NAME $PROJECT_DIR/$PROJECT_NAME
- deps: |
cd $PROJECT_DIR/$PROJECT_NAME
go mod download
- test: |
cd $PROJECT_DIR/$PROJECT_NAME
go test
- build: |
cd $PROJECT_DIR/$PROJECT_NAME
go build

View File

@ -0,0 +1,24 @@
arch: x86_64
environment:
PROJECT_DIR: '~/go/src/git.sr.ht/~tslocum'
PROJECT_NAME: 'harmony'
CGO_ENABLED: '0'
GO111MODULE: 'on'
image: alpine/edge
packages:
- go
sources:
- https://git.sr.ht/~tslocum/harmony
tasks:
- setup: |
mkdir -p $PROJECT_DIR
mv $PROJECT_NAME $PROJECT_DIR/$PROJECT_NAME
- deps: |
cd $PROJECT_DIR/$PROJECT_NAME
go mod download
- test: |
cd $PROJECT_DIR/$PROJECT_NAME
go test
- build: |
cd $PROJECT_DIR/$PROJECT_NAME
go build

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
.idea/
dist/
*.sh
harmony
!cmd/harmony/
!pkg/harmony/
harmony-server
!cmd/harmony-server/
vendor/

2
CHANGELOG Normal file
View File

@ -0,0 +1,2 @@
0.1.0:
- Initial release

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Trevor Slocum <trevor@rocketnine.space>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14
README.md Normal file
View File

@ -0,0 +1,14 @@
# harmony
[![GoDoc](https://godoc.org/git.sr.ht/~tslocum/harmony?status.svg)](https://godoc.org/git.sr.ht/~tslocum/harmony)
[![builds.sr.ht status](https://builds.sr.ht/~tslocum/harmony.svg)](https://builds.sr.ht/~tslocum/harmony)
[![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space)
Voice and text communications platform
## Features
- WIP
## Support
Please share suggestions/issues [here](https://todo.sr.ht/~tslocum/harmony).

View File

@ -0,0 +1,16 @@
package main
import (
"log"
"git.sr.ht/~tslocum/harmony/pkg/web"
)
func main() {
log.Println("starting server")
w := web.NewWebInterface("localhost:8080")
_ = w
select {}
}

10
go.mod Normal file
View File

@ -0,0 +1,10 @@
module git.sr.ht/~tslocum/harmony
go 1.13
require (
github.com/GeertJohan/go.rice v1.0.0
github.com/daaku/go.zipexe v1.0.1 // indirect
github.com/gorilla/mux v1.7.3
github.com/gorilla/websocket v1.4.1
)

17
go.sum Normal file
View File

@ -0,0 +1,17 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0 h1:KkI6O9uMaQU3VEKaj01ulavtF7o1fWT7+pk/4voiMLQ=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/daaku/go.zipexe v1.0.0 h1:VSOgZtH418pH9L16hC/JrgSNJbbAL26pj7lmD1+CGdY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/daaku/go.zipexe v1.0.1 h1:wV4zMsDOI2SZ2m7Tdz1Ps96Zrx+TzaK15VbUaGozw0M=
github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=

33
goreleaser.yml Normal file
View File

@ -0,0 +1,33 @@
project_name: harmony
builds:
-
id: harmony-server
binary: harmony-server
main: ./cmd/harmony-server
ldflags:
- -s -w -X git.sr.ht/~tslocum/harmony/pkg/config.Version={{.Version}}
goos:
- darwin
- freebsd
- linux
- windows
goarch:
- 386
- amd64
archives:
-
id: harmony
builds:
- harmony-server
replacements:
386: i386
format_overrides:
- goos: windows
format: zip
files:
- ./*.md
- CHANGELOG
- LICENSE
checksum:
name_template: 'checksums.txt'

3
pkg/config/config.go Normal file
View File

@ -0,0 +1,3 @@
package config
var Version = "0.0.0"

View File

@ -0,0 +1,107 @@
var socket = null;
var ReconnectDelay = 0;
var reconnectTimeout;
var connected;
$(document).ready(function () {
$("#startButton").on("click", function () {
navigator.mediaDevices.getUserMedia({audio: true}).then(stream => {
let options = {mimeType: 'audio/ogg'};
recorder = new MediaRecorder(stream, options);
recorder.start(60);
recorder.addEventListener('dataavailable', (e) => {
if (!e.data || e.data.size <= 0) {
return;
}
socket.send(e.data);
});
});
});
$("#stopButton").on("click", function () {
recorder.stop();
});
Connect();
});
function Connect() {
reconnectTimeout = null;
if (webSocketReady() || ReconnectDelay === -1) {
alert('exit');
return;
}
var loc = window.location, wsurl, pathname;
if (loc.protocol === "https:") {
wsurl = "wss:";
} else {
wsurl = "ws:";
}
if (loc.pathname && loc.pathname !== "") {
pathname = loc.pathname;
} else {
pathname = "/";
}
wsurl += "//" + loc.host + pathname + "w";
socket = new WebSocket(wsurl);
socket.onerror = function (e) {
console.log(e);
};
socket.onopen = function (e) {
if (reconnectTimeout != null) {
clearTimeout(reconnectTimeout);
}
};
socket.onmessage = function (e) {
if (ReconnectDelay > 0) {
ReconnectDelay = 0;
}
var incomingmsg = e.data;
var nowconnected = false;
try {
//var data = jQuery.parseJSON(incomingmsg);
//if (data.hasOwnProperty("status") && data.status === "fail") {
console.log("Got " + incomingmsg);
} catch (e) {
console.log(e);
}
NoteCheckingItem = false;
};
socket.onclose = function (e) {
connected = false;
if (ReconnectDelay < 0 || reconnectTimeout != null) {
return;
}
var waitTime = ReconnectDelay;
console.log("Reconnecting in " + ReconnectDelay + " seconds...");
reconnectTimeout = setTimeout(Connect, waitTime * 1000);
ReconnectDelay += (ReconnectDelay * 2) + 1;
if (ReconnectDelay > 10) {
ReconnectDelay = 10;
}
};
}
function webSocketReady() {
return (socket !== null && socket.readyState === 1);
}
function waitForSocketConnection(socket, callback) {
setTimeout(function () {
if (webSocketReady()) {
if (callback != null) {
callback();
}
} else {
waitForSocketConnection(socket, callback);
}
}, 250);
}

2
pkg/web/public/assets/js/jquery.js vendored Normal file

File diff suppressed because one or more lines are too long

12
pkg/web/public/index.html Normal file
View File

@ -0,0 +1,12 @@
<html>
<head>
<title>harmony</title>
<script src="assets/js/jquery.js"></script>
<script src="assets/js/harmony.js"></script>
</head>
<body>
<button id="startButton">Start</button><br><br>
<button id="stopButton">Stop</button><br><br>
<audio id="player" controls></audio>
</body>
</html>

72
pkg/web/web.go Normal file
View File

@ -0,0 +1,72 @@
package web
import (
"log"
"net/http"
rice "github.com/GeertJohan/go.rice"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
EnableCompression: true,
}
type WebInterface struct {
}
func NewWebInterface(address string) *WebInterface {
w := WebInterface{}
r := mux.NewRouter()
r.HandleFunc("/w", webSocketHandler)
r.PathPrefix("/").Handler(http.FileServer(rice.MustFindBox("public").HTTPBox()))
go func() {
if err := http.ListenAndServe(address, r); err != nil {
log.Fatal("Web server error: ", err)
}
}()
return &w
}
func webSocketHandler(w http.ResponseWriter, r *http.Request) {
log.Println("new WS")
conn, err := upgrader.Upgrade(w, r, nil)
if err != nil {
return
}
vars := mux.Vars(r)
err = conn.WriteMessage(websocket.TextMessage, []byte("Test server write"))
if err != nil {
conn.Close()
return
}
_ = vars
var (
messageType int
message []byte
)
for {
messageType, message, err = conn.ReadMessage()
if err != nil {
conn.Close()
return
}
log.Printf("received %d %d", messageType, len(message))
_ = messageType
}
}