From 3215ed7003479c92bc7bde3acbe5ae755398cead Mon Sep 17 00:00:00 2001 From: "Github Action (authored by pmalacho-mit)" Date: Mon, 29 Apr 2024 00:02:18 -0700 Subject: [PATCH] added few missing commands, like play sound and display text --- extensions/src/doodlebot/Doodlebot.ts | 4 ++ extensions/src/doodlebot/enums.ts | 11 +++++- extensions/src/doodlebot/index.ts | 54 ++++++++++++++++++--------- 3 files changed, 50 insertions(+), 19 deletions(-) diff --git a/extensions/src/doodlebot/Doodlebot.ts b/extensions/src/doodlebot/Doodlebot.ts index 20a66eb4d..83504ef40 100644 --- a/extensions/src/doodlebot/Doodlebot.ts +++ b/extensions/src/doodlebot/Doodlebot.ts @@ -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 diff --git a/extensions/src/doodlebot/enums.ts b/extensions/src/doodlebot/enums.ts index 6f905109f..a7016bbc1 100644 --- a/extensions/src/doodlebot/enums.ts +++ b/extensions/src/doodlebot/enums.ts @@ -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; @@ -88,4 +95,4 @@ export const port = { export const endpoint = { video: "video_feed" -} \ No newline at end of file +} as const; \ No newline at end of file diff --git a/extensions/src/doodlebot/index.ts b/extensions/src/doodlebot/index.ts index c138f037a..93fd18b47 100644 --- a/extensions/src/doodlebot/index.ts +++ b/extensions/src/doodlebot/index.ts @@ -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({ @@ -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({