Skip to content

Commit

Permalink
release-app - make streamVision use 0 GB down from 15 gb, and stream …
Browse files Browse the repository at this point in the history
…browser url, and add example next js to use it and fix linux build
  • Loading branch information
louis030195 committed Feb 23, 2025
1 parent 2e27e84 commit 3ab702a
Show file tree
Hide file tree
Showing 33 changed files with 1,351 additions and 318 deletions.
1 change: 0 additions & 1 deletion .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ jobs:
libayatana-appindicator3-dev \
libsamplerate-dev \
libwebrtc-audio-processing-dev \
# Add these GTK dependencies
libgtk-3-dev \
libwebkit2gtk-4.0-dev \
librsvg2-dev \
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exclude = ["screenpipe-app-tauri/src-tauri"]
resolver = "2"

[workspace.package]
version = "0.2.57"
version = "0.2.58"
authors = ["louis030195 <[email protected]>"]
description = ""
repository = "https://github.com/mediar-ai/screenpipe"
Expand Down
2 changes: 1 addition & 1 deletion screenpipe-app-tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "screenpipe-app"
version = "0.36.9"
version = "0.37.0"
description = ""
authors = ["you"]
license = ""
Expand Down
25 changes: 25 additions & 0 deletions screenpipe-events/src/events_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,19 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for EventSubscription<T> {
}
}

impl<T> Drop for EventSubscription<T> {
fn drop(&mut self) {
// Remove subscription from manager when dropped
if let Some(manager) = EVENT_MANAGER
.subscriptions
.write()
.get_mut(&self.event_name)
{
manager.last_used = Instant::now();
}
}
}

impl EventManager {
fn new() -> Self {
let (sender, _) = broadcast::channel(10000);
Expand Down Expand Up @@ -129,6 +142,7 @@ impl EventManager {
pub fn send<T: Serialize + 'static>(&self, event: impl Into<String>, data: T) -> Result<()> {
let event_name = event.into();
let value = serde_json::to_value(data)?;

tracing::debug!("sending event {} ", event_name);
match self.sender.send(Event {
name: event_name.clone(),
Expand Down Expand Up @@ -182,6 +196,17 @@ impl EventManager {
);
sub
}

pub fn unsubscribe(&self, event: impl Into<String>) {
let event_name = event.into();
let mut subs = self.subscriptions.write();
subs.remove(&event_name);
}

pub fn clear_all_subscriptions(&self) {
let mut subs = self.subscriptions.write();
subs.clear();
}
}

pub fn subscribe_to_event<T: DeserializeOwned + Unpin + Clone + Send + Sync + 'static>(
Expand Down
2 changes: 1 addition & 1 deletion screenpipe-js/browser-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@screenpipe/browser",
"version": "0.1.33",
"version": "0.1.34",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
Expand Down
1 change: 1 addition & 0 deletions screenpipe-js/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ export interface VisionEvent {
timestamp: string;
app_name?: string;
window_name?: string;
browser_url?: string;
}

export interface VisionStreamResponse {
Expand Down
41 changes: 41 additions & 0 deletions screenpipe-js/examples/stream-screenshots/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/versions

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# env files (can opt-in for committing if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions screenpipe-js/examples/stream-screenshots/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Binary file not shown.
21 changes: 21 additions & 0 deletions screenpipe-js/examples/stream-screenshots/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

body {
color: var(--foreground);
background: var(--background);
font-family: Arial, Helvetica, sans-serif;
}
34 changes: 34 additions & 0 deletions screenpipe-js/examples/stream-screenshots/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";

const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});

const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
>
{children}
</body>
</html>
);
}
73 changes: 73 additions & 0 deletions screenpipe-js/examples/stream-screenshots/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"use client";

import Image from "next/image";
import { useEffect, useState } from "react";
import { pipe } from "@screenpipe/browser";
import { VisionEvent } from "@screenpipe/browser";

export default function Home() {
const [visionEvent, setVisionEvent] = useState<VisionEvent | null>(null);

useEffect(() => {
const streamVision = async () => {
try {
for await (const event of pipe.streamVision(true)) {
setVisionEvent(event.data);
console.log("vision event received");
}
} catch (error) {
console.error("vision stream error:", error);
}
};

streamVision();

return () => {
pipe.disconnect();
};
}, []);

return (
<div className="min-h-screen flex flex-col items-center justify-center bg-transparent gap-4">
{visionEvent?.image ? (
<div className="space-y-4">
<Image
src={`data:image/jpeg;base64,${visionEvent.image}`}
alt="streamed content"
width={500}
height={300}
style={{ objectFit: "contain" }}
className="rounded-lg"
/>
<div className="space-y-2 font-mono text-sm">
<a href={visionEvent.browser_url} target="_blank">
<p className="text-gray-500">
{visionEvent.browser_url || "unknown"}
</p>
</a>
<p className="text-gray-500">
app: {visionEvent.app_name || "unknown"}
</p>
<p className="text-gray-500">
window: {visionEvent.window_name || "unknown"}
</p>
<p className="text-gray-500">
time: {new Date(visionEvent.timestamp).toLocaleTimeString()}
</p>
{visionEvent.text && (
<p className="text-gray-500 max-w-[500px] break-words">
text: {visionEvent.text}
</p>
)}
</div>
</div>
) : (
<div className="animate-pulse bg-gray-200 rounded-lg w-[500px] h-[300px]" />
)}

<div className="fixed bottom-4 right-4 text-sm text-gray-500 font-mono">
{visionEvent ? "streaming..." : "waiting for stream..."}
</div>
</div>
);
}
Loading

0 comments on commit 3ab702a

Please sign in to comment.