-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from kindlyops/ivs-osc-bridge
Feature: bridging OSC to IVS
- Loading branch information
Showing
462 changed files
with
73,863 additions
and
90,383 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
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
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,115 @@ | ||
// Copyright © 2021 Kindly Ops, LLC <[email protected]> | ||
// | ||
// 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. | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/ivs" | ||
"github.com/hypebeast/go-osc/osc" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ivsOscBridgeCmd = &cobra.Command{ | ||
Use: "ivs-bridge <ivs-stream-arn>", | ||
Short: "Connect OSC commands to IVS PutMetadata.", | ||
Long: `Use OSC to send messages to IVS using PutMetadata API.`, | ||
Run: ivsOscBridge, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
var ivsPutMetadataCmd = &cobra.Command{ | ||
Use: "ivs-put <ivs-stream-arn> <data payload>", | ||
Short: "Send payload to IVS PutMetadata.", | ||
Long: `Send messages to IVS using PutMetadata API.`, | ||
Run: ivsPutMetadata, | ||
Args: cobra.ExactArgs(2), | ||
} | ||
|
||
func ivsOscBridge(cmd *cobra.Command, args []string) { | ||
arn := args[0] | ||
addr := "127.0.0.1:" + Port | ||
|
||
if Debug { | ||
log.Printf("Listening on port: '%s'\n", addr) | ||
} | ||
|
||
s := session.Must(session.NewSession()) | ||
svc := ivs.New(s) | ||
|
||
d := osc.NewStandardDispatcher() | ||
d.AddMsgHandler("/vbs/ivsbridge", func(msg *osc.Message) { | ||
if Debug { | ||
osc.PrintMessage(msg) | ||
} | ||
data := fmt.Sprintf("%v", msg.Arguments[0]) | ||
input := &ivs.PutMetadataInput{ | ||
ChannelArn: aws.String(arn), | ||
Metadata: aws.String(data), | ||
} | ||
|
||
_, err := svc.PutMetadata(input) | ||
if err != nil { | ||
if Debug { | ||
log.Printf("error from ivs.PutMetadata: %s", err.Error()) | ||
} | ||
} | ||
}) | ||
|
||
server := &osc.Server{ | ||
Addr: addr, | ||
Dispatcher: d, | ||
} | ||
|
||
err := server.ListenAndServe() | ||
if err != nil { | ||
if Debug { | ||
log.Printf("error from server.ListenAndServe: %s", err.Error()) | ||
} | ||
} | ||
} | ||
|
||
func ivsPutMetadata(cmd *cobra.Command, args []string) { | ||
arn := args[0] | ||
data := args[1] | ||
|
||
if Debug { | ||
log.Printf("got data: '%s'\n", data) | ||
} | ||
|
||
s := session.Must(session.NewSession()) | ||
svc := ivs.New(s) | ||
input := &ivs.PutMetadataInput{ | ||
ChannelArn: aws.String(arn), | ||
Metadata: aws.String(data), | ||
} | ||
|
||
_, err := svc.PutMetadata(input) | ||
if err != nil { | ||
log.Fatalf("error from ivs.PutMetadata: %s", err.Error()) | ||
} | ||
} | ||
|
||
// Port to listen for OSC messages. | ||
var Port string | ||
|
||
func init() { | ||
ivsOscBridgeCmd.Flags().StringVarP(&Port, "port", "p", "4427", "Port to listen for OSC") | ||
rootCmd.AddCommand(ivsOscBridgeCmd) | ||
rootCmd.AddCommand(ivsPutMetadataCmd) | ||
} |
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
Oops, something went wrong.