Skip to content

Commit

Permalink
#17
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Sep 13, 2024
1 parent 80aa1e5 commit a23f5d8
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 13 deletions.
8 changes: 7 additions & 1 deletion packages/eez-studio-ui/properties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,8 @@ export const ButtonProperty = observer(
{
name?: string;
onChange: (value: number) => void;
className?: string;
disabled?: boolean;
},
{}
> {
Expand All @@ -917,7 +919,11 @@ export const ButtonProperty = observer(
<tr>
<td />
<td>
<button onClick={value => this.props.onChange(1)}>
<button
className={classNames("btn", this.props.className)}
onClick={value => this.props.onChange(1)}
disabled={this.props.disabled}
>
{this.props.name}
</button>
</td>
Expand Down
66 changes: 64 additions & 2 deletions packages/instrument/window/history/filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { observer } from "mobx-react";
import { dbQuery } from "eez-studio-shared/db-query";
import { scheduleTask, Priority } from "eez-studio-shared/scheduler";

import { PropertyList, BooleanProperty } from "eez-studio-ui/properties";
import {
PropertyList,
BooleanProperty,
ButtonProperty
} from "eez-studio-ui/properties";

import type { IActivityLogEntry } from "instrument/window/history/activity-log";

Expand Down Expand Up @@ -49,6 +53,20 @@ export class Filters {
});
}

setAll = action((value: boolean) => {
this.connectsAndDisconnects = value;
this.scpi = value;
this.downloadedFiles = value;
this.uploadedFiles = value;
this.attachedFiles = value;
this.charts = value;
this.lists = value;
this.notes = value;
this.launchedScripts = value;
this.tabulators = value;
this.media = value;
});

filterActivityLogEntry(activityLogEntry: IActivityLogEntry): boolean {
if (this.connectsAndDisconnects) {
if (
Expand Down Expand Up @@ -151,13 +169,31 @@ export class Filters {
);
}

get allDeselected() {
return !(
this.connectsAndDisconnects ||
this.scpi ||
this.downloadedFiles ||
this.uploadedFiles ||
this.attachedFiles ||
this.charts ||
this.lists ||
this.notes ||
this.launchedScripts ||
this.tabulators ||
this.media
);
}

get sqlFilter() {
const types: string[] = [];

if (this.allSelected) {
return "1";
}

let additionalCondition = "";

if (this.connectsAndDisconnects) {
types.push(
"instrument/created",
Expand Down Expand Up @@ -208,11 +244,19 @@ export class Filters {

if (this.media) {
types.push("activity-log/media");

const typesThatSupportMediaNotes =
"type = 'instrument/plotly' or type = 'instrument/tabulator' or type = 'instrument/chart' or type = 'instrument/file-download' or type = 'instrument/file-upload' or type = 'instrument/received'";

additionalCondition = ` OR (${typesThatSupportMediaNotes}) and json_valid(message) and json_extract(message, '$.mediaNote') is not null`;
}

if (types.length > 0) {
return (
"(" + types.map(type => `type == '${type}'`).join(" OR ") + ")"
"(" +
types.map(type => `type == '${type}'`).join(" OR ") +
additionalCondition +
")"
);
} else {
return "0";
Expand Down Expand Up @@ -447,6 +491,24 @@ export const FiltersComponent = observer(
(this.props.appStore.filters.media = value)
)}
/>

<ButtonProperty
name="Select All"
className="btn-secondary"
onChange={() =>
this.props.appStore.filters.setAll(true)
}
disabled={this.props.appStore.filters.allSelected}
></ButtonProperty>

<ButtonProperty
name="Deselect All"
className="btn-secondary"
onChange={() =>
this.props.appStore.filters.setAll(false)
}
disabled={this.props.appStore.filters.allDeselected}
></ButtonProperty>
</PropertyList>
</div>
);
Expand Down
146 changes: 136 additions & 10 deletions packages/instrument/window/media-dialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { observer } from "mobx-react";

import { Dialog, showDialog } from "eez-studio-ui/dialog";
import { ButtonAction } from "eez-studio-ui/action";
import { action, makeObservable, observable, runInAction } from "mobx";
import {
action,
makeObservable,
observable,
reaction,
runInAction
} from "mobx";
import { Toolbar } from "eez-studio-ui/toolbar";
import { formatDurationWithParam } from "eez-studio-shared/util";
import { settingsController } from "home/settings";
Expand Down Expand Up @@ -38,6 +44,11 @@ const MediaDialog = observer(

error: string | undefined;

devices: MediaDeviceInfo[] = [];
selectedDeviceId: string = "";

animationFrameRequest: number | undefined;

constructor(props: any) {
super(props);

Expand All @@ -47,20 +58,105 @@ const MediaDialog = observer(
paused: observable,
duration: observable,
mediaURL: observable,
error: observable
error: observable,
devices: observable,
selectedDeviceId: observable
});
}

componentDidMount(): void {
const constraints = { audio: true, video: this.props.video };
reaction(
() => this.selectedDeviceId,
selectedDeviceId => {
if (selectedDeviceId) {
window.localStorage.setItem(
`selected_${
this.props.video ? "video" : "audio"
}_device`,
selectedDeviceId
);
}

this.onDeviceChange();
}
);

navigator.mediaDevices.enumerateDevices().then(devices => {
devices = devices.filter(
d =>
d.kind ===
(this.props.video ? "videoinput" : "audioinput")
);

let selectedDeviceId =
window.localStorage.getItem(
`selected_${
this.props.video ? "video" : "audio"
}_device`
) || "";

if (selectedDeviceId) {
if (!devices.find(d => d.deviceId === selectedDeviceId)) {
selectedDeviceId = "";
}
}

if (!selectedDeviceId) {
selectedDeviceId =
devices.length > 0 ? devices[0].deviceId : "";
}

runInAction(() => {
this.devices = devices;
this.selectedDeviceId = selectedDeviceId;
});

console.log(devices, selectedDeviceId);
});
}

onDeviceChange() {
if (this.refVideo.current) {
this.refVideo.current.srcObject = null;
}

if (this.animationFrameRequest !== undefined) {
cancelAnimationFrame(this.animationFrameRequest);
this.animationFrameRequest = undefined;
}

if (this.mediaRecorder) {
this.mediaRecorder.onstart = null;
this.mediaRecorder.onpause = null;
this.mediaRecorder.onresume = null;
this.mediaRecorder.onstop = null;
this.mediaRecorder.ondataavailable = null;
this.mediaRecorder = undefined;
}

const constraints = this.props.video
? {
audio: true,
video: {
deviceId: this.selectedDeviceId
? { exact: this.selectedDeviceId }
: undefined
}
}
: {
audio: {
deviceId: this.selectedDeviceId
? { exact: this.selectedDeviceId }
: undefined
}
};

let onSuccess = (stream: MediaStream) => {
if (this.refVideo.current) {
this.refVideo.current.srcObject = stream;
}

const mediaRecorder = new MediaRecorder(stream);

runInAction(() => {
this.mediaRecorder = mediaRecorder;
});
Expand Down Expand Up @@ -170,7 +266,9 @@ const MediaDialog = observer(
};

let onError = (err: any) => {
this.error = "The following error occured: " + err;
runInAction(() => {
this.error = "The following error occured: " + err;
});
};

navigator.mediaDevices
Expand All @@ -192,15 +290,21 @@ const MediaDialog = observer(

source.connect(analyser);

const canvas = this.refCanvas.current!;
const canvasCtx = canvas.getContext("2d")!;

const draw = () => {
this.animationFrameRequest = requestAnimationFrame(draw);

const canvas = this.refCanvas.current!;
if (!canvas) {
return;
}
const canvasCtx = canvas.getContext("2d");
if (!canvasCtx) {
return;
}

const WIDTH = canvas.width;
const HEIGHT = canvas.height;

requestAnimationFrame(draw);

analyser.getByteTimeDomainData(dataArray);

canvasCtx.fillStyle = settingsController.isDarkTheme
Expand Down Expand Up @@ -318,6 +422,28 @@ const MediaDialog = observer(
okEnabled={() => this.blob != undefined}
okButtonText="Add"
>
<div>
<select
className="form-select"
value={this.selectedDeviceId}
onChange={event => {
runInAction(() => {
this.selectedDeviceId = event.target.value;
});
}}
style={{ marginBottom: 10 }}
disabled={this.recording}
>
{this.devices.map(device => (
<option
key={device.deviceId}
value={device.deviceId}
>
{device.label}
</option>
))}
</select>
</div>
{this.error ? (
<div className="alert alert-danger">{this.error}</div>
) : (
Expand Down

0 comments on commit a23f5d8

Please sign in to comment.