Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Tyler | 2baa15923a |
|
@ -8,13 +8,14 @@ import (
|
||||||
type SlobsClient struct {
|
type SlobsClient struct {
|
||||||
client *slobs.Client
|
client *slobs.Client
|
||||||
key string
|
key string
|
||||||
|
password string
|
||||||
recording bool
|
recording bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSlobsClient(key, host string, port int, password string) *SlobsClient {
|
func NewSlobsClient(key, host string, port int, password string) *SlobsClient {
|
||||||
slobsc := slobs.NewClient(host + ":" + strconv.Itoa(port))
|
slobsc := slobs.NewClient(host + ":" + strconv.Itoa(port))
|
||||||
|
|
||||||
return &SlobsClient{client: slobsc, key: key}
|
return &SlobsClient{client: slobsc, key: key, password: password}
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -31,6 +32,19 @@ func (c *SlobsClient) Connect() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.client.Auth(c.password, func(err error) {
|
||||||
|
if err != nil {
|
||||||
|
// TODO alert that it failed to startup?
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.requestInitialData()
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *SlobsClient) requestInitialData() {
|
||||||
c.client.SendRPC("StreamingService", "getModel", func(e *slobs.RPCResponse) {
|
c.client.SendRPC("StreamingService", "getModel", func(e *slobs.RPCResponse) {
|
||||||
state := &slobs.IStreamingState{}
|
state := &slobs.IStreamingState{}
|
||||||
|
|
||||||
|
@ -63,8 +77,6 @@ func (c *SlobsClient) Connect() error {
|
||||||
c.recording = false
|
c.recording = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SlobsClient) Disconnect() error {
|
func (c *SlobsClient) Disconnect() error {
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,11 +3,9 @@ module meow.tf/streamdeck/obs-replay
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
|
||||||
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
|
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9
|
||||||
github.com/gorilla/websocket v1.4.1
|
github.com/gorilla/websocket v1.4.1
|
||||||
github.com/mitchellh/mapstructure v1.1.2
|
github.com/mitchellh/mapstructure v1.1.2
|
||||||
github.com/mordillo123/sockjs-go-client v0.0.0-20161009150606-c1486c966a40
|
|
||||||
github.com/valyala/fastjson v1.4.1
|
github.com/valyala/fastjson v1.4.1
|
||||||
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d
|
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,13 +1,9 @@
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
|
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
|
||||||
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 h1:74lLNRzvsdIlkTgfDSMuaPjBr4cf6k7pwQQANm/yLKU=
|
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9 h1:74lLNRzvsdIlkTgfDSMuaPjBr4cf6k7pwQQANm/yLKU=
|
||||||
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
|
github.com/dchest/uniuri v0.0.0-20160212164326-8902c56451e9/go.mod h1:GgB8SF9nRG+GqaDtLcwJZsQFhcogVCJ79j4EdT0c2V4=
|
||||||
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
|
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/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||||
github.com/mordillo123/sockjs-go-client v0.0.0-20161009150606-c1486c966a40 h1:d/FazCBU+C1trw+F+Gdah5Q3QX5kNsOigUCes3z0gVc=
|
|
||||||
github.com/mordillo123/sockjs-go-client v0.0.0-20161009150606-c1486c966a40/go.mod h1:b+6Qgn9fCwiTtpRr6lHe51DY2g69kcMnWc53J4EV4Jc=
|
|
||||||
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
|
github.com/valyala/fastjson v1.4.1 h1:hrltpHpIpkaxll8QltMU8c3QZ5+qIiCL8yKqPFJI/yE=
|
||||||
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
|
github.com/valyala/fastjson v1.4.1/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o=
|
||||||
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d h1:PPZHRoZFy9p4GjXssLvTneJfX6cS0bEm51md5TqXFgU=
|
meow.tf/streamdeck/sdk v0.0.0-20190519021527-54a933f8777d h1:PPZHRoZFy9p4GjXssLvTneJfX6cS0bEm51md5TqXFgU=
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
"Icon": "images/pluginIcon",
|
"Icon": "images/pluginIcon",
|
||||||
"CategoryIcon": "images/pluginIcon",
|
"CategoryIcon": "images/pluginIcon",
|
||||||
"URL": "https://streamdeck.meow.tf/obsreplay",
|
"URL": "https://streamdeck.meow.tf/obsreplay",
|
||||||
"Version": "1.1.1",
|
"Version": "1.1.2",
|
||||||
"SDKVersion": 2,
|
"SDKVersion": 2,
|
||||||
"OS": [
|
"OS": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,12 +85,38 @@ func (c *Client) Connect() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) Auth(key string, callback func(error)) {
|
||||||
|
c.SendRPC("TcpServerService", "auth", func(response *RPCResponse) {
|
||||||
|
if response.Error != nil {
|
||||||
|
callback(errors.New(response.Error.Message))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var result bool
|
||||||
|
|
||||||
|
json.Unmarshal(*response.Result, &result)
|
||||||
|
|
||||||
|
if !result {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(nil)
|
||||||
|
}, key)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client) Disconnect() error {
|
func (c *Client) Disconnect() error {
|
||||||
return c.conn.Close()
|
return c.conn.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Subscribe(resource, method string, handler SubscriptionHandler) {
|
func (c *Client) Subscribe(resource, method string, handler SubscriptionHandler) error {
|
||||||
|
responseCh := make(chan error, 1)
|
||||||
|
|
||||||
c.SendRPC(resource, method, func(response *RPCResponse) {
|
c.SendRPC(resource, method, func(response *RPCResponse) {
|
||||||
|
if response.Error != nil {
|
||||||
|
responseCh <- errors.New(response.Error.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
res := &ResourceEvent{}
|
res := &ResourceEvent{}
|
||||||
|
|
||||||
json.Unmarshal(*response.Result, &res)
|
json.Unmarshal(*response.Result, &res)
|
||||||
|
@ -98,14 +124,18 @@ func (c *Client) Subscribe(resource, method string, handler SubscriptionHandler)
|
||||||
c.subscriptionLock.Lock()
|
c.subscriptionLock.Lock()
|
||||||
c.subscriptions[res.ResourceId] = handler
|
c.subscriptions[res.ResourceId] = handler
|
||||||
c.subscriptionLock.Unlock()
|
c.subscriptionLock.Unlock()
|
||||||
|
|
||||||
|
close(responseCh)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return <-responseCh
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SendRPC(resource, method string, handler ResponseHandler) error {
|
func (c *Client) SendRPC(resource, method string, handler ResponseHandler, args ...string) error {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
|
|
||||||
m["resource"] = resource
|
m["resource"] = resource
|
||||||
m["args"] = []string{}
|
m["args"] = args
|
||||||
|
|
||||||
atomic.AddInt32(&c.requestId, 1)
|
atomic.AddInt32(&c.requestId, 1)
|
||||||
|
|
||||||
|
|
|
@ -14,12 +14,21 @@ func Test_StreamlabsOBS(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
closeCh := make(chan struct{}, 1)
|
||||||
|
|
||||||
|
c.Auth("a", func(err error) {
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
closeCh <- struct{}{}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.Subscribe("StreamingService", "replayBufferStatusChange", func(event *ResourceEvent) {
|
c.Subscribe("StreamingService", "replayBufferStatusChange", func(event *ResourceEvent) {
|
||||||
var status string
|
var status string
|
||||||
event.DecodeTo(&status)
|
event.DecodeTo(&status)
|
||||||
log.Println("Event received:", status)
|
log.Println("Event received:", status)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
ch := make(chan struct{}, 1)
|
<-closeCh
|
||||||
<-ch
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue