web client blog

This commit is contained in:
rustdesk 2024-10-12 19:50:46 +08:00
parent 2af7030680
commit 4de2059796
4 changed files with 44 additions and 213 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 276 KiB

View File

@ -60,17 +60,12 @@ const { post, url } = Astro.props;
>
{post.title}
</h1>
<p
class="max-w-3xl mx-auto mt-4 mb-8 px-4 sm:px-6 text-xl md:text-2xl text-muted dark:text-slate-400 text-justify"
>
{post.excerpt}
</p>
{
post.image ? (
<Image
src={post.image}
class="max-w-full lg:max-w-[900px] mx-auto mb-6 sm:rounded-md bg-gray-400 dark:bg-slate-700"
class="mt-8 max-w-full lg:max-w-[900px] mx-auto mb-6 sm:rounded-md bg-gray-400 dark:bg-slate-700"
widths={[400, 900]}
sizes="(max-width: 900px) 400px, 900px"
alt={post?.excerpt || ''}

View File

@ -1,207 +0,0 @@
---
publishDate: 2023-07-17T00:00:00Z
title: RustDesk template in depth
excerpt: While easy to get started, Astrowind is quite complex internally. This page provides documentation on some of the more intricate parts.
image: https://images.unsplash.com/photo-1534307671554-9a6d81f4d629?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1651&q=80
category: Documentation
tags:
- astro
- tailwind css
- front-end
metadata:
canonical: https://astrowind.vercel.app/astrowind-template-in-depth
---
import DListItem from '~/components/ui/DListItem.astro';
import ToggleTheme from '~/components/common/ToggleTheme.astro';
## Overview
It can be a somewhat daunting task trying to get a handle on _RustDesk_ internals, and particularly various points of usage.
This page outlines and clarifies some of the techniques found in _RustDesk_. Use it as a guide for further modification, or an instructional for techniques to use in your own endeavors.
## Styling
As the name suggests, _RustDesk_ relies on _TailWind_ for styling. Furthermore, _RustDesk_ defines custom low level style settings which are incorporated into _TailWind_ seamlessly, and which provides consistency for higher level styling constructs, as well as enabling dark mode.
The styling mechanism consists of the following files (all paths are prefixed with `/src/` ):
<DListItem dt="assets/styles/tailwind.css">
This file is essentially an extension of _TailWind's_ base.css. High-level component styles are defined here. Note
also styling on elements selected by 'attribute' selectors at the bottom of the files, particularly those selected by
'data' attributes.
</DListItem>
<DListItem dt="components/CustomStyles.astro">
Defines custom colors and fonts. For these to take effect in the 'base.css' file, they need to be loaded in the html
header section. See next.
</DListItem>
<DListItem dt="layouts/Layout.astro">
This layout is used for all of the pages rendered by _RustDesk_. The contents of _tailwind.css_ and
_CustomStyles.astro_ component, described above, is injected into the html header.
</DListItem>
### Dark Mode
_Dark Mode_ is triggered by the little 'sunlight' icon:<ToggleTheme/>in the page header. It is defined in the _components/common/ToggleTheme.astro_, but the event is attached and the action defined in _components/common/BasicScripts.astro_ in the following snippet:
```javascript
attachEvent('[data-aw-toggle-color-scheme]', 'click', function () {
if (defaultTheme.endsWith(':only')) {
return;
}
document.documentElement.classList.toggle('dark');
localStorage.theme = document.documentElement.classList.contains('dark') ? 'dark' : 'light';
});
```
Note that this is a client event. _BasicScripts.astro_ defines several other client-side functionality as well as this one.
## Advanced Slot Usage
_slots_ are part of the component implementation, which is a common concept among many frameworks, including _Astrojs_. The typical slot definition in a component looks like this:
```astro
---
// (file: MyComponent.astro)
const { title } = Astro.props;
export interface Props {
title: string;
}
---
<div>
<h2>{title}</h2>
<slot />
<!-- slot contents injected here -->
<div></div>
</div>
```
And in usage elsewhere:
```astro
import MyComponent from "~/components/MyComponent"; ...
<MyComponent someArg="A Slot example">
<p>This content will be displayed in the slot</p>
</MyComponent>
```
### Alternate usage
There's another way we can use slots, useful particularly when a component can have markdown content is as follows (study carefully...):
```astro
---
// (file: MyComponent.astro)
const { title } = Astro.props;
export interface Props {
title: string;
}
const content: string = await Astro.props.render('default');
---
// renders the html to the 'content' variable
<div>
<h2>{title}</h2>
<div set:html={content} />
<!-- slot contents injected here -->
<div></div>
</div>
```
Whoa!! What's going on here?
Notice there is no slot definition in the html portion of the component. Instead, what we do is have _Astro_ render the slot content (here, the 'default' content, but you can also render named slots) into a variable, and then use that content in a _div_ (for instance).
So, if the usage is in a markdown file, like so:
```mdx
import MyComponent from '../../components/MyComponent';
# Using the above component in a .mdx file (that can take components)
{' '}
<MyComponent title="This is a slot implementor">### Here is some markdown content - With a bullet item.</MyComponent>
```
_MyComponent_ renders the markdown to html and then injects it into the div.
This actually has a big advantage -- consider that with the normal usage you don't have access to the slot contents: _Astro_ just plops the content into the _&lt;slot/&gt;_ tag. Using this method, however, allows you to access the content and further manipulate it before it gets inserted into the html.
This allows a great deal of flexibility in component design.
### Yet Another Step
Now, we get to the techniques used in _RustDesk_, we'll use the _pages/index.astro_ file to illustrate.
You'll note that the index file imports a lot of components, each one roughly analagous to a panel in the index page. Each of these components, in turn, is instantiated sequentially throughout the page. But, you'll notice that some of them use this kind of construct (we'll use the last section, _CallToAction_, as it is most illustrative of the technique):
```astro
<CallToAction
callToAction={{
text: 'Get template',
href: 'https://github.com/onwidget/astrowind',
icon: 'tabler:download',
}}
>
<Fragment slot="title">
Astro + <br class="block sm:hidden" /><span class="sm:whitespace-nowrap">Tailwind CSS</span>
</Fragment>
<Fragment slot="subtitle">
Be very surprised by these huge fake numbers you are seeing on this page. <br class="hidden md:inline" />Don't waste
more time! :P
</Fragment>
</CallToAction>
```
Some things to note, here:
<DListItem dt="The <em>callToAction</em> argument">
This argument is actually being passed a javascript object -- not a string. (However, in the TS definition, it could
be a string...)
</DListItem>
<DListItem dt="There are several <em>Fragment</em> children">
Furthermore, these &lt;Fragment/&gt; elements each have a _slot="(value)"_ specifier.
</DListItem>
The latter seems odd, because &lt;Fragment/&gt; is a built-in component over which you have no control, and doesn't have a provision for rendering slots, <em>per se</em>.
The answer lies in a paragraph in the _Astro_ docs, slots section, which states:
> Use a `slot="my-slot"` attribute on the child element that you want to pass through to a matching slot `name="my-slot" />` placeholder in your component.
That's pretty concise and a bit of a head-scratcher to read, but basically what it says is that:
1. Given a component that defines a slot:
1. you can reference a slot from a child element of that component and,
1. provide content to the parent component's slot from the child by naming the slot in the child with a `slot="<slot-name>"` property assignment, where the _slot-name_ is the parent's slot.
So, in the example above, the _CallToAction_ component defines the _subtitle_ slot, and the following _&lt;Fragment slot="subtitle"&gt;_ populates the slot with the following content:
```astro
<Fragment slot="subtitle">
Be very surprised by these huge fake numbers you are seeing on this page. <br class="hidden md:inline" />Don't waste
more time! :P
</Fragment>
```
And, the _CallToAction_ component defines and renders it thusly:
```astro
---
//...
const { subtitle = await Astro.slots.render('subtitle') } = Astro.props;
---
//...
{subtitle && <p class="text-xl text-muted dark:text-slate-400" set:html={subtitle} />}
//...
```
There's a lot to wrap your head around, here.
Notice first that _subtitle_ is defined as a prop/argument, but it's being processed as a slot. Interestingly, prop args and slots seem to be somewhat interchangeable: if the subtitle was just a string, it would simply take that assignment. The main difference is that if you render them independently, you have to call the render with an _await_ modifier.

View File

@ -0,0 +1,43 @@
---
publishDate: 2024-10-12T00:00:00Z
title: RustDesk web client V2 Preview
excerpt: V2 offers better codecs, international keyboard support, clipboard support, file transfer etc.
image: ~/assets/images/blog/web-client.jpg
category: Release
tags:
- web client
- release
metadata:
canonical: https://rustdesk.com/rustdesk-web-client-v2-preview
---
Rustdesk web client V1 hasn't been updated for over two years and lacks many features, our team has spent three months developing V2. Today, we are proud to introduce the V2 Preview, which offers numerous enhancements over V1. These improvements include stronger decoding capabilities, better international keyboard support, clipboard support (not just text but also image clipboards), and file transfer functionality etc. We have strived to ensure that the web version offers a synchronized feature set and user experience with the desktop version, despite the limitations imposed by browser capabilities.
You can access the RustDesk web client V2 Preview by visiting https://rustdesk.com/web. If you wish to access your own server through V2, please configure WebSocket Secure (WSS) support according to the [documentation](https://rustdesk.com/docs/en/self-host/rustdesk-server-pro/faq/#8-add-websocket-secure-wss-support-for-the-id-server-and-relay-server-to-enable-secure-communication-for-the-web-client), setting it up on ports 21118/21119.
```
location /ws/id {
proxy_pass http://localhost:21118;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /ws/relay {
proxy_pass http://localhost:21119;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
```
Once the V2 version is stable, we will also integrate the web client into the Pro version, allowing you to access it via `https://rustdesk.yourcompany.com/web`.
We are excited to bring these enhancements to our users and look forward to your feedback as we continue to refine and improve the RustDesk Web Client V2.