opentok

package
v2.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

The OpenTok Go SDK lets you generate sessions and tokens for OpenTok applications.

It also includes methods for working with OpenTok archives, working with OpenTok live streaming broadcasts, working with OpenTok SIP interconnect, and disconnecting clients from sessions.

See Also

Generate sessions: https://tokbox.com/developer/guides/create-session

Generate tokens: https://tokbox.com/developer/guides/create-token

Archives: https://tokbox.com/developer/guides/archiving

Live streaming broadcasts: https://tokbox.com/developer/guides/broadcast/live-streaming

SIP interconnect: https://tokbox.com/developer/guides/sip

Disconnecting clients from sessions: https://tokbox.com/developer/guides/moderation/rest

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func UserAgent added in v2.3.0

func UserAgent() string

UserAgent returns a string containing the Go version, system architecture and OS, and the opentok-go-sdk version.

func Version added in v2.3.0

func Version() string

Version returns the semantic version (see http://semver.org).

Types

type AmazonS3Config

type AmazonS3Config struct {
	// The Amazon Web Services access key.
	AccessKey string `json:"accessKey"`

	// The Amazon Web Services secret key.
	SecretKey string `json:"secretKey"`

	// The S3 bucket name.
	Bucket string `json:"bucket"`

	// The S3 or S3-compatible storage endpoint.
	Endpoint string `json:"endpoint,omitempty"`
}

AmazonS3Config defines the Amazon S3 config for setting archiving upload target.

type Archive

type Archive struct {
	// The time at which the archive was created, in milliseconds since the
	// UNIX epoch.
	CreatedAt int `json:"createdAt"`

	// The duration of the archive, in milliseconds.
	Duration int `json:"duration"`

	// Whether the archive has an audio track or not.
	HasAudio bool `json:"hasAudio"`

	// Whether the archive has an video track or not.
	HasVideo bool `json:"hasVideo"`

	// The unique archive ID.
	ID string `json:"id"`

	// The name of the archive.
	Name string `json:"name"`

	// The output mode to be generated for this archive.
	OutputMode ArchiveOutputMode `json:"outputMode"`

	// The API key associated with the archive.
	ProjectID int `json:"projectId"`

	// This string describes the reason the archive stopped or failed.
	Reason string `json:"reason"`

	// The resolution of the archive.
	Resolution Resolution `json:"resolution"`

	// The session ID of the OpenTok session associated with this archive.
	SessionID string `json:"sessionId"`

	// The size of the MP4 file.
	Size int `json:"size"`

	// The status of the archive.
	Status string `json:"status"`

	// The download URL of the available MP4 file.
	URL *string `json:"url"`

	// The instance of OpenTok.
	OpenTok *OpenTok `json:"-"`
}

Archive defines the response returned from API.

func (*Archive) Delete

func (archive *Archive) Delete() error

Delete deletes a specific archive.

func (*Archive) Stop

func (archive *Archive) Stop() (*Archive, error)

Stop stops the recording of the archive.

type ArchiveList

type ArchiveList struct {
	// The total number of archives for the API key.
	Count int `json:"count"`

	// An array of objects defining each archive retrieved.
	// Archives are listed from the newest to the oldest in the return set.
	Items []*Archive `json:"items"`
}

ArchiveList defines the response returned from API.

type ArchiveListOptions

type ArchiveListOptions struct {
	// Query parameters to specify the index offset of the first archive.
	Offset int

	// Query parameter to limit the number of archives to be returned.
	Count int

	// Query parameter to list archives for a specific session ID.
	SessionID string
}

ArchiveListOptions defines the query parameters to filter the list of archives.

type ArchiveMode

type ArchiveMode string

ArchiveMode is the alias of string type.

const (
	// AutoArchived is used to have the session archived automatically.
	AutoArchived ArchiveMode = "always"

	// ManualArchived is used to have the session archived manually, you can
	// archive the session by calling the REST /archive POST method.
	ManualArchived ArchiveMode = "manual"
)

type ArchiveOptions

type ArchiveOptions struct {
	// The session ID of the OpenTok session you want to start archiving.
	SessionID string `json:"sessionId"`

	// Whether the archive will record audio (true, the default) or not (false).
	HasAudio bool `json:"hasAudio,omitempty"`

	// Whether the archive will record video (true, the default) or not (false).
	HasVideo bool `json:"hasVideo,omitempty"`

	// Specify this to assign the initial layout type for the archive.
	Layout *Layout `json:"layout,omitempty"`

	// The name of the archive (for your own identification).
	Name string `json:"name,omitempty"`

	// Whether all streams in the archive are recorded to a single file or to
	// individual files.
	OutputMode ArchiveOutputMode `json:"outputMode,omitempty"`

	// The resolution of the archive.
	Resolution Resolution `json:"resolution,omitempty"`
}

ArchiveOptions defines the options for starting an archive recording.

type ArchiveOutputMode

type ArchiveOutputMode string

ArchiveOutputMode is the alias of string type.

const (
	// Composed means the archive is a single MP4 file composed of all streams.
	Composed ArchiveOutputMode = "composed"

	// Individual means the archive is a ZIP container file with multiple
	// individual media files for each stream, and a JSON metadata file for video
	// synchronization.
	Individual ArchiveOutputMode = "individual"
)

type AzureConfig

type AzureConfig struct {
	// The Microsoft Azure account name.
	AccountName string `json:"accountName"`

	// The Microsoft Azure account key.
	AccountKey string `json:"accountKey"`

	// The Microsoft Azure container name.
	Container string `json:"container"`

	// The Microsoft Azure domain in which the container resides.
	Domain string `json:"domain,omitempty"`
}

AzureConfig defines the Microsoft Azure config for setting archiving upload target.

type Broadcast

type Broadcast struct {
	// The unique ID for the broadcast.
	ID string `json:"id"`

	// The OpenTok session ID.
	SessionID string `json:"sessionId"`

	// The API key associated with the broadcast.
	ProjectID int `json:"projectId"`

	// The time at which the broadcast was created, in milliseconds since the
	// UNIX epoch.
	CreatedAt int `json:"createdAt"`

	// The time at which the broadcast was updated, in milliseconds since the
	// UNIX epoch.
	UpdatedAt int `json:"updatedAt"`

	// The resolution of the broadcast.
	Resolution Resolution `json:"resolution"`

	// The status of the broadcast.
	Status string `json:"status"`

	// An object containing details about the HLS and RTMP broadcasts.
	BroadcastURLs *BroadcastURLs `json:"broadcastUrls"`

	// The instance of OpenTok.
	OpenTok *OpenTok `json:"-"`
}

Broadcast defines the response returned from API.

func (*Broadcast) Stop

func (broadcast *Broadcast) Stop() (*Broadcast, error)

Stop stops a live broadcast of an OpenTok session.

type BroadcastList

type BroadcastList struct {
	// The total number of broadcasts in the results.
	Count int `json:"count"`

	// An array of objects defining each broadcast retrieved.
	// Broadcasts are listed from the newest to the oldest in the return set.
	Items []*Broadcast `json:"items"`
}

BroadcastList defines the response returned from API.

type BroadcastListOptions

type BroadcastListOptions struct {
	// The start offset in the list of existing broadcasts.
	Offset int

	// The number of broadcasts to retrieve starting at offset.
	Count int

	// Retrive only broadcasts for a given session ID.
	SessionID string
}

BroadcastListOptions defines the query parameters to filter the list of broadcasts.

type BroadcastOptions

type BroadcastOptions struct {
	// The OpenTok session you want to broadcast.
	SessionID string `json:"sessionId"`

	// Specify this to assign the initial layout type for the broadcast.
	Layout *Layout `json:"layout,omitempty"`

	// The maximum duration for the broadcast, in seconds.
	MaxDuration int `json:"maxDuration,omitempty"`

	// This object defines the types of broadcast streams you want to start
	// (both HLS and RTMP).
	Outputs *BroadcastOutputOptions `json:"outputs"`

	// The resolution of the broadcast: either SD(default) or HD.
	Resolution Resolution `json:"resolution,omitempty"`
}

BroadcastOptions defines the options for live streaming broadcast.

type BroadcastOutputOptions

type BroadcastOutputOptions struct {
	// Set this property to an empty object for HLS.
	// The HLS URL is returned in the response and in the REST method for getting
	// information about a live streaming broadcast.
	HLS *HLSConfig `json:"hls,omitempty"`

	// The configuration of RTMP.
	RTMP []*RTMPConfig `json:"rtmp,omitempty"`
}

BroadcastOutputOptions defines the types of broadcast streams you want to start (both HLS and RTMP).

type BroadcastURLs

type BroadcastURLs struct {
	// HLS broadcast streams URL.
	HLS string `json:"hls"`

	// The configuration of RTMP.
	RTMP []*RTMPConfig `json:"rtmp"`
}

BroadcastURLs defines the details on the HLS and RTMP broadcast streams.

type DialOptions

type DialOptions struct {
	// The OpenTok session ID for the SIP call to join.
	SessionID string `json:"sessionId"`

	// The OpenTok token to be used for the participant being called.
	Token string `json:"token"`

	// The SIP information
	SIP *SIP `json:"sip"`

	// The data for token generation
	TokenData string `json:"-"`
}

DialOptions defines the options for SIP call

type HLSConfig

type HLSConfig struct{}

HLSConfig defines the config of HLS.

type HTTPClient added in v2.1.0

type HTTPClient interface {
	Do(r *http.Request) (*http.Response, error)
}

HTTPClient is an interface to allow custom clients and timeouts.

type Layout

type Layout struct {
	Type            LayoutType `json:"type,omitempty"`
	StyleSheet      string     `json:"stylesheet,omitempty"`
	ScreenShareType LayoutType `json:"screenshareType,omitempty"`
}

Layout defines the layout type for the archive.

type LayoutType

type LayoutType string

LayoutType is the alias of string type.

const (
	// BestFit is a tiled layout, which scales according to the number of videos.
	// The number of columns and rows of varies depending on the number of
	// OpenTok streams in the archive.
	BestFit LayoutType = "bestFit"

	// PIP is a picture-in-picture layout, where a small stream is visible over
	// a full-size stream.
	PIP LayoutType = "pip"

	// VerticalPresentation is a layout with one large stream on the right edge of
	// the output, and several smaller streams along the left edge of the output.
	VerticalPresentation LayoutType = "verticalPresentation"

	// HorizontalPresentation is a layout with one large stream on the top edge of
	// the output, and several smaller streams along the bottom edge of the output.
	HorizontalPresentation LayoutType = "horizontalPresentation"

	// Custom let you can use CSS to define your own custom layout for composed
	// archive videos.
	Custom LayoutType = "custom"
)

type MediaMode

type MediaMode string

MediaMode is the alias of string type.

const (
	// Relayed if you prefer clients to attempt to send audio-video
	// streams directly to other clients.
	Relayed MediaMode = "enabled"

	// Routed if you want to use the OpenTok Media Router.
	Routed MediaMode = "disabled"
)

type MuteOptions added in v2.3.0

type MuteOptions struct {
	// Active specifies whether streams published after this call, in addition to
	// the current streams in the session, should be muted (true) or not (false).
	Active bool

	// ExcludedStreams specifies stream IDs for streams that should not be muted.
	ExcludedStreams []string
}

MuteOptions defines the options for mute published audio.

type OpenTok

type OpenTok struct {
	// contains filtered or unexported fields
}

OpenTok stores the API key and secret for use in making API call.

func New

func New(apiKey, apiSecret string) *OpenTok

New returns an initialized OpenTok instance with the API key and API secret.

Example
package main

import (
	"github.com/calvertyang/opentok-go-sdk/v2/opentok"
)

const (
	apiKey    = "<your api key here>"
	apiSecret = "<your api secret here>"
)

var ot = opentok.New(apiKey, apiSecret)

func main() {
	const (
		apiKey    = "12345678"
		apiSecret = "ba7816bf8f01cfea414140de5dae2223b00361a3"
	)

	ot = opentok.New(apiKey, apiSecret)
}
Output:

func (*OpenTok) ChangeProjectStatus

func (ot *OpenTok) ChangeProjectStatus(projectAPIKey string, projectStatus ProjectStatus) (*Project, error)

ChangeProjectStatus changes the project's status. The status is either active or suspended. You can change a project's status from active to suspended and back.

Example (Active)

Active a project API key

project, err := ot.ChangeProjectStatus("40000001", opentok.ProjectActive)
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "ACTIVE",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

Example (Suspend)

Suspend a project API key

project, err := ot.ChangeProjectStatus("40000001", opentok.ProjectSuspended)
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "SUSPENDED",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) ChangeProjectStatusContext added in v2.1.0

