-
Notifications
You must be signed in to change notification settings - Fork 18
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 (#776)
- Loading branch information
Showing
42 changed files
with
2,205 additions
and
1,280 deletions.
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 |
---|---|---|
@@ -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
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.js'; | ||
export { LiveCompositor } from './compositor.js'; | ||
export { CompositorManager } from './compositorManager.js'; | ||
export { RegisterInputRequest, RegisterInput } from './api/input.js'; | ||
export { RegisterOutputRequest, RegisterOutput } from './api/output.js'; |
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 |
---|---|---|
@@ -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,27 @@ | ||
{ | ||
"name": "@live-compositor/web-wasm", | ||
"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": { | ||
"@datastructures-js/queue": "^4.2.3", | ||
"@live-compositor/browser-render": "0.1.0-rc.4", | ||
"@live-compositor/core": "0.1.0", | ||
"live-compositor": "^0.1.0", | ||
"mp4box": "^0.5.2", | ||
"path-parser": "^6.1.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,86 @@ | ||
import { Renderer } from '@live-compositor/browser-render'; | ||
import { LiveCompositor as CoreLiveCompositor } from '@live-compositor/core'; | ||
import WasmInstance from './manager/wasmInstance'; | ||
import { intoRegisterOutput, RegisterOutput } from './output/registerOutput'; | ||
import { intoRegisterInput, RegisterInput } from './input/registerInput'; | ||
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 instance?: WasmInstance; | ||
private renderer?: Renderer; | ||
private options: LiveCompositorOptions; | ||
|
||
public constructor(options: LiveCompositorOptions) { | ||
this.options = options; | ||
} | ||
|
||
/* | ||
* Initializes LiveCompositor instance. It needs to be called before any resource is registered. | ||
* Outputs won't produce any results until `start()` is called. | ||
*/ | ||
public async init(): Promise<void> { | ||
this.renderer = await Renderer.create({ | ||
streamFallbackTimeoutMs: this.options.streamFallbackTimeoutMs ?? 500, | ||
}); | ||
this.instance = new WasmInstance({ | ||
renderer: this.renderer!, | ||
framerate: this.options.framerate ?? { num: 30, den: 1 }, | ||
}); | ||
this.coreCompositor = new CoreLiveCompositor(this.instance!); | ||
|
||
await this.coreCompositor!.init(); | ||
} | ||
|
||
public async registerOutput(outputId: string, request: RegisterOutput): Promise<void> { | ||
await this.coreCompositor!.registerOutput(outputId, intoRegisterOutput(request)); | ||
} | ||
|
||
public async unregisterOutput(outputId: string): Promise<void> { | ||
await this.coreCompositor!.unregisterOutput(outputId); | ||
} | ||
|
||
public async registerInput(inputId: string, request: RegisterInput): Promise<void> { | ||
await this.coreCompositor!.registerInput(inputId, intoRegisterInput(request)); | ||
} | ||
|
||
public async unregisterInput(inputId: string): Promise<void> { | ||
await this.coreCompositor!.unregisterInput(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); | ||
} | ||
|
||
/** | ||
* Starts processing pipeline. Any previously registered output will start producing video data. | ||
*/ | ||
public async start(): Promise<void> { | ||
await this.coreCompositor!.start(); | ||
} | ||
|
||
/** | ||
* Stops processing pipeline. | ||
*/ | ||
public stop(): void { | ||
this.instance!.stop(); | ||
} | ||
} |
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,62 @@ | ||
import { CompositorEvent, CompositorEventType } from 'live-compositor'; | ||
|
||
export class EventSender { | ||
private eventCallback?: (event: object) => void; | ||
|
||
public setEventCallback(eventCallback: (event: object) => void) { | ||
this.eventCallback = eventCallback; | ||
} | ||
|
||
public sendEvent(event: CompositorEvent) { | ||
if (!this.eventCallback) { | ||
console.warn(`Failed to send event: ${event}`); | ||
return; | ||
} | ||
|
||
this.eventCallback!(toWebSocketMessage(event)); | ||
} | ||
} | ||
|
||
function toWebSocketMessage(event: CompositorEvent): WebSocketMessage { | ||
if (event.type == CompositorEventType.OUTPUT_DONE) { | ||
return { | ||
type: event.type, | ||
output_id: event.outputId, | ||
}; | ||
} | ||
|
||
return { | ||
type: event.type, | ||
input_id: event.inputId, | ||
}; | ||
} | ||
|
||
export type WebSocketMessage = | ||
| { | ||
type: CompositorEventType.AUDIO_INPUT_DELIVERED; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.VIDEO_INPUT_DELIVERED; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.AUDIO_INPUT_PLAYING; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.VIDEO_INPUT_PLAYING; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.AUDIO_INPUT_EOS; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.VIDEO_INPUT_EOS; | ||
input_id: string; | ||
} | ||
| { | ||
type: CompositorEventType.OUTPUT_DONE; | ||
output_id: string; | ||
}; |
Oops, something went wrong.