Skip to content

Latest commit

 

History

History
166 lines (115 loc) · 10.6 KB

File metadata and controls

166 lines (115 loc) · 10.6 KB

Streams

Overview

Available Operations

  • create - Create a new stream
  • list - Get all live streams

create

Creates a new RTMPS or SRT live stream in FastPix. When you create a stream, FastPix generates a unique streamKey and srtSecret that you can use with broadcasting software such as OBS to connect to FastPix RTMPS or SRT servers. Use SRT for live streaming in unstable network conditions, as it provides error correction and encryption for a more reliable and secure broadcast.

Leverage SRT for live streaming in environments with unstable networks, taking advantage of its error correction and encryption features for a resilient and secure broadcast.

How it works

  1. Send a POST request to this endpoint. You can configure the stream settings, including metadata (such as stream name and description), reconnectWindow (in case of disconnection), and privacy options (public or private).

  2. FastPix returns the stream details for both RTMPS and SRT configurations. These keys and IDs from the stream details are essential for connecting the broadcasting software to FastPix’s servers and transmitting the live stream to viewers.

  3. After the live stream is created, FastPix sends a POST request to your specified webhook endpoint with the event video.live_stream.created.

Example:

Imagine a gaming platform that allows users to live stream gameplay directly from their dashboard. The API creates a new stream, provides the necessary stream key, and sets it to "private" so that only specific viewers can access it.

Related guide: How to live stream

Note: In the examples below, package hello.world; is used for demonstration purposes. When creating your own Java files, ensure the package name matches your directory structure (e.g., if your file is at src/main/java/com/example/MyApp.java, use package com.example;).

Example Usage

// Package declaration - adjust to match your project's directory structure
package hello.world;

// Import required classes from the FastPix SDK
import java.lang.Exception;
import java.util.Map;
import io.fastpix.sdk.FastPixSDK;
import io.fastpix.sdk.models.components.*;
import io.fastpix.sdk.models.operations.CreateNewStreamResponse;
import io.fastpix.sdk.utils.JSON;

public class Application {

    public static void main(String[] args) throws Exception {

        FastPixSDK sdk = FastPixSDK.builder()
                .security(Security.builder()
                    .username("your-access-token")
                    .password("your-secret-key")
                    .build())
            .build();

        CreateLiveStreamRequest req = CreateLiveStreamRequest.builder()
                .playbackSettings(PlaybackSettings.builder()
                    .build())
                .inputMediaSettings(InputMediaSettings.builder()
                    .metadata(Map.ofEntries(
                        Map.entry("livestream_name", "fastpix_livestream")))
                    .build())
                .build();

        CreateNewStreamResponse res = sdk.streams().create()
                .request(req)
                .call();

        if (res.liveStreamResponseDTO().isPresent()) {
            var mapper = JSON.getMapper();
            mapper.enable(SerializationFeature.INDENT_OUTPUT);
            System.out.println(mapper.writeValueAsString(res.liveStreamResponseDTO().get()));
        }
    }
}

Parameters

Parameter Type Required Description
request CreateLiveStreamRequest ✔️ The request object to use for the request.

Response

CreateNewStreamResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*

list

Retrieves a list of all live streams associated with the current workspace. It provides an overview of both current and past live streams, including details like streamId, metadata, status, createdAt and more.

How it works

Use the access token and secret key related to the workspace in the request header. When called, the API provides a paginated response containing all the live streams in that specific workspace. This is helpful for retrieving a large volume of streams and managing content in bulk.

Example Usage

// Package declaration - adjust to match your project's directory structure
package hello.world;

// Import required classes from the FastPix SDK
import java.lang.Exception;
import com.fasterxml.jackson.databind.SerializationFeature;
import io.fastpix.sdk.FastPixSDK;
import io.fastpix.sdk.models.components.Security;
import io.fastpix.sdk.models.operations.GetAllStreamsResponse;
import io.fastpix.sdk.models.operations.OrderBy;
import io.fastpix.sdk.utils.JSON;

public class Application {

    public static void main(String[] args) throws Exception {

        FastPixSDK sdk = FastPixSDK.builder()
                .security(Security.builder()
                    .username("your-access-token")
                    .password("your-secret-key")
                    .build())
            .build();

        GetAllStreamsResponse res = sdk.streams().list()
                .limit(20L)
                .offset(1L)
                .orderBy(OrderBy.DESC)
                .call();

        if (res.getStreamsResponse().isPresent()) {
            var mapper = JSON.getMapper();
            mapper.enable(SerializationFeature.INDENT_OUTPUT);
            System.out.println(mapper.writeValueAsString(res.getStreamsResponse().get()));
        }
    }
}

Parameters

Parameter Type Required Description Example
limit Optional<Long> Limit specifies the maximum number of items to display per page. 20
offset Optional<Long> Offset determines the starting point for data retrieval within a paginated list. 1
orderBy Optional<OrderBy> The list of value can be order in two ways DESC (Descending) or ASC (Ascending). In case not specified, by default it will be DESC. desc

Response

GetAllStreamsResponse

Errors

Error Type Status Code Content Type
models/errors/APIException 4XX, 5XX */*