newtek

package module
v0.0.0-...-c0fac69 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

newtek-go

A Go library for interacting with NewTek TriCaster and 3Play devices via HTTP API and TCP connections.

Developer

FlowingSPDG (Shugo Kawamura/河村 柊吾)

Overview

This library provides a comprehensive Go interface for controlling and monitoring NewTek broadcast equipment, including TriCaster and 3Play devices. It supports both HTTP API communication and TCP-based real-time control, enabling developers to build custom automation and monitoring solutions.

Features

HTTP API Client (ClientV1)
  • Device Information: Get product information, version details, and system status
  • Shortcut Control: Execute device shortcuts via HTTP requests
  • Video Preview: Capture video thumbnails and previews
  • Metadata Access: Retrieve clip metadata and project information
  • State Monitoring: Get current shortcut states and device status
  • WebSocket Notifications: Real-time notifications for various events
TCP Client (ClientV1TCP)
  • Direct TCP Communication: Low-latency control via TCP port 5951
  • Shortcut Execution: Send shortcut commands with parameters
  • Registration Management: Register/unregister client connections
  • Binary Data Transmission: Efficient data transfer for real-time control
Supported Notification Types
  • Change Notifications: Monitor system state changes
  • Shortcut Notifications: Track shortcut executions
  • Timecode Notifications: Receive timecode updates
  • VU Notifications: Monitor audio levels
  • Video Notifications: Track video state changes

Installation

go get github.com/FlowingSPDG/newtek-go

Dependencies

  • Go 1.24+
  • github.com/coder/websocket - WebSocket support
  • github.com/icholy/digest - HTTP Digest authentication

Quick Start

HTTP API Client
package main

import (
    "context"
    "fmt"
    "github.com/FlowingSPDG/newtek-go"
)

func main() {
    ctx := context.Background()
    
    // Create HTTP client
    client, err := newtek.NewClientV1("192.168.1.100", "admin", "admin")
    if err != nil {
        panic(err)
    }
    
    // Get device information
    product, err := client.GetProduct(ctx)
    if err != nil {
        panic(err)
    }
    
    fmt.Printf("Product: %s %s\n", product.ProductName, product.ProductVersion)
    fmt.Printf("Session: %s\n", product.SessionName)
    
    // Execute a shortcut
    err = client.ShortcutHTTP(ctx, "record", nil)
    if err != nil {
        panic(err)
    }
}
TCP Client
package main

import (
    "fmt"
    "github.com/FlowingSPDG/newtek-go"
)

func main() {
    // Create TCP client
    client, err := newtek.NewClientV1TCP("192.168.1.100")
    if err != nil {
        panic(err)
    }
    defer client.Close()
    
    // Send shortcut command
    shortcuts := []newtek.Shortcut{
        {Name: "mode", Value: "2"},
    }
    
    req := newtek.Shortcuts{Shortcut: shortcuts}
    err = client.Shortcut(req)
    if err != nil {
        panic(err)
    }
}
WebSocket Notifications
package main

import (
    "context"
    "fmt"
    "github.com/FlowingSPDG/newtek-go"
)

func main() {
    ctx := context.Background()
    client, err := newtek.NewClientV1("192.168.1.100", "admin", "admin")
    if err != nil {
        panic(err)
    }
    
    // Listen for change notifications
    err = client.ChangeNotifications(ctx, func(msg string) {
        fmt.Printf("System change: %s\n", msg)
    })
    if err != nil {
        panic(err)
    }
    
    // Keep the program running
    select {}
}

API Reference

ClientV1 Interface
Device Information
  • GetLive(ctx context.Context) bool - Check if device is live
  • GetProduct(ctx context.Context) (*ProductInformation, error) - Get device information
Control
  • ShortcutHTTP(ctx context.Context, name string, kv map[string]string) error - Execute shortcut via HTTP
  • Trigger(ctx context.Context, name string) error - Trigger device action
Media
  • VideoPreview(ctx context.Context, name string, xres, yres, quality int) (image.Image, error) - Get video preview
  • MetaData(ctx context.Context) (*Metadata, error) - Get project metadata
State Monitoring
  • ShortcutStates(ctx context.Context) (*ShortcutStates, error) - Get current shortcut states
Notifications
  • ChangeNotifications(ctx context.Context, cb func(msg string)) error - Monitor system changes
  • ShortcutNotifications(ctx context.Context, cb func(msg string)) error - Monitor shortcut executions
  • TimecodeNotifications(ctx context.Context, cb func(msg string)) error - Monitor timecode
  • VUNotifications(ctx context.Context, name string, cb func(msg string)) error - Monitor audio levels
ClientV1TCP Interface
  • Register(name string) error - Register client connection
  • Unregister(name string) error - Unregister client connection
  • Shortcut(s Shortcuts) error - Send shortcut command
  • Send(data string) error - Send raw data
  • SendBytes(data []byte) error - Send raw bytes
  • Close() error - Close connection

Data Models

ProductInformation

Contains device information including model, version, serial number, and session details.

ShortcutStates

Current state of all device shortcuts with their values and types.

Metadata

