-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
919f1cf
commit fad2e9e
Showing
4 changed files
with
147 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/andreykaipov/goobs" | ||
"github.com/andreykaipov/goobs/api/events" | ||
) | ||
|
||
func main() { | ||
client, err := goobs.New(os.Getenv("WSL_HOST")+":4444", goobs.WithPassword("hello")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer client.Disconnect() | ||
|
||
version, _ := client.General.GetVersion() | ||
fmt.Printf("Websocket server version: %s\n", version.ObsWebsocketVersion) | ||
fmt.Printf("OBS Studio version: %s\n", version.ObsStudioVersion) | ||
|
||
// This event loop is in the foreground now. If you mess around in OBS, | ||
// you'll see different events popping up! | ||
|
||
for event := range client.IncomingEvents { | ||
switch e := event.(type) { | ||
case *events.Error: | ||
log.Printf("Got an error: %s", e.Err) | ||
default: | ||
log.Printf("Unhandled event: %#v", e.GetUpdateType()) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"math/rand" | ||
"os" | ||
"time" | ||
|
||
"github.com/andreykaipov/goobs" | ||
"github.com/andreykaipov/goobs/api/events" | ||
"github.com/andreykaipov/goobs/api/requests/sources" | ||
) | ||
|
||
func main() { | ||
client, err := goobs.New(os.Getenv("WSL_HOST")+":4444", goobs.WithPassword("hello")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
go func() { | ||
for event := range client.IncomingEvents { | ||
switch e := event.(type) { | ||
case *events.SourceVolumeChanged: | ||
fmt.Printf("Volume changed for %-25q: %f\n", e.SourceName, e.Volume) | ||
default: | ||
log.Printf("Unhandled event: %#v", e.GetUpdateType()) | ||
} | ||
} | ||
}() | ||
|
||
fmt.Println("Setting random volumes for each source...") | ||
|
||
rand.Seed(time.Now().UnixNano()) | ||
list, _ := client.Sources.GetSourcesList() | ||
|
||
for _, v := range list.Sources { | ||
if _, err := client.Sources.SetVolume(&sources.SetVolumeParams{ | ||
Source: v.Name, | ||
Volume: rand.Float64(), | ||
}); err != nil { | ||
panic(err) | ||
} | ||
} | ||
|
||
fmt.Println("Test toggling the mute status of the first source...") | ||
|
||
name := list.Sources[0].Name | ||
resp, _ := client.Sources.GetVolume(&sources.GetVolumeParams{Source: name}) | ||
fmt.Printf("%s is muted? %t\n", name, resp.Muted) | ||
|
||
_, _ = client.Sources.ToggleMute(&sources.ToggleMuteParams{Source: name}) | ||
resp, _ = client.Sources.GetVolume(&sources.GetVolumeParams{Source: name}) | ||
fmt.Printf("%s is muted? %t\n", name, resp.Muted) | ||
} |