question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hey, looking forward to using Mux in my project. It would be great if TypeScript typings could either be provided with the module, or in an @types/@mux/mux-node package. You’ve done a great job with the JSDoc comments, hopefully there’s an easy way to generate them from those.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ebelodedcommented, Jul 6, 2020

Here are some types I wrote to have some typing support in our project. Maybe this will be helpful:


type MuxUpdateUploadEventType =
  | 'video.upload.asset_created'
  | 'video.upload.created'
  | 'video.upload.cancelled'
  | 'video.upload.errored'
type MuxUpdateAssetEventType =
  | 'video.asset.created'
  | 'video.asset.ready'
  | 'video.asset.errored'
  | 'video.asset.deleted'
type MuxUpdateStaticAssetEventType = 'video.asset.static_renditions.ready'

interface VideoTrack {
  type: 'video'
  max_width: number
  max_height: number
  max_frame_rate: number
  id: string
  duration: number
}

interface AudioTrack {
  type: 'audio'
  max_channels: 2
  max_channel_layout: 'stereo'
  id: string
  duration: number
}
interface MuxUpdateData {
  id: string
}
interface MuxUploadUpdateData extends MuxUpdateData {
  new_asset_settings: {
    playback_policies: ['public']
    mp4_support: 'standard'
    passthrough?: string
  }
  status: 'waiting' | 'asset_created'
  url: string
  cors_origin: string
  timeout: number
}
interface MuxAssetUpdateDataShared extends MuxUpdateData {
  created_at: number
  mp4_support: 'standard' | 'none'
  master_access: 'none'
  passthrough: string
  playback_ids: Array<{ policy: 'public'; id: string }>
}
interface MuxAssetUpdateDataPreparing extends MuxAssetUpdateDataShared {
  status: 'preparing'
}
interface MuxAssetUpdateDataReady extends MuxAssetUpdateDataShared {
  status: 'ready'
  tracks: Array<VideoTrack | AudioTrack>
  duration: number
  aspect_ratio: string //'16:9'
  max_stored_resolution: 'HD' | 'SD'
  max_stored_frame_rate: number
}
type MuxAssetUpdateData = MuxAssetUpdateDataReady | MuxAssetUpdateDataPreparing

interface MuxUpdateShared {
  request_id: null
  id: string
  environment: {
    name: string
    id: string
  }
  created_at: string
  accessor_source: null
  accessor: null
  attempts: []
}

interface MuxUploadUpdate extends MuxUpdateShared {
  type: MuxUpdateUploadEventType
  object: {
    type: 'upload'
    id: string
  }
  data: MuxUploadUpdateData
}
interface MuxAssetUpdate extends MuxUpdateShared {
  type: MuxUpdateAssetEventType
  object: {
    type: 'asset'
    id: string
  }
  data: Asset
}

interface MuxAssetStaticUpdate extends MuxUpdateShared {
  type: MuxUpdateStaticAssetEventType
  data: Asset
}
type MuxUpdate = MuxUploadUpdate | MuxAssetUpdate | MuxAssetStaticUpdate

1reaction
cwqtcommented, Dec 14, 2020

Made something a bit simpler than what else is in here;

export declare enum MUXHook {
    VideoAssetCreated = "video.asset.created",
    VideoAssetReady = "video.asset.ready",
    VideoAssetErrored = "video.asset.errored",
    VideoAssetUpdated = "video.asset.updated",
    VideoAssetDeleted = "video.asset.deleted",
    StaticRendReady = "video.asset.static_renditions.ready",
    StaticRendPreparing = "video.asset.static_renditions.preparing",
    StaticRendDeleted = "video.asset.static_renditions.deleted",
    StaticRendErrored = "video.asset.static_renditions.errored",
    MasterReady = "video.asset.master.ready",
    MasterPreparing = "video.asset.master.preparing",
    MasterDeleted = "video.asset.master.deleted",
    MasterErrored = "video.asset.master.errored",
    TrackCreated = "video.asset.track.created",
    TrackReady = "video.asset.track.ready",
    TrackErrored = "video.asset.track.errored",
    TrackDeleted = "video.asset.track.deleted",
    UploadAssetCreated = "video.upload.asset_created",
    UploadCancelled = "video.upload.cancelled",
    UploadCreated = "video.upload.created",
    UploadErrored = "video.upload.errored",
    StreamCompleted = "video.asset.live_stream_completed",
    StreamCreated = "video.live_stream.created",
    StreamConnected = "video.live_stream.connected",
    StreamRecording = "video.live_stream.recording",
    StreamActive = "video.live_stream.active",
    StreamDisconnected = "video.live_stream.disconnected",
    StreamIdle = "video.live_stream.idle",
    StreamUpdated = "video.live_stream.updated",
    StreamEnabled = "video.live_stream.enabled",
    StreamDisabled = "video.live_stream.deleted"
}
export interface IMUXHookResponse<T> {
    type: MUXHook;
    created_at: Date;
    object: {
        type: "asset" | "track" | "upload" | "live" | "simulcast-target";
        id: string;
    };
    id: string;
    environment: {
        name: string;
        id: string;
    };
    data: T;
    attempts: Array<{
        address: string;
        created_at: Date;
        id: string;
        max_attempts: number;
        response_body: string;
        response_headers: object;
        reponse_status_code: number;
        webhook_id: number;
    }>;
}

Then alongside the built in types, IMUXHookResponse<LiveStream>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handbook - Basic Types - TypeScript
Basic Types · Boolean · Number · String · Array · Tuple · Enum · Unknown · Any.
Read more >
Documentation - Everyday Types - TypeScript
JavaScript has three very commonly used primitives: string , number , and boolean . Each has a corresponding type in TypeScript. As you...
Read more >
Documentation - Advanced Types - TypeScript
TypeScript has two special types, null and undefined , that have the values null and undefined respectively. We mentioned these briefly in the...
Read more >
Documentation - Object Types - TypeScript
In JavaScript, the fundamental way that we group and pass around data is through objects. In TypeScript, we represent those through object types....
Read more >
Documentation - Creating Types from Types - TypeScript
An overview of the ways in which you can create more types from existing types. ... TypeScript's type system is very powerful because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found