Project metadata including clips, marks, and camera information.

Tally

Tally information for video sources including program and preview states.

Examples

The example/ directory contains comprehensive examples demonstrating various features:

  • simple_shortcut/ - Basic shortcut execution
  • simple_shortcut_tcp/ - TCP-based shortcut control
  • change_notification/ - System change monitoring
  • shortcut_notifications/ - Shortcut execution monitoring
  • timecode/ - Timecode monitoring
  • vu_notifications/ - Audio level monitoring
  • thumbnail/ - Video preview capture
  • autoplay/ - Complex automation example with 3Play and TriCaster integration

Use Cases

  • Broadcast Automation: Automate recording, switching, and playback operations
  • Monitoring Systems: Real-time monitoring of device status and audio levels
  • Integration: Connect NewTek devices with external systems and workflows
  • Custom Control Panels: Build custom control interfaces for specific workflows
  • Data Collection: Gather device telemetry and operational data

Network Requirements

  • HTTP API: Port 80 (default) for HTTP communication
  • TCP Control: Port 5951 for direct TCP control
  • WebSocket: Port 80 for WebSocket notifications
  • Authentication: HTTP Digest authentication required

Error Handling

The library provides comprehensive error handling for network issues, authentication failures, and device communication errors. Always check returned errors and implement appropriate retry logic for production applications.

Contributing

Contributions are welcome! Please ensure your code follows Go best practices and includes appropriate tests.

License

This project is licensed under the terms specified in the LICENSE file.

Support

For issues and questions, please create an issue in the GitHub repository.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct {
	Text  string `xml:",chardata"`
	Angle string `xml:"angle,attr"`
	Tag   string `xml:"tag,attr"`
	Path  string `xml:"path,attr"`
}

type ClientV1

type ClientV1 interface {
	GetLive(ctx context.Context) bool
	GetProduct(ctx context.Context) (info *ProductInformation, err error)
	ShortcutHTTP(ctx context.Context, name string, kv map[string]string) error
	ShortcutWS(ctx context.Context, name string, kv map[string]string) error
	Trigger(ctx context.Context, name string) error

	// Basic Switcher Controls
	Take(ctx context.Context) error
	AutoTransition(ctx context.Context) error
	SetSourceToPreview(ctx context.Context, source string) error
	SetSourceToProgram(ctx context.Context, source string) error
	SetSourceToME(ctx context.Context, me, source string) error
	SetDSKOnAir(ctx context.Context, dsk string, onAir bool) error
	SetTransitionSelection(ctx context.Context, transition string) error

	// Media Controls
	MediaPlay(ctx context.Context, media string) error
	MediaStop(ctx context.Context, media string) error
	MediaRewind(ctx context.Context, media string) error
	MediaFastForward(ctx context.Context, media string) error
	MediaPause(ctx context.Context, media string) error

	// Recording and Streaming
	RecordToggle(ctx context.Context) error
	RecordStart(ctx context.Context) error
	RecordStop(ctx context.Context) error
	StreamToggle(ctx context.Context) error
	StreamStart(ctx context.Context) error
	StreamStop(ctx context.Context) error

	// Macros
	RunSystemMacro(ctx context.Context, macro string) error
	RunCustomMacro(ctx context.Context, macro string) error

	// Advanced Macro Controls
	PlayMacroByName(ctx context.Context, name string) error
	PlayMacroByID(ctx context.Context, id string) error
	RecordMacroByName(ctx context.Context, name string) error
	StopRecordMacro(ctx context.Context) error
	StopMacroByName(ctx context.Context, name string) error
	StopMacroByID(ctx context.Context, id string) error
	MacroIsEnabledByName(ctx context.Context, name string) (bool, error)
	MacroIsEnabledByID(ctx context.Context, id string) (bool, error)
	GetMacroIDByName(ctx context.Context, name string) (string, error)

	// Output Control
	SetMixOutput(ctx context.Context, output string) error

	// DataLink
	SetDataLinkValue(ctx context.Context, key, value string) error
	GetDataLinkValue(ctx context.Context, key string) (string, error)

	// Feedback and Status
	GetTally(ctx context.Context) (*Tally, error)
	GetRecordingStatus(ctx context.Context) (bool, error)
	GetStreamingStatus(ctx context.Context) (bool, error)
	GetMediaStatus(ctx context.Context, media string) (string, error)
	GetSourceStatus(ctx context.Context) (program, preview string, err error)

	// Dictionary Queries
	GetDictionary(ctx context.Context, key string) ([]byte, error)
	GetSwitcherInfo(ctx context.Context) ([]byte, error)
	GetBufferInfo(ctx context.Context) ([]byte, error)
	GetSwitcherUIEffects(ctx context.Context) ([]byte, error)
	GetAudioMixerInfo(ctx context.Context) ([]byte, error)
	GetAudioBinsInfo(ctx context.Context) ([]byte, error)
	GetFileBrowserInfo(ctx context.Context) ([]byte, error)
	GetMacrosList(ctx context.Context) ([]byte, error)
	GetNDISources(ctx context.Context) ([]byte, error)
	GetDDRPlaylist(ctx context.Context) ([]byte, error)
	GetDDRTimecode(ctx context.Context) ([]byte, error)

	// DataLink()
	// File()
	VideoPreview(ctx context.Context, name string, xres, yres, quality int) (image.Image, error)

	// Dictonary stuff
	// Dictionary(key string) error
	MetaData(ctx context.Context) (*Metadata, error)
	// Tally()
	// Switcher()
	// Buffer()
	// SwitcherUIEffect()
	ShortcutStates(ctx context.Context) (*ShortcutStates, error)

	// Websocket stuff
	// v1/audio_notifications
	// v1/change_notifications
	// v1/shortcut_notifications
	// v1/shortcut_state_notifications
	// v1/timecode_notifications
	// v1/vu_notifications
	VUNotifications(ctx context.Context, name string, cb func(msg string)) error
	ChangeNotifications(ctx context.Context, cb func(msg string)) error
	TimecodeNotifications(ctx context.Context, cb func(msg string)) error
	ShortcutNotifications(ctx context.Context, cb func(msg string)) error

	// Additional WebSocket features
	AudioNotifications(ctx context.Context, name string, cb func(data []byte)) error
	ShortcutStateNotifications(ctx context.Context, cb func(msg string)) error
	VideoNotifications(ctx context.Context, name string, xres, yres, quality int, cb func(data []byte)) error
}

