-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TS SDK #673
Merged
Merged
TS SDK #673
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: TS SDK check | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
paths: | ||
- "ts/**" | ||
pull_request: | ||
types: [opened, synchronize] | ||
paths: | ||
- "ts/**" | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "20" | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
${{ runner.os }}- | ||
|
||
- name: Install project dependencies | ||
working-directory: ./ts | ||
run: npm install | ||
|
||
- name: Build | ||
working-directory: ./ts | ||
run: npm run build | ||
|
||
- name: Lint code | ||
working-directory: ./ts | ||
run: npm run lint | ||
|
||
- name: Typecheck code | ||
working-directory: ./ts | ||
run: npm run typecheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:import/recommended", | ||
"plugin:import/typescript", | ||
"prettier" | ||
], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"rules": { | ||
"prettier/prettier": ["error"], | ||
"@typescript-eslint/no-explicit-any": [0, {}], | ||
"no-constant-condition": [0], | ||
"@typescript-eslint/no-unused-vars": [ | ||
"error", | ||
{ | ||
"args": "all", | ||
"argsIgnorePattern": "^_", | ||
"caughtErrors": "all", | ||
"caughtErrorsIgnorePattern": "^_", | ||
"destructuredArrayIgnorePattern": "^_", | ||
"varsIgnorePattern": "^_", | ||
"ignoreRestSiblings": true | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"bracketSameLine": true, | ||
"trailingComma": "es5", | ||
"arrowParens": "avoid", | ||
"endOfLine": "auto" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"../../.eslintrc.base.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "@live-compositor/core", | ||
"version": "0.1.0-rc.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"typecheck": "tsc --noEmit", | ||
"watch": "tsc --watch", | ||
"build": "tsc", | ||
"clean": "rimraf dist" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/react-reconciler": "0.28.8" | ||
}, | ||
"dependencies": { | ||
"react-reconciler": "0.29.2" | ||
}, | ||
"peerDependencies": { | ||
"live-compositor": "0.1.0-rc.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { Api } from 'live-compositor'; | ||
import { CompositorManager } from './compositorManager'; | ||
|
||
export { Api }; | ||
|
||
export type ApiRequest = { | ||
method: 'GET' | 'POST'; | ||
route: string; | ||
body?: object; | ||
}; | ||
|
||
export class ApiClient { | ||
private serverManager: CompositorManager; | ||
|
||
constructor(serverManager: CompositorManager) { | ||
this.serverManager = serverManager; | ||
} | ||
|
||
public async updateScene(outputId: string, request: Api.UpdateOutputRequest): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/output/${encodeURIComponent(outputId)}/update`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async registerOutput(outptuId: string, request: Api.RegisterOutput): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/output/${encodeURIComponent(outptuId)}/register`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async unregisterOutput(outptuId: string): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/output/${encodeURIComponent(outptuId)}/unregister`, | ||
body: {}, | ||
}); | ||
} | ||
|
||
public async registerInput(inputId: string, request: Api.RegisterInput): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/input/${encodeURIComponent(inputId)}/register`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async unregisterInput(inputId: string): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/input/${encodeURIComponent(inputId)}/unregister`, | ||
body: {}, | ||
}); | ||
} | ||
|
||
public async registerShader(shaderId: string, request: Api.ShaderSpec): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/shader/${encodeURIComponent(shaderId)}/register`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async unregisterShader(shaderId: string): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/shader/${encodeURIComponent(shaderId)}/unregister`, | ||
body: {}, | ||
}); | ||
} | ||
|
||
public async registerImage(imageId: string, request: Api.ImageSpec): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/image/${encodeURIComponent(imageId)}/register`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async unregisterImage(imageId: string): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/image/${encodeURIComponent(imageId)}/unregister`, | ||
body: {}, | ||
}); | ||
} | ||
|
||
public async registerWebRenderer( | ||
instanceId: string, | ||
request: Api.WebRendererSpec | ||
): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/web-renderer/${encodeURIComponent(instanceId)}/register`, | ||
body: request, | ||
}); | ||
} | ||
|
||
public async unregisterWebRenderer(instanceId: string): Promise<object> { | ||
return this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/web-renderer/${encodeURIComponent(instanceId)}/unregister`, | ||
body: {}, | ||
}); | ||
} | ||
|
||
public async start(): Promise<void> { | ||
await this.serverManager.sendRequest({ | ||
method: 'POST', | ||
route: `/api/start`, | ||
body: {}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Api } from '../api'; | ||
import { RegisterInput, Inputs } from 'live-compositor'; | ||
|
||
export function intoRegisterInput(input: RegisterInput): Api.RegisterInput { | ||
if (input.type === 'mp4') { | ||
return intoMp4RegisterInput(input); | ||
} else if (input.type === 'rtp_stream') { | ||
return intoRtpRegisterInput(input); | ||
} else { | ||
throw new Error(`Unknown input type ${(input as any).type}`); | ||
} | ||
} | ||
|
||
function intoMp4RegisterInput(input: Inputs.RegisterMp4Input): Api.RegisterInput { | ||
return { | ||
type: 'mp4', | ||
url: input.url, | ||
path: input.path, | ||
required: input.required, | ||
offset_ms: input.offsetMs, | ||
}; | ||
} | ||
|
||
function intoRtpRegisterInput(input: Inputs.RegisterRtpInput): Api.RegisterInput { | ||
return { | ||
type: 'rtp_stream', | ||
port: input.port, | ||
transport_protocol: input.transportProtocol, | ||
video: input.video, | ||
audio: input.audio && intoInputAudio(input.audio), | ||
required: input.required, | ||
offset_ms: input.offsetMs, | ||
}; | ||
} | ||
|
||
function intoInputAudio(audio: Inputs.InputRtpAudioOptions): Api.InputRtpAudioOptions { | ||
if (audio.decoder === 'opus') { | ||
return { | ||
decoder: 'opus', | ||
forward_error_correction: audio.forwardErrorCorrection, | ||
}; | ||
} else if (audio.decoder === 'aac') { | ||
return { | ||
decoder: 'aac', | ||
audio_specific_config: audio.audioSpecificConfig, | ||
rtp_mode: audio.rtpMode, | ||
}; | ||
} else { | ||
throw new Error(`Unknown audio decoder type: ${(audio as any).decoder}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { RegisterOutput, Api, Outputs } from 'live-compositor'; | ||
|
||
export function intoRegisterOutput( | ||
output: RegisterOutput, | ||
initialVideo?: Api.Video | ||
): Api.RegisterOutput { | ||
if (output.type === 'rtp_stream') { | ||
return intoRegisterRtpOutput(output, initialVideo); | ||
} else { | ||
throw new Error(`Unknown input type ${(output as any).type}`); | ||
} | ||
} | ||
|
||
function intoRegisterRtpOutput( | ||
output: Outputs.RegisterRtpOutput, | ||
initialVideo?: Api.Video | ||
): Api.RegisterOutput { | ||
return { | ||
type: 'rtp_stream', | ||
port: output.port, | ||
ip: output.ip, | ||
transport_protocol: output.transportProtocol, | ||
video: output.video && initialVideo && intoOutputRtpVideoOptions(output.video, initialVideo), | ||
audio: output.audio && intoOutputRtpAudioOptions(output.audio), | ||
}; | ||
} | ||
|
||
function intoOutputRtpVideoOptions( | ||
video: Outputs.OutputRtpVideoOptions, | ||
initial: Api.Video | ||
): Api.OutputRtpVideoOptions { | ||
return { | ||
resolution: video.resolution, | ||
send_eos_when: video.sendEosWhen && intoOutputEosCondition(video.sendEosWhen), | ||
encoder: intoVideoEncoderOptions(video.encoder), | ||
initial, | ||
}; | ||
} | ||
|
||
function intoVideoEncoderOptions(encoder: Outputs.VideoEncoderOptions): Api.VideoEncoderOptions { | ||
return { | ||
type: 'ffmpeg_h264', | ||
preset: encoder.preset, | ||
ffmpeg_options: encoder.ffmpegOptions, | ||
}; | ||
} | ||
|
||
function intoOutputRtpAudioOptions( | ||
audio: Outputs.OutputRtpAudioOptions | ||
): Api.OutputRtpAudioOptions { | ||
return { | ||
send_eos_when: audio.sendEosWhen && intoOutputEosCondition(audio.sendEosWhen), | ||
encoder: intoAudioEncoderOptions(audio.encoder), | ||
initial: intoAudioInputsConfiguration(audio.initial), | ||
}; | ||
} | ||
|
||
function intoAudioEncoderOptions(encoder: Outputs.AudioEncoderOptions): Api.AudioEncoderOptions { | ||
return { | ||
type: 'opus', | ||
preset: encoder.preset, | ||
channels: encoder.channels, | ||
}; | ||
} | ||
|
||
export function intoAudioInputsConfiguration(audio: Outputs.AudioInputsConfiguration): Api.Audio { | ||
return { | ||
inputs: audio.inputs.map(input => ({ | ||
input_id: input.inputId, | ||
volume: input.volume, | ||
})), | ||
}; | ||
} | ||
|
||
function intoOutputEosCondition(condition: Outputs.OutputEndCondition): Api.OutputEndCondition { | ||
if ('anyOf' in condition) { | ||
return { any_of: condition.anyOf }; | ||
} else if ('allOf' in condition) { | ||
return { all_of: condition.allOf }; | ||
} else if ('allInputs' in condition) { | ||
return { all_inputs: condition.allInputs }; | ||
} else if ('anyInput' in condition) { | ||
return { any_input: condition.anyInput }; | ||
} else { | ||
throw new Error('Invalid "send_eos_when" value.'); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add mp4 output