Skip to content
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

WIP: Experimental VEDA.js support #82

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Web-based P2P collaborative editor for live coding music and graphics
* Web Plugins, for languages embedded in editor:
- [Hydra](https://github.com/ojack/hydra)
- [p5.js](https://p5js.org/)
- [VEDA.js](https://github.com/fand/vedajs) (*not implemented yet*)
- [VEDA.js](https://github.com/fand/vedajs)
- [Tilt](https://github.com/munshkr/tilt) (*not implemented yet*)


Expand Down
38 changes: 0 additions & 38 deletions packages/web/components/HydraCanvas.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const HydraError = ({ children }) => (
const LocalError = ({ children }) => (
<>
<span className="error">{children}</span>
<style jsx>
Expand All @@ -17,4 +17,4 @@ const HydraError = ({ children }) => (
</>
);

export default HydraError;
export default LocalError;
7 changes: 6 additions & 1 deletion packages/web/components/Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import Mosaic from "./Mosaic";
import Audio from "./Audio";

const MAX_LINES: number = 100;
const LOCAL_TARGETS = ["hydra"];
const LOCAL_TARGETS = ["hydra", "veda"];

type Props = {
websocketsHost: string;
sessionName: string;
userName?: string;
onHydraEvaluation: (code: string) => void;
onVedaEvaluation: (code: string) => void;
audioStreamingEnabled: boolean;
extraIceServers?: IceServerType[];
layout: {
Expand Down Expand Up @@ -46,6 +47,7 @@ class Session extends Component<Props, State> {
static defaultProps = {
userName: "anonymous",
onHydraEvaluation: () => {},
onVedaEvaluation: () => {},
};

componentDidMount() {
Expand Down Expand Up @@ -141,6 +143,9 @@ class Session extends Component<Props, State> {
case "hydra":
this.props.onHydraEvaluation(body);
break;
case "veda":
this.props.onVedaEvaluation(body);
break;
default:
console.error("Unhandle local target:", target);
}
Expand Down
1 change: 1 addition & 0 deletions packages/web/components/TextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const modesByTarget = {
foxdot: "python",
sclang: "smalltalk",
hydra: "javascript",
veda: "javascript",
};

const EvaluateButton = ({ onClick }) => (
Expand Down
47 changes: 47 additions & 0 deletions packages/web/lib/VedaWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Veda from "vedajs";

export type ErrorHandler = (error: string) => void;

class VedaWrapper {
veda: any;
playing: boolean;
onError: ErrorHandler;

constructor(canvas: HTMLCanvasElement, onError: ErrorHandler) {
this.onError = onError || (() => {});
this.playing = false;

this.veda = new Veda();
this.veda.setCanvas(canvas);

// Wrap around Veda.render() function with a try/catch
// to gracefully handle shader program exceptions.
const vedaRender = this.veda.render;
this.veda.render = () => {
try {
vedaRender.apply(this.veda);
} catch (err) {
console.warn("VEDA ERROR", err);
// this.onError(err);
}
};
}

evalFragment(code: string) {
this.veda.loadFragmentShader(code);
this.play();
}

evalVertex(code: string) {
this.veda.loadVertexShader(code);
this.play();
}

play() {
if (this.playing) return;
this.veda.play();
this.playing = true;
}
}

export default VedaWrapper;
2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@fortawesome/react-fontawesome": "^0.1.8",
"@zeit/next-css": "^1.0.1",
"@zeit/next-sass": "^1.0.1",
"classnames": "^2.2.6",
"commander": "^2.20.0",
"cross-env": "^7.0.0",
"express": "^4.17.1",
Expand All @@ -33,6 +34,7 @@
"react": "^16.12.0",
"react-dom": "^16.12.0",
"simple-peer": "^9.6.2",
"vedajs": "^0.15.0",
"ws": "^7.0.1"
},
"devDependencies": {
Expand Down
Loading