func NewClientV1

func NewClientV1(host, user, password string) (ClientV1, error)

type ClientV1TCP

type ClientV1TCP interface {
	Close() error                 // Close Connection
	Register(name string) error   // send NTK_states
	Unregister(name string) error // send NTK_states
	Send(data string) error
	SendBytes(data []byte) error
	Shortcut(s Shortcuts) error // should include shortcut XML or name and K/V

}

func NewClientV1TCP

func NewClientV1TCP(host string) (ClientV1TCP, error)

type Clip

type Clip struct {
	Text string `xml:",chardata"`
	Mark []struct {
		Text   string   `xml:",chardata"`
		ID     string   `xml:"id,attr"`
		In     string   `xml:"in,attr"`
		Out    string   `xml:"out,attr"`
		Camera []Camera `xml:"camera"`
	} `xml:"mark"`
}

type Metadata

type Metadata struct {
	XMLName xml.Name `xml:"metadata"`
	Text    string   `xml:",chardata"`
	Clips   []Clip   `xml:"clips"`
}

type ProductInformation

type ProductInformation struct {
	XMLName            xml.Name `xml:"product_information"`
	Text               string   `xml:",chardata"`
	ProductModel       string   `xml:"product_model"`
	ProductName        string   `xml:"product_name"`
	ProductVersion     string   `xml:"product_version"`
	ProductID          string   `xml:"product_id"`
	ProductSerialNo    string   `xml:"product_serial_no"`
	ProductBuildNo     string   `xml:"product_build_no"`
	MachineName        string   `xml:"machine_name"`
	SessionXResolution string   `xml:"session_x_resolution"`
	SessionYResolution string   `xml:"session_y_resolution"`
	SessionFielded     string   `xml:"session_fielded"`
	SessionFrameRate   string   `xml:"session_frame_rate"`
	SessionAspectRatio string   `xml:"session_aspect_ratio"`
	SessionColorFormat string   `xml:"session_color_format"`
	SessionColorCoding string   `xml:"session_color_coding"`
	SessionName        string   `xml:"session_name"`
	OutputCount        string   `xml:"output_count"`
}

ProductInformation. /v1/version API

type Shortcut

type Shortcut struct {
	XMLName xml.Name `xml:"shortcut"`
	Text    string   `xml:",chardata"`
	Name    string   `xml:"name,attr"`
	Value   string   `xml:"value,attr"`
}

type ShortcutState

type ShortcutState struct {
	Text   string `xml:",chardata"`
	Name   string `xml:"name,attr"`
	Value  string `xml:"value,attr"`
	Type   string `xml:"type,attr"`
	Sender string `xml:"sender,attr"`
}

type ShortcutStates

type ShortcutStates struct {
	XMLName       xml.Name        `xml:"shortcut_states"`
	Text          string          `xml:",chardata"`
	ShortcutState []ShortcutState `xml:"shortcut_state"`
}

type Shortcuts

type Shortcuts struct {
	XMLName  xml.Name   `xml:"shortcuts"`
	Text     string     `xml:",chardata"`
	Shortcut []Shortcut `xml:"shortcut"`
}

type Tally

type Tally struct {
	XMLName xml.Name `xml:"tally"`
	Text    string   `xml:",chardata"`
	Column  []struct {
		Text   string `xml:",chardata"`
		Name   string `xml:"name,attr"`
		Index  string `xml:"index,attr"`
		OnPgm  string `xml:"on_pgm,attr"`
		OnPrev string `xml:"on_prev,attr"`
		NdiID  string `xml:"ndi_id,attr"`
	} `xml:"column"`
}

Directories

Path Synopsis
example
autoplay command
feedback_status command
macros_datalink command
media_control command
simple_shortcut command
thumbnail command
timecode command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址