func (ot *OpenTok) ChangeProjectStatusContext(ctx context.Context, projectAPIKey string, projectStatus ProjectStatus) (*Project, error)

ChangeProjectStatusContext uses ctx for HTTP requests.

func (*OpenTok) CreateProject

func (ot *OpenTok) CreateProject(projectName string) (*Project, error)

CreateProject creates an OpenTok API key and secret for a project.

Example
project, err := ot.CreateProject("example")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "VALID",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) CreateProjectContext added in v2.1.0

func (ot *OpenTok) CreateProjectContext(ctx context.Context, projectName string) (*Project, error)

CreateProjectContext uses ctx for HTTP requests.

func (*OpenTok) CreateSession

func (ot *OpenTok) CreateSession(opts *SessionOptions) (*Session, error)

CreateSession generates a new session.

Example
session, err := ot.CreateSession(&opentok.SessionOptions{
	ArchiveMode: opentok.AutoArchived,
	MediaMode:   opentok.Routed,
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", session)
}

// &opentok.Session{
// 	SessionID:      "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	ProjectID:      "40000001",
// 	CreateDt:       "Wed Jan 01 00:00:00 PST 2020",
// 	MediaServerURL: "",
// }
Output:

func (*OpenTok) CreateSessionContext added in v2.1.0

func (ot *OpenTok) CreateSessionContext(ctx context.Context, opts *SessionOptions) (*Session, error)

CreateSessionContext uses ctx for HTTP requests.

func (*OpenTok) Debug added in v2.3.0

func (ot *OpenTok) Debug()

Debug sets the debug flage to true. It will dump the request/response allows you easy to debug.

func (*OpenTok) DeleteArchive

func (ot *OpenTok) DeleteArchive(archiveID string) error

DeleteArchive deletes a specific archive.

Example
err := ot.DeleteArchive("c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea")
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) DeleteArchiveContext added in v2.1.0

