Skip to content

Commit

Permalink
add nextjs example
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrohd committed Mar 26, 2024
1 parent 1d8abd9 commit a764220
Show file tree
Hide file tree
Showing 21 changed files with 4,783 additions and 18 deletions.
3 changes: 0 additions & 3 deletions crates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ unsafe_code = "forbid"
lto = true
opt-level = 3
codegen-units = 1

[profile.release.package.marecchia-core]
strip = true
8 changes: 4 additions & 4 deletions crates/marecchia-core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use libp2p::{
SwarmBuilder,
};
use libp2p_webrtc_websys as webrtc_websys;
use std::{num::NonZeroU8, str::FromStr, time::Duration};
use std::{num::NonZeroU8, panic, str::FromStr, time::Duration};
use tracing_subscriber::{fmt::format::Pretty, prelude::*};
use tracing_web::{performance_layer, MakeWebConsoleWriter};
use wasm_bindgen::prelude::*;
Expand All @@ -27,6 +27,7 @@ pub fn new_p2p_client(
stream_id: String,
secret_key_seed: Option<u8>,
) -> Result<P2PClient, ClientError> {
panic::set_hook(Box::new(console_error_panic_hook::hook));
let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(false) // Only partially supported across browsers
.without_time() // std::time is not available in browsers, see note below
Expand Down Expand Up @@ -112,8 +113,7 @@ impl P2PClient {
segment: Uint8Array,
) -> Result<(), ClientError> {
let data = segment.to_vec();
self
.0
self.0
.send(Command::ProvideSegment { segment_id, data })
.await?;
Ok(())
Expand Down Expand Up @@ -156,7 +156,7 @@ impl From<ClientError> for wasm_bindgen::JsValue {
ClientError::ListenError => 4.into(),
ClientError::DialError => 5.into(),
ClientError::ConnectionClosed => 1.into(),
ClientError::RequestError(_) => 2.into()
ClientError::RequestError(_) => 2.into(),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions examples/nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

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

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions examples/nextjs/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://github.com/vercel/next.js/tree/canary/packages/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/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## 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/deployment) for more details.
14 changes: 14 additions & 0 deletions examples/nextjs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
output: 'export',
webpack: (config, _options) => {
config.experiments = {
layers: true,
asyncWebAssembly: true
};
return config;
}
};

export default nextConfig;
Loading

0 comments on commit a764220

Please sign in to comment.