Skip to content

Version 2

Overview

The protocol is a TCP protocol on port 46899.

The header packet structure is defined as:

struct HEADER {
   uint32_t size; //Little Endian
   uint8_t opcode;
} header;

For a packet with no body, only the header is sent. In this case, size = 1.

When a body is attached, it has the following format.

struct BODY {
   uint8_t bytes[header.size - 1];
};

The body is a JSON string, encoded using UTF-8. Note the total packet size is max 32KB. Consequently, the maximum body size is 32000 - 1.

Opcode Name Description
0 None Not used
Play 1 Sender message to play a video, body is PlayMessage
Pause 2 Sender message to pause a video, no body
Resume 3 Sender message to resume a video, no body
Stop 4 Sender message to stop a video, no body
Seek 5 Sender message to seek, body is SeekMessage
PlaybackUpdate 6 Receiver message to notify an updated playback state, body is PlaybackUpdateMessage
VolumeUpdate 7 Receiver message to notify when the volume has changed, body is VolumeUpdateMessage
SetVolume 8 Sender message to change volume, body is SetVolumeMessage
PlaybackError 9 Server message to notify the sender a playback error happened, body is PlaybackErrorMessage
SetSpeed 10 Sender message to change playback speed, body is SetSpeedMessage
Version 11 Message to notify the other of the current version, body is VersionMessage
Ping 12 Message to get the other party to pong, no body
Pong 13 Message to respond to a ping from the other party, no body

Bodies

PlayMessage

export class PlayMessage {
    constructor(
        public container: String, //The MIME type (video/mp4)
        public url: String = null, //The URL to load (optional)
        public content: String = null, //The content to load (i.e. a DASH manifest, optional)
        public time: number = null, //The time to start playing in seconds
        public speed: number = null, //The factor to multiply playback speed by (defaults to 1.0)
        public headers: { [key: string]: string } = null //HTTP request headers to add to the play request Map<string, string>
    ) {}
}

SeekMessage

export class SeekMessage {
    constructor(
        public time: number //The time to seek to in seconds
    ) {}
}

PlaybackUpdateMessage

export class PlaybackUpdateMessage {
    constructor(
        public generationTime: number, //The time the packet was generated (unix time milliseconds)
        public time: number, //The current time playing in seconds
        public duration: number, //The duration in seconds
        public state: number, //The playback state
        public speed: number //The playback speed factor
    ) {}
}

The playback state are defined as follows.

Number Name
0 Idle
1 Playing
2 Paused

VolumeUpdateMessage

export class VolumeUpdateMessage {
    constructor(
        public generationTime: number, //The time the packet was generated (unix time milliseconds)
        public volume: number //The current volume (0-1)
    ) {}
}

SetVolumeMessage

export class SetVolumeMessage {
    constructor(
        public volume: number //The desired volume (0-1)
    ) {}
}

SetSpeedMessage

export class SetSpeedMessage {
    constructor(
        public speed: number //The factor to multiply playback speed by.
    ) {}
}

PlaybackErrorMessage

export class PlaybackErrorMessage {
    constructor(
        public message: string
    ) {}
}

VersionMessage

export class VersionMessage {
    constructor(
        public version: number
    ) {}
}