-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ts-sdk] Make react sdk run on browser
- Loading branch information
Showing
47 changed files
with
962 additions
and
36,770 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { loadWasmModule } from './wasm'; | ||
export * from './renderer'; | ||
export * from './api'; |
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
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
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
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { ApiClient, ApiRequest } from './api'; | ||
export { LiveCompositor } from './compositor'; | ||
export { CompositorManager } from './compositorManager'; | ||
export { RegisterInputRequest } from './api/input'; | ||
export { RegisterOutputRequest, RegisterBytesOutput } from './api/output'; |
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
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
"outDir": "dist", | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"target": "ESNext" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
"outDir": "dist", | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"target": "ESNext" | ||
} | ||
} |
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,25 @@ | ||
{ | ||
"name": "@live-compositor/web", | ||
"version": "0.1.0-rc.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"lint": "eslint .", | ||
"typecheck": "tsc --noEmit", | ||
"watch": "tsc --watch --preserveWatchOutput", | ||
"build": "tsc", | ||
"clean": "rimraf dist", | ||
"prepublishOnly": "npm run clean && npm run build" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"files": [ | ||
"/dist" | ||
], | ||
"dependencies": { | ||
"@live-compositor/browser-render": "0.1.0-rc.4", | ||
"@live-compositor/core": "0.1.0-rc.5", | ||
"live-compositor": "^0.1.0-rc.5", | ||
"mp4box": "^0.5.2" | ||
} | ||
} |
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,89 @@ | ||
import { Renderer } from '@live-compositor/browser-render'; | ||
import { LiveCompositor as CoreLiveCompositor } from '@live-compositor/core'; | ||
import WasmInstance from './manager/wasmInstance'; | ||
import { Queue, StopQueueFn } from './queue'; | ||
import { EventSender } from './eventSender'; | ||
import { intoRegisterOutput, RegisterOutput } from './output/registerOutput'; | ||
import { Output } from './output/output'; | ||
import { intoRegisterInput, RegisterInput } from './input/registerInput'; | ||
import { Input } from './input/input'; | ||
import { RegisterImage } from './renderers'; | ||
|
||
export type LiveCompositorOptions = { | ||
framerate: Framerate; | ||
streamFallbackTimeoutMs: number; | ||
}; | ||
|
||
export type Framerate = { | ||
num: number; | ||
den: number; | ||
}; | ||
|
||
export default class LiveCompositor { | ||
private coreCompositor: CoreLiveCompositor; | ||
private queue: Queue; | ||
private renderer: Renderer; | ||
private eventSender?: EventSender; | ||
|
||
private constructor(renderer: Renderer, framerate: Framerate) { | ||
this.coreCompositor = new CoreLiveCompositor( | ||
new WasmInstance({ | ||
renderer: renderer, | ||
onRegisterCallback: cb => { | ||
this.eventSender = new EventSender(cb); | ||
}, | ||
}) | ||
); | ||
this.queue = new Queue(framerate, renderer); | ||
this.renderer = renderer; | ||
} | ||
|
||
public static async create(options: LiveCompositorOptions): Promise<LiveCompositor> { | ||
const renderer = await Renderer.create({ | ||
streamFallbackTimeoutMs: options.streamFallbackTimeoutMs, | ||
}); | ||
const compositor = new LiveCompositor(renderer, options.framerate); | ||
await compositor.coreCompositor.init(); | ||
return compositor; | ||
} | ||
|
||
public async registerOutput(outputId: string, request: RegisterOutput): Promise<void> { | ||
await this.coreCompositor.registerOutput(outputId, intoRegisterOutput(request)); | ||
const output = Output.create(request); | ||
this.queue.addOutput(outputId, output); | ||
} | ||
|
||
public async unregisterOutput(outputId: string): Promise<void> { | ||
await this.coreCompositor.unregisterOutput(outputId); | ||
this.queue.removeOutput(outputId); | ||
} | ||
|
||
public async registerInput(inputId: string, request: RegisterInput): Promise<void> { | ||
await this.coreCompositor.registerInput(inputId, intoRegisterInput(request)); | ||
|
||
const input = Input.create(inputId, request, this.eventSender!); | ||
this.queue.addInput(inputId, input); | ||
input.start(); | ||
} | ||
|
||
public async unregisterInput(inputId: string): Promise<void> { | ||
await this.coreCompositor.unregisterInput(inputId); | ||
this.queue.removeInput(inputId); | ||
} | ||
|
||
public async registerImage(imageId: string, request: RegisterImage): Promise<void> { | ||
await this.coreCompositor.registerImage(imageId, request); | ||
} | ||
|
||
public async unregisterImage(imageId: string): Promise<void> { | ||
await this.coreCompositor.unregisterImage(imageId); | ||
} | ||
|
||
public async registerFont(fontUrl: string): Promise<void> { | ||
await this.renderer.registerFont(fontUrl); | ||
} | ||
|
||
public start(): StopQueueFn { | ||
return this.queue.start(); | ||
} | ||
} |
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 @@ | ||
import { InputId } from '@live-compositor/browser-render'; | ||
import { CompositorEventType } from 'live-compositor'; | ||
|
||
export class EventSender { | ||
private eventCallback: (event: object) => void; | ||
|
||
public constructor(eventCallback: (event: object) => void) { | ||
this.eventCallback = eventCallback; | ||
} | ||
|
||
public sendEvent(event: ApiEvent) { | ||
this.eventCallback(event); | ||
} | ||
} | ||
|
||
export type ApiEvent = | ||
| { | ||
type: CompositorEventType.VIDEO_INPUT_DELIVERED; | ||
input_id: InputId; | ||
} | ||
| { | ||
type: CompositorEventType.VIDEO_INPUT_PLAYING; | ||
input_id: InputId; | ||
}; |
Oops, something went wrong.