func (ot *OpenTok) DeleteArchiveContext(ctx context.Context, archiveID string) error

DeleteArchiveContext uses ctx for HTTP requests.

func (*OpenTok) DeleteArchiveStorage

func (ot *OpenTok) DeleteArchiveStorage() error

DeleteArchiveStorage deletes the configuration of archive storage.

Example
err := ot.DeleteArchiveStorage()

if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) DeleteArchiveStorageContext added in v2.1.0

func (ot *OpenTok) DeleteArchiveStorageContext(ctx context.Context) error

DeleteArchiveStorageContext uses ctx for HTTP requests.

func (*OpenTok) DeleteProject

func (ot *OpenTok) DeleteProject(projectAPIKey string) error

DeleteProject prevents the use of the project API key (and any OpenTok sessions created with it).

Example
err := ot.DeleteProject("40000001")
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) DeleteProjectContext added in v2.1.0

func (ot *OpenTok) DeleteProjectContext(ctx context.Context, projectAPIKey string) error

DeleteProjectContext uses ctx for HTTP requests.

func (*OpenTok) Dial

func (ot *OpenTok) Dial(sessionID string, opts *DialOptions) (*SIPCall, error)

Dial connects your SIP platform to an OpenTok session. The audio from your end of the SIP call is added to the OpenTok session as an audio-only stream. The OpenTok Media Router mixes audio from other streams in the session and sends the mixed audio to your SIP endpoint.

Example
sipCall, err := ot.Dial("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.DialOptions{
	SIP: &opentok.SIP{
		URI: "sip:user@sip.example.comwhen;transport=tls",
		Headers: &opentok.SIPHeaders{
			"X-Foo": "bar",
		},
		Auth: &opentok.SIPAuth{
			Username: "username",
			Password: "password",
		},
		Secure: true,
	},
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", sipCall)
}

// &opentok.SIPCall{
// 	ID:           "ab31819a-cd52-4da4-8b3e-fb9803337c17",
// 	ConnectionID: "3a6aa409-bfc5-462c-a9c7-59b72aeebf69",
// 	StreamID:     "f1a58131-7b2c-4fa8-b2a7-64fdc6b2c0f6",
// }
Output:

func (*OpenTok) DialContext added in v2.1.0

func (ot *OpenTok) DialContext(ctx context.Context, sessionID string, opts *DialOptions) (*SIPCall, error)

DialContext uses ctx for HTTP requests.

func (*OpenTok) ForceDisconnect

func (ot *OpenTok) ForceDisconnect(sessionID, connectionID string) error

ForceDisconnect disconnects a client from an OpenTok session via server-side.

Example
err := ot.ForceDisconnect("40000001", "efdf2fc7-bd6e-4871-9c1d-531f7f6a9486")
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) ForceDisconnectContext added in v2.1.0

func (ot *OpenTok) ForceDisconnectContext(ctx context.Context, sessionID, connectionID string) error

ForceDisconnectContext uses ctx for HTTP requests.

func (*OpenTok) GenerateToken

func (ot *OpenTok) GenerateToken(sessionID string, opts *TokenOptions) (string, error)

GenerateToken generates a token for each user connecting to an OpenTok session.

Example
token, err := ot.GenerateToken("40000001", &opentok.TokenOptions{
	Role:       opentok.Publisher,
	ExpireTime: time.Now().UTC().Add(1 * 24 * time.Hour).Unix(),
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", token)
}

// T1==cGFydG5lcl9pZD08eW91ciBhcGkga2V5IGhlcmU+JnNpZz0yYjQyMzlkNjU4YTVkYmE0NGRhMGMyMmUzOTA2MWM5ZWI1ODQ1MTE1OmNvbm5lY3Rpb25fZGF0YT1mb28lM0RiYXImY3JlYXRlX3RpbWU9MTU3Nzg2NTYwMCZleHBpcmVfdGltZT0xNTc3ODY1NjAwJmluaXRpYWxfbGF5b3V0X2NsYXNzX2xpc3Q9Jm5vbmNlPTAuNDk4OTMzNzE3NzEyNjgyMjUmcm9sZT1wdWJsaXNoZXImc2Vzc2lvbl9pZD0xX01YNDBNREF3TURBd01YNS1NVFUzTnpnMk5UWXdNREF3TUg1NE4ySTBPRTFSWjBSbUsxbFJSbkZRVVdnNGRsWm1UMHQtUVg0
Output:

func (*OpenTok) GetArchive

func (ot *OpenTok) GetArchive(archiveID string) (*Archive, error)

GetArchive returns a archive details record describing the archive.

Example
archive, err := ot.GetArchive("c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", archive)
}

// &opentok.Archive{
// 	CreatedAt:  1579163008000,
// 	Duration:   34,
// 	HasAudio:   true,
// 	HasVideo:   true,
// 	ID:         "c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea",
// 	Name:       "example",
// 	OutputMode: "composed",
// 	ProjectID:  40000001,
// 	Reason:     "user initiated",
// 	Resolution: "1280x720",
// 	SessionID:  "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	Size:       355816,
// 	Status:     "uploaded",
// 	URL:        nil,
// }
Output:

func (*OpenTok) GetArchiveContext added in v2.1.0

func (ot *OpenTok) GetArchiveContext(ctx context.Context, archiveID string) (*Archive, error)

GetArchiveContext uses ctx for HTTP requests.

func (*OpenTok) GetBroadcast

func (ot *OpenTok) GetBroadcast(broadcastID string) (*Broadcast, error)

GetBroadcast returns a broadcast that is in-progress.

Example
broadcast, err := ot.GetBroadcast("ce872e0d-4997-440a-a0a5-10ce715b54cf")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", broadcast)
}

// &opentok.Broadcast{
// 	ID:            "ce872e0d-4997-440a-a0a5-10ce715b54cf",
// 	SessionID:     "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	ProjectID:     40000001,
// 	CreatedAt:     1579163008000,
// 	UpdatedAt:     1579163009000,
// 	Resolution:    "1280x720",
// 	Status:        "stopped",
// 	BroadcastURLs: nil,
// }
Output:

