Skip to content

Commit

Permalink
added few missing commands, like play sound and display text
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalacho-mit committed Apr 29, 2024
1 parent ea0b80d commit 3215ed7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 19 deletions.
4 changes: 4 additions & 0 deletions extensions/src/doodlebot/Doodlebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ export default class Doodlebot {
await this.sendWebsocketCommand(command.display, value);
}

async displayText(text: string) {
await this.sendWebsocketCommand(command.display, "t", text);
}

/**
* NOTE: Consider making private
* @param command
Expand Down
11 changes: 9 additions & 2 deletions extensions/src/doodlebot/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ export const display = {
clear: "c",
sad: "s",
happy: "T",
child: "H"
child: "H",
angry: "a",
annoyed: "n",
disgust: "d",
worried: "w",
fear: "f",
love: "l",
confused: "q",
} as const;

export type DisplayKey = keyof typeof display;
Expand Down Expand Up @@ -88,4 +95,4 @@ export const port = {

export const endpoint = {
video: "video_feed"
}
} as const;
54 changes: 37 additions & 17 deletions extensions/src/doodlebot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,35 +167,37 @@ export default class DoodlebotBlocks extends extension(details, "ui", "indicator

@block({
type: "command",
text: "clear display"
text: (type: DisplayKey) => `display ${type}`,
arg: { type: "string", options: displayKeys.filter(key => key !== "clear"), defaultValue: "happy" }
})
async clearDisplay() {
await this.doodlebot?.display("clear");
async setDisplay(display: DisplayKey) {
await this.doodlebot?.display(display);
}

@block({
type: "command",
text: (type: DisplayKey) => `display ${type}`,
arg: { type: "string", options: displayKeys.filter(key => key !== "clear"), defaultValue: "happy" }
text: (text: string) => `display text ${text}`,
arg: { type: "string", defaultValue: "hello world!" }
})
async setDisplay(display: DisplayKey) {
await this.doodlebot?.display(display);
async setText(text: string) {
await this.doodlebot?.displayText(text);
}

@block({
type: "command",
text: "stream video"
text: "clear display"
})
async connectToVideo() {
const image = await this.doodlebot?.getImageStream();
async clearDisplay() {
await this.doodlebot?.display("clear");
}

const drawable = this.createDrawable(image);
drawable.setVisible(true);
const update = () => {
drawable.update(image);
requestAnimationFrame(update);
}
requestAnimationFrame(update);
@block({
type: "command",
text: (sound) => `play sound ${sound}`,
arg: { type: "number", defaultValue: 1 }
})
async playSound(sound: number) {
await this.doodlebot?.sendWebsocketCommand("m", sound)
}

@block({
Expand Down Expand Up @@ -226,6 +228,24 @@ export default class DoodlebotBlocks extends extension(details, "ui", "indicator

audioBufferSource.start();
audioBufferSource.stop(context.currentTime + audioDuration);

await new Promise((resolve) => setTimeout(resolve, audioDuration * 1000));
}

@block({
type: "command",
text: "stream video"
})
async connectToVideo() {
const image = await this.doodlebot?.getImageStream();

const drawable = this.createDrawable(image);
drawable.setVisible(true);
const update = () => {
drawable.update(image);
requestAnimationFrame(update);
}
requestAnimationFrame(update);
}

@block({
Expand Down

0 comments on commit 3215ed7

Please sign in to comment.