-
Notifications
You must be signed in to change notification settings - Fork 22
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
Clean up Fix `package-lock.json`
- Loading branch information
Showing
23 changed files
with
4,507 additions
and
2,705 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { ApiClient, ApiRequest } from './api'; | ||
export { LiveCompositor, createLiveCompositor } from './compositor'; | ||
export { CompositorManager } from './compositorManager'; | ||
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
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,24 @@ | ||
{ | ||
"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": "file:../browser-render", | ||
"@live-compositor/core": "0.1.0-rc.0", | ||
"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,63 @@ | ||
import { LiveCompositor as CoreLiveCompositor, CompositorManager } from '@live-compositor/core'; | ||
import WasmInstance from './manager/wasmInstance'; | ||
import { Api, RegisterInput, RegisterOutput } from 'live-compositor'; | ||
|
||
export { WasmInstance }; | ||
|
||
export default class LiveCompositor extends CoreLiveCompositor { | ||
private constructor(manager: CompositorManager) { | ||
super(manager); | ||
} | ||
|
||
public static async create(manager: CompositorManager): Promise<LiveCompositor> { | ||
const compositor = new LiveCompositor(manager); | ||
await compositor['setupInstance'](); | ||
return compositor; | ||
} | ||
|
||
public override async registerOutput(outputId: string, request: RegisterOutput): Promise<object> { | ||
if (request.type !== 'bytes') { | ||
throw `Output type "${request.type}" is unsupported on web`; | ||
} | ||
|
||
return super.registerOutput(outputId, request); | ||
} | ||
|
||
public override async registerInput(inputId: string, request: RegisterInput): Promise<object> { | ||
if (request.type !== 'bytes') { | ||
throw `Input type "${request.type}" is unsupported on web`; | ||
} | ||
|
||
return super.registerInput(inputId, request); | ||
} | ||
|
||
public override async registerImage(imageId: string, request: Api.ImageSpec): Promise<object> { | ||
if (request.path) { | ||
throw "Image's `path` field is not supported on web"; | ||
} | ||
|
||
return super.registerImage(imageId, request); | ||
} | ||
|
||
public override async registerShader( | ||
_shaderId: string, | ||
_request: Api.ShaderSpec | ||
): Promise<object> { | ||
throw 'Shaders are unsupported'; | ||
} | ||
|
||
public override async unregisterShader(_shaderId: string): Promise<object> { | ||
throw 'Shaders are unsupported'; | ||
} | ||
|
||
public override async registerWebRenderer( | ||
_instanceId: string, | ||
_request: Api.WebRendererSpec | ||
): Promise<object> { | ||
throw 'Web renderers are unsupported'; | ||
} | ||
|
||
public override async unregisterWebRenderer(_instanceId: string): Promise<object> { | ||
throw 'Web renderers are unsupported'; | ||
} | ||
} |
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,118 @@ | ||
import { ApiRequest, CompositorManager, RegisterOutputRequest } from '@live-compositor/core'; | ||
import { Renderer, Resolution, Component, ImageSpec } from '@live-compositor/browser-render'; | ||
import { Api } from 'live-compositor'; | ||
|
||
type Output = { | ||
resolution: Resolution; | ||
}; | ||
|
||
class WasmInstance implements CompositorManager { | ||
private renderer: Renderer; | ||
private outputs: Map<string, Output>; | ||
|
||
public constructor(renderer: Renderer) { | ||
this.renderer = renderer; | ||
this.outputs = new Map(); | ||
} | ||
|
||
public async setupInstance(): Promise<void> {} | ||
|
||
public async sendRequest(request: ApiRequest): Promise<object> { | ||
const paths = request.route.split('/'); | ||
if (paths.length < 3) { | ||
return {}; | ||
} | ||
|
||
switch (paths[2]) { | ||
case 'input': | ||
this.handleInputRequest(paths[3], paths[4]); | ||
break; | ||
case 'output': | ||
this.handleOutputRequest(paths[3], paths[4], request.body); | ||
break; | ||
case 'image': | ||
await this.handleImageRequest(paths[3], paths[4], request.body); | ||
break; | ||
case 'start': | ||
// TODO(noituri): Run queue | ||
break; | ||
case 'shader': | ||
throw 'Shaders are not supported'; | ||
case 'web-renderer': | ||
throw 'Web renderers are not supported'; | ||
default: | ||
throw 'Unknown request: ' + paths[2]; | ||
} | ||
return {}; | ||
} | ||
|
||
public registerEventListener(_cb: (event: unknown) => void): void {} | ||
|
||
private handleInputRequest(inputId: string, operation: string): void { | ||
switch (operation) { | ||
case 'register': | ||
this.renderer.registerInput(inputId); | ||
break; | ||
case 'unregister': | ||
this.renderer.unregisterInput(inputId); | ||
break; | ||
default: | ||
throw 'Unknown operation: ' + operation; | ||
} | ||
} | ||
|
||
private handleOutputRequest(outputId: string, operation: string, body?: object): void { | ||
switch (operation) { | ||
case 'register': { | ||
const outputInfo = body! as RegisterOutputRequest; | ||
if (outputInfo.video) { | ||
const resolution = outputInfo.video.resolution; | ||
this.outputs.set(outputId, { resolution: resolution }); | ||
this.renderer.updateScene( | ||
outputId, | ||
resolution, | ||
outputInfo.video?.initial.root as Component | ||
); | ||
} | ||
break; | ||
} | ||
case 'unregister': { | ||
this.renderer.unregisterOutput(outputId); | ||
break; | ||
} | ||
case 'update': { | ||
const scene = body! as Api.UpdateOutputRequest; | ||
if (!scene.video) { | ||
return; | ||
} | ||
const output = this.outputs.get(outputId); | ||
if (!output) { | ||
throw `Unknown output "${outputId}"`; | ||
} | ||
this.renderer.updateScene(outputId, output.resolution, scene.video.root as Component); | ||
break; | ||
} | ||
case 'request_keyframe': | ||
// Do nothing | ||
break; | ||
default: | ||
throw 'Unknown operation: ' + operation; | ||
} | ||
} | ||
|
||
private async handleImageRequest( | ||
imageId: string, | ||
operation: string, | ||
body?: object | ||
): Promise<void> { | ||
switch (operation) { | ||
case 'register': | ||
await this.renderer.registerImage(imageId, body as ImageSpec); | ||
break; | ||
case 'unregister': | ||
this.renderer.unregisterImage(imageId); | ||
} | ||
} | ||
} | ||
|
||
export default WasmInstance; |
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 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { | ||
"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 |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
*.tsbuildinfo | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
Oops, something went wrong.