func (*OpenTok) GetBroadcastContext added in v2.1.0

func (ot *OpenTok) GetBroadcastContext(ctx context.Context, broadcastID string) (*Broadcast, error)

GetBroadcastContext uses ctx for HTTP requests.

func (*OpenTok) GetProject

func (ot *OpenTok) GetProject(projectAPIKey string) (*Project, error)

GetProject returns a project details record describing the project.

Example
project, err := ot.GetProject("40000001")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "VALID",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) GetProjectContext added in v2.1.0

func (ot *OpenTok) GetProjectContext(ctx context.Context, projectAPIKey string) (*Project, error)

GetProjectContext uses ctx for HTTP requests.

func (*OpenTok) GetStream

func (ot *OpenTok) GetStream(sessionID, streamID string) (*Stream, error)

GetStream returns a stream details record describing the stream.

Example
stream, err := ot.GetStream("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", "d962b966-964d-4f18-be3f-e0b181a43b0e")

if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", stream)
}

// &opentok.Stream{
// 	ID:              "d962b966-964d-4f18-be3f-e0b181a43b0e",
// 	VideoType:       "camera",
// 	Name:            "",
// 	LayoutClassList: []string{}
// }
Output:

func (*OpenTok) GetStreamContext added in v2.1.0

func (ot *OpenTok) GetStreamContext(ctx context.Context, sessionID, streamID string) (*Stream, error)

GetStreamContext uses ctx for HTTP requests.

func (*OpenTok) ListArchives

func (ot *OpenTok) ListArchives(opts *ArchiveListOptions) (*ArchiveList, error)

ListArchives returns both completed and in-progress archive records of the project.

Example
archiveList, err := ot.ListArchives(&opentok.ArchiveListOptions{})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", archiveList)
}

// &opentok.ArchiveList{
// 	Count: 1,
// 	Items: []*opentok.Archive{
// 		&opentok.Archive{
// 			CreatedAt:  1579163008000,
// 			Duration:   34,
// 			HasAudio:   true,
// 			HasVideo:   true,
// 			ID:         "c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea",
// 			Name:       "example",
// 			OutputMode: "composed",
// 			ProjectID:  40000001,
// 			Reason:     "user initiated",
// 			Resolution: "1280x720",
// 			SessionID:  "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 			Size:       355816,
// 			Status:     "uploaded",
// 			URL:        nil,
// 		},
// 	},
// }
Output:

func (*OpenTok) ListArchivesContext added in v2.1.0

func (ot *OpenTok) ListArchivesContext(ctx context.Context, opts *ArchiveListOptions) (*ArchiveList, error)

ListArchivesContext uses ctx for HTTP requests.

func (*OpenTok) ListBroadcasts

func (ot *OpenTok) ListBroadcasts(opts *BroadcastListOptions) (*BroadcastList, error)

ListBroadcasts returns the records of all broadcasts for your project that are in progress and started. Completed broadcasts are not included in the listing.

Example
broadcasts, err := ot.ListBroadcasts(&opentok.BroadcastListOptions{})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", broadcasts)
}

// &opentok.BroadcastList{
// 	Count:1,
// 	Items:[]*opentok.Broadcast{
// 		&opentok.Broadcast{
// 			ID:            "ce872e0d-4997-440a-a0a5-10ce715b54cf",
// 			SessionID:     "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 			ProjectID:     "40000001",
// 			CreatedAt:     1579163008000,
// 			UpdatedAt:     1579163008000,
// 			Resolution:    "1280x720",
// 			Status:        "started",
// 			BroadcastURLs: &opentok.BroadcastURLs{
// 				HLS: "",
// 				RTMP:[]*opentok.RTMPConfig{
// 					&opentok.RTMPConfig{
// 						ID:         "foo",
// 						Status:     "connecting",
// 						ServerURL:  "rtmps://myfooserver/myfooapp",
// 						StreamName: "myfoostream"
// 					},
// 					&opentok.RTMPConfig{
// 						ID:         "bar",
// 						Status:     "connecting",
// 						ServerURL:  "rtmp://mybarserver/mybarapp",
// 						StreamName: "mybarstream"
// 					},
// 				},
// 			},
// 		},
// 	},
// }
Output:

func (*OpenTok) ListBroadcastsContext added in v2.1.0

func (ot *OpenTok) ListBroadcastsContext(ctx context.Context, opts *BroadcastListOptions) (*BroadcastList, error)

ListBroadcastsContext uses ctx for HTTP requests.

func (*OpenTok) ListProjects

func (ot *OpenTok) ListProjects() ([]*Project, error)

ListProjects returns the records for all projects.

Example
projects, err := ot.ListProjects()
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", projects)
}

// [
// 	&opentok.Project{
// 		ID:                     "40000001",
// 		Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 		Status:                 "VALID",
// 		Name:                   "example",
// 		CreatedAt:              1579163008000,
// 		EnvironmentName:        "default",
// 		EnvironmentDescription: "Standard Environment",
// 	},
// 	&opentok.Project{
// 		ID:                     "40000002",
// 		Secret:                 "fcde2b2edba56bf408601fb721fe9b5c338d10ee",
// 		Status:                 "VALID",
// 		Name:                   "foo",
// 		CreatedAt:              1579163506000,
// 		EnvironmentName:        "default",
// 		EnvironmentDescription: "Standard Environment",
// 	},
// ]
Output:

func (*OpenTok) ListProjectsContext added in v2.1.0

func (ot *OpenTok) ListProjectsContext(ctx context.Context) ([]*Project, error)

ListProjectsContext uses ctx for HTTP requests.

func (*OpenTok) ListStreams

func (ot *OpenTok) ListStreams(sessionID string) (*StreamList, error)

ListStreams returns the stream records in a session.

Example
streams, err := ot.ListStreams("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4")

if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", streams)
}

// &opentok.StreamList{
// 	Count:1,
// 	Items:[]*opentok.Stream{
// 		&opentok.Stream{
// 			ID:              "d962b966-964d-4f18-be3f-e0b181a43b0e",
// 			VideoType:       "camera",
// 			Name:            "",
// 			LayoutClassList: []string{}
// 		}
// 	}
// }
Output:

func (*OpenTok) ListStreamsContext added in v2.1.0

func (ot *OpenTok) ListStreamsContext(ctx context.Context, sessionID string) (*StreamList, error)

ListStreamsContext uses ctx for HTTP requests.

func (*OpenTok) MuteSession added in v2.3.0

func (ot *OpenTok) MuteSession(sessionID string, opts *MuteOptions) (*Project, error)

MuteSession force all streams (except for an optional list of streams) in a session to mute published audio.

