Skip to content

Commit

Permalink
Merge pull request #40 from kindlyops/windows-named-pipes-player
Browse files Browse the repository at this point in the history
  • Loading branch information
statik committed Jan 27, 2022
2 parents 5bcbfaf + 731ef5b commit 2b69a00
Show file tree
Hide file tree
Showing 32 changed files with 2,950 additions and 224 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package(default_visibility = ["//visibility:public"])

# gazelle:prefix github.com/kindlyops/vbs
# gazelle:exclude dummy.go
# gazelle:resolve go github.com/kindlyops/vbs/embeddy //embeddy:go_default_library
gazelle(
name = "gazelle",
external = "vendored",
Expand Down
12 changes: 9 additions & 3 deletions cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,29 @@ go_library(
"ivs.go",
"lighting.go",
"play.go",
"play_unix.go",
"play_windows.go",
"root.go",
],
importpath = "github.com/kindlyops/vbs/cmd",
visibility = ["//visibility:public"],
deps = [
"//embeddy:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/aws/session:go_default_library",
"//vendor/github.com/aws/aws-sdk-go/service/ivs:go_default_library",
"//vendor/github.com/charmbracelet/bubbletea:go_default_library",
"//vendor/github.com/hypebeast/go-osc/osc:go_default_library",
"//vendor/github.com/kennygrant/sanitize:go_default_library",
"//vendor/github.com/mattn/go-isatty:go_default_library",
"//vendor/github.com/mitchellh/go-homedir:go_default_library",
"//vendor/github.com/rs/zerolog:go_default_library",
"//vendor/github.com/rs/zerolog/log:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/github.com/spf13/viper:go_default_library",
"//embeddy:go_default_library",
],
] + select({
"@io_bazel_rules_go//go/platform:windows": [
"//vendor/github.com/Microsoft/go-winio:go_default_library",
],
"//conditions:default": [],
}),
)
3 changes: 1 addition & 2 deletions cmd/lighting.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ package cmd

import (
"io/fs"
"net/http"
"strings"

"github.com/hypebeast/go-osc/osc"
"github.com/kindlyops/vbs/embeddy"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"net/http"
)

var lightingBridgeCmd = &cobra.Command{
Expand Down
21 changes: 7 additions & 14 deletions cmd/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cmd
import (
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -189,26 +188,20 @@ func play(cmd *cobra.Command, args []string) {

m := initialModel(target)

f, err := ioutil.TempFile("", "vbs-player")
if err != nil {
log.Fatal().Err(err).Msg("Could not create temp file")
}

socketName := f.Name()

os.Remove(socketName)
defer os.Remove(socketName)
ipcName := GetIPCName()
defer os.Remove(ipcName)

m.debug = socketName
m.debug = ipcName

go runMpvPlayer(m.outputScreen, socketName, m.currentItem)
go runMpvPlayer(m.outputScreen, ipcName, m.currentItem)

time.Sleep(1 * time.Second)

c, err := net.Dial("unix", socketName)
c, err := ConnectIPC(ipcName)
m.controlSocket = c

// TODO: set up an event loop and turn them into messages
// TODO: set up an event loop and turn them into messages so we can handle
// events like a file ending
// go responseEventReader(m.controlSocket)

if err != nil {
Expand Down
44 changes: 44 additions & 0 deletions cmd/play_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright © 2018 Kindly Ops, LLC <support@kindlyops.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !windows
// +build !windows

package cmd

import (
"io/ioutil"
"net"
"os"

"github.com/rs/zerolog/log"
)

func GetIPCName() string {
f, err := ioutil.TempFile("", "vbs-player")
if err != nil {
log.Fatal().Err(err).Msg("Could not create temp file")
}

socketName := f.Name()
os.Remove(socketName)

return socketName
}

func ConnectIPC(socketName string) (net.Conn, error) {
c, err := net.Dial("unix", socketName)

return c, err
}
45 changes: 45 additions & 0 deletions cmd/play_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright © 2018 Kindly Ops, LLC <support@kindlyops.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build windows
// +build windows

package cmd

import (
"fmt"
"io/ioutil"
"net"

"github.com/Microsoft/go-winio"
"github.com/rs/zerolog/log"
)

func GetIPCName() string {
f, err := ioutil.TempFile("", "vbs-player")
if err != nil {
log.Fatal().Err(err).Msg("Could not create temp file")
}

socketName := f.Name()
pipeName := fmt.Sprintf(`\\.\pipe\%s`, socketName)

return pipeName
}

func ConnectIPC(socketName string) (net.Conn, error) {
c, err := winio.DialPipe(socketName, nil)

return c, err
}
7 changes: 3 additions & 4 deletions embeddy/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ next(
name = "next_build",
outs = [".next"],
args = ["build $(RULEDIR)"],
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
data = [":copy_source_files"], # + NPM_DEPENDENCIES,
tags = ["no-sandbox"],
)

Expand All @@ -41,20 +41,19 @@ next(
"-o $(@)",
],
data = [":next_build"],
visibility = ["//visibility:public"]
visibility = ["//visibility:public"],
)

static_site_embedder(
name = "embedder",
srcs = [":dist"],
)

# keep
go_library(
name = "go_default_library",
srcs = [":embedder"],
embedsrcs = [":build"],
importpath = "github.com/kindlyops/vbs/embeddy",
visibility = ["//visibility:public"],
)


7 changes: 7 additions & 0 deletions embeddy/dummy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build neverbuild
// +build neverbuild

package embeddy

func main() {
}
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ require (
github.com/hypebeast/go-osc v0.0.0-20200115085105-85fee7fed692
github.com/kennygrant/sanitize v1.2.4
github.com/mattn/go-isatty v0.0.13
github.com/mitchellh/go-homedir v1.1.0
github.com/rs/zerolog v1.22.0
github.com/spf13/cobra v0.0.7
github.com/spf13/viper v1.7.0
)

require github.com/charmbracelet/bubbletea v0.19.3
require (
github.com/Microsoft/go-winio v0.5.1
github.com/charmbracelet/bubbletea v0.19.3
)

require (
github.com/containerd/console v1.0.2 // indirect
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Microsoft/go-winio v0.5.1 h1:aPJp2QD7OOrhO5tQXqQoGSJc+DjDtWTGLOmNyAm6FgY=
github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand Down Expand Up @@ -146,7 +148,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
Expand Down Expand Up @@ -196,6 +197,7 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
Expand Down Expand Up @@ -300,6 +302,7 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions vendor/github.com/Microsoft/go-winio/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/Microsoft/go-winio/CODEOWNERS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions vendor/github.com/Microsoft/go-winio/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2b69a00

Please sign in to comment.