Example
project, err := ot.MuteSession("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.MuteOptions{
	Active: true,
	ExcludedStreams: []string{
		"a919b531-bd0e-41fb-8ff0-cdc15684cc93",
		"7f6d8780-741a-4824-98da-16c1f5f1f043",
	},
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "VALID",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) MuteSessionContext added in v2.3.0

func (ot *OpenTok) MuteSessionContext(ctx context.Context, sessionID string, opts *MuteOptions) (*Project, error)

MuteSessionContext uses ctx for HTTP requests.

func (*OpenTok) MuteStream added in v2.3.0

func (ot *OpenTok) MuteStream(sessionID, streamID string) (*Project, error)

MuteStream force a publisher of a specific stream to mute its audio.

Example
project, err := ot.MuteStream("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", "7f6d8780-741a-4824-98da-16c1f5f1f043")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "ba7816bf8f01cfea414140de5dae2223b00361a3",
// 	Status:                 "VALID",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) MuteStreamContext added in v2.3.0

func (ot *OpenTok) MuteStreamContext(ctx context.Context, sessionID, streamID string) (*Project, error)

MuteStreamContext uses ctx for HTTP requests.

func (*OpenTok) RefreshProjectSecret

func (ot *OpenTok) RefreshProjectSecret(projectAPIKey string) (*Project, error)

RefreshProjectSecret generates a new API secret for a project.

Example
project, err := ot.RefreshProjectSecret("40000001")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", project)
}

// &opentok.Project{
// 	ID:                     "40000001",
// 	Secret:                 "6a1e361fc002c0b2b51a821d7ce11f96e1887aea",
// 	Status:                 "ACTIVE",
// 	Name:                   "example",
// 	CreatedAt:              1579163008000,
// 	EnvironmentName:        "default",
// 	EnvironmentDescription: "Standard Environment",
// }
Output:

func (*OpenTok) RefreshProjectSecretContext added in v2.1.0

func (ot *OpenTok) RefreshProjectSecretContext(ctx context.Context, projectAPIKey string) (*Project, error)

RefreshProjectSecretContext uses ctx for HTTP requests.

func (*OpenTok) SendConnectionSignal

func (ot *OpenTok) SendConnectionSignal(sessionID, connectionID string, data *SignalData) error

SendConnectionSignal send signals to a specific client in an active OpenTok session.

Example
err := ot.SendConnectionSignal("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", "18145975-97c8-4802-8975-fc8408d56d5c", &opentok.SignalData{
	Type: "foo",
	Data: "bar",
})
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) SendConnectionSignalContext added in v2.1.0

func (ot *OpenTok) SendConnectionSignalContext(ctx context.Context, sessionID, connectionID string, data *SignalData) error

SendConnectionSignalContext uses ctx for HTTP requests.

func (*OpenTok) SendDTMF added in v2.3.0

func (ot *OpenTok) SendDTMF(sessionID string, digits string) error

SendDTMF sends the DTMF digits to all clients connected to the session.

Example
err := ot.SendDTMF("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", "1713")
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) SendDTMFContext added in v2.3.0

func (ot *OpenTok) SendDTMFContext(ctx context.Context, sessionID, digits string) error

SendDTMFContext uses ctx for HTTP requests.

func (*OpenTok) SendDTMFToClient added in v2.3.0

func (ot *OpenTok) SendDTMFToClient(sessionID, connectionID, digits string) error

SendDTMFToClient sends the DTMF tones to a specific client connected to the session.

Example
err := ot.SendDTMFToClient("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", "3a6aa409-bfc5-462c-a9c7-59b72aeebf69", "1713")
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) SendDTMFToClientContext added in v2.3.0

func (ot *OpenTok) SendDTMFToClientContext(ctx context.Context, sessionID, connectionID, digits string) error

SendDTMFToClientContext uses ctx for HTTP requests.

func (*OpenTok) SendSessionSignal

func (ot *OpenTok) SendSessionSignal(sessionID string, data *SignalData) error

SendSessionSignal send signals to all participants in an active OpenTok session.

Example
err := ot.SendSessionSignal("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.SignalData{
	Type: "foo",
	Data: "bar",
})
if err != nil {
	fmt.Println(err)
}
Output:

func (*OpenTok) SendSessionSignalContext added in v2.1.0

func (ot *OpenTok) SendSessionSignalContext(ctx context.Context, sessionID string, data *SignalData) error

SendSessionSignalContext uses ctx for HTTP requests.

func (*OpenTok) SetAPIHost

func (ot *OpenTok) SetAPIHost(url string) error

SetAPIHost is used to set the OpenTok API Host to specific URL.

func (*OpenTok) SetArchiveLayout

func (ot *OpenTok) SetArchiveLayout(archiveID string, layout *Layout) (*Archive, error)

SetArchiveLayout dynamically change the layout type of a composed archive while it is being recorded.

Example
archive, err := ot.SetArchiveLayout("c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea", &opentok.Layout{
	Type: opentok.BestFit,
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", archive)
}

// &opentok.Archive{
// 	CreatedAt:  1579163008000,
// 	Duration:   0,
// 	HasAudio:   true,
// 	HasVideo:   true,
// 	ID:         "c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea",
// 	Name:       "example",
// 	OutputMode: "composed",
// 	ProjectID:  40000001,
// 	Reason:     "",
// 	Resolution: "1280x720",
// 	SessionID:  "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	Size:       0,
// 	Status:     "started",
// 	URL:        nil,
// }
Output:

func (*OpenTok) SetArchiveLayoutContext added in v2.1.0

func (ot *OpenTok) SetArchiveLayoutContext(ctx context.Context, archiveID string, layout *Layout) (*Archive, error)

SetArchiveLayoutContext uses ctx for HTTP requests.

func (*OpenTok) SetArchiveStorage

func (ot *OpenTok) SetArchiveStorage(opts *StorageOptions) (*StorageOptions, error)

SetArchiveStorage let you can have OpenTok upload completed archives to an Amazon S3 bucket (or an S3-compliant storage provider) or Microsoft Azure container.

Example
storageConfig, err := ot.SetArchiveStorage(&opentok.StorageOptions{
	Type: "s3",
	Config: &opentok.AmazonS3Config{
		AccessKey: "myUsername",
		SecretKey: "myPassword",
		Bucket:    "example",
	},
	Fallback: "none",
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", storageConfig)
}

// &opentok.StorageOptions{
// 	Type:   "s3",
// 	Config: map[string]interface {}{
// 		"accessKey": "myUsername",
// 		"bucket":    "example",
// 		"secretKey": "myPassword"
// 	},
// 	Fallback: "none",
// }
Output:

func (*OpenTok) SetArchiveStorageContext added in v2.1.0

func (ot *OpenTok) SetArchiveStorageContext(ctx context.Context, opts *StorageOptions) (*StorageOptions, error)

SetArchiveStorageContext uses ctx for HTTP requests.

func (*OpenTok) SetBroadcastLayout

func (ot *OpenTok) SetBroadcastLayout(broadcastID string, layout *Layout) (*Broadcast, error)

SetBroadcastLayout dynamically changes the layout type of a live streaming broadcast.

Example
broadcast, err := ot.SetBroadcastLayout("ce872e0d-4997-440a-a0a5-10ce715b54cf", &opentok.Layout{
	Type: opentok.BestFit,
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", broadcast)
}

// &opentok.Broadcast{
// 	ID:            "ce872e0d-4997-440a-a0a5-10ce715b54cf",
// 	SessionID:     "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	ProjectID:     "40000001",
// 	CreatedAt:     1579163008000,
// 	UpdatedAt:     1579163008000,
// 	Resolution:    "1280x720",
// 	Status:        "started",
// 	BroadcastURLs: &opentok.BroadcastURLs{
// 		HLS: "",
// 		RTMP:[]*opentok.RTMPConfig{
// 			&opentok.RTMPConfig{
// 				ID:         "foo",
// 				Status:     "connecting",
// 				ServerURL:  "rtmps://myfooserver/myfooapp",
// 				StreamName: "myfoostream"
// 			},
// 			&opentok.RTMPConfig{
// 				ID:         "bar",
// 				Status:     "connecting",
// 				ServerURL:  "rtmp://mybarserver/mybarapp",
// 				StreamName: "mybarstream"
// 			},
// 		},
// 	},
// }
Output:

func (*OpenTok) SetBroadcastLayoutContext added in v2.1.0

func (ot *OpenTok) SetBroadcastLayoutContext(ctx context.Context, broadcastID string, layout *Layout) (*Broadcast, error)

SetBroadcastLayoutContext uses ctx for HTTP requests.

func (*OpenTok) SetHTTPClient added in v2.3.1

func (ot *OpenTok) SetHTTPClient(client HTTPClient)

SetHTTPClient specifies http client, http.DefaultClient used by default.

func (*OpenTok) SetStreamClassLists

func (ot *OpenTok) SetStreamClassLists(sessionID string, opts *StreamClassOptions) (*StreamList, error)

SetStreamClassLists changes the composed archive layout classes for an OpenTok stream

Example
streams, err := ot.SetStreamClassLists("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.StreamClassOptions{
	Items: []*opentok.StreamClass{
		{
			ID:              "d962b966-964d-4f18-be3f-e0b181a43b0e",
			LayoutClassList: []string{"full"},
		},
	},
})

if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", streams)
}

// &opentok.StreamList{
// 	Count:1,
// 	Items:[]*opentok.Stream{
// 		&opentok.Stream{
// 			ID:              "d962b966-964d-4f18-be3f-e0b181a43b0e",
// 			VideoType:       "camera",
// 			Name:            "",
// 			LayoutClassList: []string{"full"}
// 		}
// 	}
// }
Output:

func (*OpenTok) SetStreamClassListsContext added in v2.1.0

func (ot *OpenTok) SetStreamClassListsContext(ctx context.Context, sessionID string, opts *StreamClassOptions) (*StreamList, error)

SetStreamClassListsContext uses ctx for HTTP requests.

func (*OpenTok) StartArchive

func (ot *OpenTok) StartArchive(sessionID string, opts *ArchiveOptions) (*Archive, error)

StartArchive starts the recording of the archive.

To successfully start recording an archive, at least one client must be connected to the session. You can only record one archive at a time for a given session. You can only record archives of sessions that use the OpenTok Media Router.

Example
archive, err := ot.StartArchive("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.ArchiveOptions{
	Name: "example",
	Layout: &opentok.Layout{
		Type: opentok.PIP,
	},
	Resolution: opentok.HD,
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", archive)
}

// &opentok.Archive{
// 	CreatedAt:  1579163008000,
// 	Duration:   0,
// 	HasAudio:   true,
// 	HasVideo:   true,
// 	ID:         "c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea",
// 	Name:       "example",
// 	OutputMode: "composed",
// 	ProjectID:  40000001,
// 	Reason:     "",
// 	Resolution: "1280x720",
// 	SessionID:  "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	Size:       0,
// 	Status:     "started",
// 	URL:        nil,
// }
Output:

func (*OpenTok) StartArchiveContext added in v2.1.0

func (ot *OpenTok) StartArchiveContext(ctx context.Context, sessionID string, opts *ArchiveOptions) (*Archive, error)

StartArchiveContext uses ctx for HTTP requests.

func (*OpenTok) StartBroadcast

func (ot *OpenTok) StartBroadcast(sessionID string, opts *BroadcastOptions) (*Broadcast, error)

StartBroadcast starts a live streaming for an OpenTok session. This broadcasts the session to an HLS (HTTP live streaming) or to RTMP streams.

Example
broadcast, err := ot.StartBroadcast("1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4", &opentok.BroadcastOptions{
	Layout: &opentok.Layout{
		Type: opentok.PIP,
	},
	MaxDuration: 60,
	Outputs: &opentok.BroadcastOutputOptions{
		RTMP: []*opentok.RTMPConfig{
			{
				ID:         "foo",
				ServerURL:  "rtmps://myfooserver/myfooapp",
				StreamName: "myfoostream",
			},
			{
				ID:         "bar",
				ServerURL:  "rtmp://mybarserver/mybarapp",
				StreamName: "mybarstream",
			},
		},
	},
	Resolution: opentok.HD,
})
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", broadcast)
}

// &opentok.Broadcast{
// 	ID:            "ce872e0d-4997-440a-a0a5-10ce715b54cf",
// 	SessionID:     "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	ProjectID:     "40000001",
// 	CreatedAt:     1579163008000,
// 	UpdatedAt:     1579163008000,
// 	Resolution:    "1280x720",
// 	Status:        "started",
// 	BroadcastURLs: &opentok.BroadcastURLs{
// 		HLS: "",
// 		RTMP:[]*opentok.RTMPConfig{
// 			&opentok.RTMPConfig{
// 				ID:         "foo",
// 				Status:     "connecting",
// 				ServerURL:  "rtmps://myfooserver/myfooapp",
// 				StreamName: "myfoostream"
// 			},
// 			&opentok.RTMPConfig{
// 				ID:         "bar",
// 				Status:     "connecting",
// 				ServerURL:  "rtmp://mybarserver/mybarapp",
// 				StreamName: "mybarstream"
// 			},
// 		},
// 	},
// }
Output:

func (*OpenTok) StartBroadcastContext added in v2.1.0

func (ot *OpenTok) StartBroadcastContext(ctx context.Context, sessionID string, opts *BroadcastOptions) (*Broadcast, error)

StartBroadcastContext uses ctx for HTTP requests.

func (*OpenTok) StopArchive

func (ot *OpenTok) StopArchive(archiveID string) (*Archive, error)

StopArchive stops the recording of the archive.

Archives stop recording after 2 hours (120 minutes), or 60 seconds after the last client disconnects from the session, or 60 minutes after the last client stops publishing.

Example
archive, err := ot.StopArchive("c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", archive)
}

// &opentok.Archive{
// 	CreatedAt:  1579163008000,
// 	Duration:   0,
// 	HasAudio:   true,
// 	HasVideo:   true,
// 	ID:         "c9c87fbb-f91b-49bf-a6b4-fd0dbe16caea",
// 	Name:       "example",
// 	OutputMode: "composed",
// 	ProjectID:  40000001,
// 	Reason:     "user initiated",
// 	Resolution: "1280x720",
// 	SessionID:  "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	Size:       0,
// 	Status:     "stopped",
// 	URL:        nil,
// }
Output:

func (*OpenTok) StopArchiveContext added in v2.1.0

func (ot *OpenTok) StopArchiveContext(ctx context.Context, archiveID string) (*Archive, error)

StopArchiveContext uses ctx for HTTP requests.

func (*OpenTok) StopBroadcast

func (ot *OpenTok) StopBroadcast(broadcastID string) (*Broadcast, error)

StopBroadcast stops a live broadcast of an OpenTok session. Note that broadcasts automatically stop 120 minutes after they are started.

Example
broadcast, err := ot.StopBroadcast("ce872e0d-4997-440a-a0a5-10ce715b54cf")
if err != nil {
	fmt.Println(err)
} else {
	fmt.Printf("%#v", broadcast)
}

// &opentok.Broadcast{
// 	ID:            "ce872e0d-4997-440a-a0a5-10ce715b54cf",
// 	SessionID:     "1_QX90NjQ2MCY0Nm6-MTU4QTO4NzE5NTkyOX4yUy2OZndKQExJR0NyalcvNktmTzBpSnp-QX4",
// 	ProjectID:     40000001,
// 	CreatedAt:     1579163008000,
// 	UpdatedAt:     1579163009000,
// 	Resolution:    "1280x720",
// 	Status:        "stopped",
// 	BroadcastURLs: nil,
// }
Output:

func (*OpenTok) StopBroadcastContext added in v2.1.0

func (ot *OpenTok) StopBroadcastContext(ctx context.Context, broadcastID string) (*Broadcast, error)

StopBroadcastContext uses ctx for HTTP requests.

type Project

type Project struct {
	// The OpenTok project API key.
	ID string `json:"id"`

	// The OpenTok project API secret.
	Secret string `json:"secret"`

	// Whether the project is active ("VALID", "ACTIVE") or suspended ("SUSPENDED").
	Status string `json:"status"`

	// The name, if you specified one when creating the project; or an empty
	// string if you did not specify a name.
	Name string `json:"name"`

	// The time at which the project was created (a UNIX timestamp, in milliseconds).
	CreatedAt int `json:"createdAt"`

	// The environment name that project is running on.
	EnvironmentName string `json:"environmentName"`

	// The environment description that project is running on.
	EnvironmentDescription string `json:"environmentDescription"`
}

Project defines the response returned from API.

type ProjectStatus

type ProjectStatus string

ProjectStatus is the alias of string type.

const (
	// ProjectActive is used to set the project API key to ACTIVE.
	ProjectActive ProjectStatus = "ACTIVE"

	// ProjectSuspended is used to set the project API key to SUSPENDED, you will
	// not be able to use the project API key (and any OpenTok sessions created
	// with it).
	ProjectSuspended ProjectStatus = "SUSPENDED"
)

type RTMPConfig

type RTMPConfig struct {
	// An unique ID for the stream.
	ID string `json:"id"`

	// RTMP stream status returned in the response.
	Status string `json:"status,omitempty"`

	// The RTMP server URL.
	ServerURL string `json:"serverUrl"`

	// The stream name, such as the YouTube Live stream name or the Facebook
	// stream key.
	StreamName string `json:"streamName"`
}

RTMPConfig defines the config of RTMP.

type Resolution

type Resolution string

Resolution is the alias of string type.

const (
	// SDLandscape (640x480-pixel) archives have a 4:3 aspect ratio, the default.
	//
	// Deprecated: use SDLandscape instead.
	SD Resolution = "640x480"

	// HDLandscape (1280x720-pixel) archives have a 16:9 aspect ratio.
	//
	// Deprecated: use HDLandscape instead.
	HD Resolution = "1280x720"

	// SDLandscape (640x480-pixel) archives have a 4:3 aspect ratio, the default.
	SDLandscape Resolution = "640x480"

	// HDLandscape (1280x720-pixel) archives have a 16:9 aspect ratio.
	HDLandscape Resolution = "1280x720"

	// SDPortrait (480x640-pixel) archives have a 3:4 aspect ratio.
	SDPortrait Resolution = "480x640"

	// HDPortrait (720x1280-pixel) archives have a 9:16 aspect ratio.
	HDPortrait Resolution = "720x1280"
)

The resolution of the archive, either SDLandscape(default), HDLandscape, SDPortrait or HDPortrait.

type ResponseError added in v2.3.1

type ResponseError struct {
	// StatusCode is the HTTP Response StatusCode that led to the error.
	StatusCode int

	// Message is the error message.
	Message string `json:"message"`
}

ResponseError encloses an error with code and message.

func (*ResponseError) Error added in v2.3.1

func (e *ResponseError) Error() string

Error returns a formatted error message.

type Role

type Role string

Role is the alias of string type.

const (
	// Publisher can publish streams, subscribe to streams, and signal.
	Publisher Role = "publisher"

	// Subscriber can only subscribe to streams.
	Subscriber Role = "subscriber"

	// Moderator can call the forceUnpublish() and forceDisconnect() method of
	// the Session object in clients using the OpenTok.js library, and have the
	// privileges granted to a publisher.
	Moderator Role = "moderator"
)

type SIP

type SIP struct {
	// The SIP URI to be used as destination of the SIP call initiated from
	// OpenTok to your SIP platform.
	URI string `json:"uri"`

	// The number or string that will be sent to the final SIP number as the
	// caller.
	From string `json:"from,omitempty"`

	// Custom headers to be added to the SIP ​INVITE​ request initiated from
	// OpenTok to your SIP platform.
	Headers *SIPHeaders `json:"headers,omitempty"`

	// The username and password to be used in the the SIP INVITE​ request for
	// HTTP digest authentication
	Auth *SIPAuth `json:"auth,omitempty"`

	// A flag that indicates whether the media must be transmitted encrypted
	// or not.
	Secure bool `json:"secure,omitempty"`
}

SIP defines the information of SIP call

type SIPAuth

type SIPAuth struct {
	// The username for HTTP digest authentication
	Username string `json:"username"`

	// The password for HTTP digest authentication
	Password string `json:"password"`
}

SIPAuth defines the authentication information for SIP call

type SIPCall

type SIPCall struct {
	// A unique ID for the SIP call.
	ID string `json:"id"`

	// The OpenTok connection ID for the SIP call's connection in the OpenTok
	// session.
	ConnectionID string `json:"connectionId"`

	// The OpenTok stream ID for the SIP call's stream in the OpenTok session.
	StreamID string `json:"streamId"`
}

SIPCall defines the response returned from API

type SIPHeaders

type SIPHeaders map[string]string

SIPHeaders is the alias of map[string]string type

type Session

type Session struct {
	// The session ID.
	SessionID string `json:"session_id"`

	// The API key associated with the project.
	ProjectID string `json:"project_id"`

	// The time at which the session was created.
	CreateDt string `json:"create_dt"`

	// The URL of the OpenTok media router used by the session.
	MediaServerURL string `json:"media_server_url"`

	// The instance of OpenTok.
	OpenTok *OpenTok `json:"-"`
}

Session defines the response returned from API.

func (*Session) Dial added in v2.3.0

func (s *Session) Dial(opts *DialOptions) (*SIPCall, error)

Dial connects your SIP platform to an OpenTok session.

func (*Session) DialContext added in v2.3.0

func (s *Session) DialContext(ctx context.Context, opts *DialOptions) (*SIPCall, error)

DialContext uses ctx for HTTP requests.

func (*Session) GenerateToken

func (s *Session) GenerateToken(opts *TokenOptions) (string, error)

GenerateToken generates a token for each user connecting to an OpenTok session.

func (*Session) Mute added in v2.3.0

func (s *Session) Mute(opts *MuteOptions) (*Project, error)

Mute force all force all streams (except for an optional list of streams) in a session to mute published audio.

func (*Session) MuteContext added in v2.3.0

func (s *Session) MuteContext(ctx context.Context, opts *MuteOptions) (*Project, error)

MuteContext uses ctx for HTTP requests.

func (*Session) MuteStream added in v2.3.0

func (s *Session) MuteStream(streamID string) (*Project, error)

MuteStream force a publisher of a specific stream to mute its audio.

func (*Session) MuteStreamContext added in v2.3.0

func (s *Session) MuteStreamContext(ctx context.Context, streamID string) (*Project, error)

MuteStreamContext uses ctx for HTTP requests.

func (*Session) SendConnectionSignal added in v2.3.0

func (s *Session) SendConnectionSignal(connectionID string, data *SignalData) error

SendConnectionSignal send signals to a specific client.

func (*Session) SendConnectionSignalContext added in v2.3.0

func (s *Session) SendConnectionSignalContext(ctx context.Context, connectionID string, data *SignalData) error

SendConnectionSignalContext uses ctx for HTTP requests.

func (*Session) SendDTMF added in v2.3.0

func (s *Session) SendDTMF(digits string) error

SendDTMF sends the DTMF digits to all clients connected to the session.

func (*Session) SendDTMFContext added in v2.3.0

func (s *Session) SendDTMFContext(ctx context.Context, digits string) error

SendDTMFContext uses ctx for HTTP requests.

func (*Session) SendDTMFToClient added in v2.3.0

func (s *Session) SendDTMFToClient(connectionID, digits string) error

SendDTMFToClient sends the DTMF tones to a specific client connected to the session.

func (*Session) SendDTMFToClientContext added in v2.3.0

func (s *Session) SendDTMFToClientContext(ctx context.Context, connectionID, digits string) error

SendDTMFToClientContext uses ctx for HTTP requests.

func (*Session) SendSignal added in v2.3.0

func (s *Session) SendSignal(data *SignalData) error

SendSignal send signals to all participants.

func (*Session) SendSignalContext added in v2.3.0

func (s *Session) SendSignalContext(ctx context.Context, data *SignalData) error

SendSignalContext uses ctx for HTTP requests.

type SessionIDInfo

type SessionIDInfo struct {
	// The API key associated with the project.
	APIKey string

	// The IP address that TokBox use to situate the session in its global
	// network.
	Location string

	// The time at which the session was created.
	CreateTime time.Time
}

SessionIDInfo defines the information decoded from the session ID.

type SessionOptions

type SessionOptions struct {
	// Set to always to have the session archived automatically.
	// With the archiveModeset to manual (the default), you can archive the
	// session by calling the REST /archive POST method.
	ArchiveMode ArchiveMode

	// The IP address that TokBox will use to situate the session in its global
	// network.
	Location string

	// Set to enabled if you prefer clients to attempt to send audio-video
	// streams directly to other clients; set to disabled for sessions that use
	// the OpenTok Media Router.
	MediaMode MediaMode
}

SessionOptions defines the options for creating a session.

type SignalData

type SignalData struct {
	// The type of the signal.
	// This is a string value that clients can filter on when listening for signals
	Type string `json:"type"`

	// The data of the signal
	Data string `json:"data"`
}

SignalData defines the type and data of signal

type StorageOptions

type StorageOptions struct {
	// Type of upload target.
	Type StorageType `json:"type"`

	// Settings for the target.
	Config interface{} `json:"config"`

	// Set this to "opentok" to have the archive available at the OpenTok
	// dashboard if upload fails.
	// Set this to "none" (or omit the property) to prevents archive files from
	// being stored in the OpenTok cloud if the upload fails.
	Fallback string `json:"fallback,omitempty"`
}

StorageOptions defines the options for setting archiving upload target.

type StorageType added in v2.3.0

type StorageType string

StorageType is the alias of string type.

const (
	// Azure specifies the Azure storage type
	Azure StorageType = "azure"

	// S3 specifies the Amazon S3 storage type
	S3 StorageType = "s3"
)

type Stream

type Stream struct {
	// The unique stream ID.
	ID string `json:"id"`

	// Either "camera" or "screen".
	VideoType string `json:"videoType"`

	// The stream name.
	Name string `json:"name"`

	// An array of the layout classes for the stream.
	LayoutClassList []string `json:"layoutClassList"`
}

Stream defines the response returned from API

type StreamClass

type StreamClass struct {
	// The stream ID.
	ID string `json:"id"`

	// An array of layout classes (each strings) for the stream.
	LayoutClassList []string `json:"layoutClassList"`
}

StreamClass defines the layout classes to assign to a stream.

type StreamClassOptions

type StreamClassOptions struct {
	// The layout classes to assign to a stream.
	Items []*StreamClass `json:"items"`
}

StreamClassOptions defines the options for setting the layout classes for the stream

type StreamList

type StreamList struct {
	// The total number of streams in a session.
	Count int `json:"count"`

	// An array of objects defining each stream retrieved.
	// Streams are listed from the newest to the oldest in the return set.
	Items []*Stream `json:"items"`
}

StreamList defines the response returned from API

type TokenOptions

type TokenOptions struct {
	// The role to determine the capabilities of the client that connects with
	// a token.
	Role Role

	// The metadata for describing the client.
	Data string

	// The expiration period of the token.
	ExpireTime int64

	// Layout classes for the stream.
	InitialLayoutClassList []string
}

TokenOptions defines the options for generating token.

Jump to

Keyboard shortcuts

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