VCS WebFrame component
Renders an embedded web page. Similar to <iframe>
element in HTML, but with the following essential differences:
- You can only use one WebFrame element inside a VCS composition. (In other words, WebFrame is a "singleton".)
- Creating multiple WebFrame elements is undefined behavior. They will render the same content even if you set different source URLs. To avoid this, use only one WebFrame element in your composition.
- The WebFrame element doesn't update at a guaranteed frame rate. You should assume the content will be refreshed about two times per second (2 fps).
- You can control the web page by sending keyboard events to it (see section below).
In practice, WebFrame behaves a lot like an image component that renders a live web page instead of a static image asset. You can use all the props that exist on <Image>
.
The src
prop sets the URL of the web page to be loaded. Note that VCS will load this URL on Daily's cloud-based media servers, so the page must be publicly accessible.
The viewportSize
prop sets the size of the embedded browser window in pixels. The value must be an object containing properties w
and h
. You should always set this prop to a value that fits your content. If unset, WebFrame will use a default viewport size. The default size is currently 1280*720 pixels, but could change depending on rendering environment.
Code example:
Props
Properties specific to the <WebFrame>
component:
Name | Type | Description | Default value |
---|---|---|---|
src | String | A URL to be loaded into the embedded web browser. | null |
viewportSize | Object | The size of the viewport for the embedded web browser. See description above. | null |
keyPressAction | Object | A simulated key press to be sent to the embedded web browser. See description above. | null |
Properties shared with the <Image>
component:
Name | Type | Description | Default value |
---|---|---|---|
scaleMode | String | Determines how the browser image should be rendered within its layout frame. Available values: "fit" — image is rendered without any cropping, centered inside its layout frame, scaled as needed, "fill" — image is cropped and scaled to fill its layout frame | "fit" |
transform | Object | An object defining transformations to be applied at the compositing stage. Supported properties: rotate_deg (Number), which specifies the rotation of the component in degrees. | null |
blend | Object | An object of compositing-related properties. Supported child properties: opacity : (Number), which can range from 0 to 1 (0 is fully transparent, 1 is fully opaque). If you don't pass a value for blend , or the object you pass doesn't include opacity , it defaults to full opacity. | null |
Properties available to all VCS components, including this one.
Name | Type | Description | Default value |
---|---|---|---|
id | String | A name of your choice for the component instance. Works just like the “id” property in HTML. Primarily useful for debugging. | null |
key | String , Number | This prop has a special meaning to the React runtime. When you render components inside an array (e.g. a list), each individual item in the array should have a different value for the key prop. React uses this internally to quickly compare the rendered array with its previous version. | null |
style | Object | An object of style. Each component class has its own supported style properties. For example, the Text lets you select font styles and sizing using style, but these are not relevant to other components. Note: VCS style properties are not the same as CSS properties. | {} |
layout | Array | Allows you to hook into your rendered components into the VCS layout system. After the React render cycle completes, the layout system computes final layout frames (coordinates within the output viewport). You can guide the layout process using callback functions and data you provide using the layout prop. The first value of the array must be a layout function. The second (optional) value can be a data object containing param values, which is passed to the layout function when computing the layout. See Layout API for more details. | null |
style
prop
The style
prop accepts an object that can have the following values set:
Name | Type | Description |
---|---|---|
cornerRadius_px | Number | Apply a rounded mask to the corners of the component. |
Sending events to the web page
You can interact with the page loaded into a WebFrame by sending it a key press action, a simulated keyboard event.
This is particularly useful for document viewers. For example, if you're embedding a Google Slides presentation, you might want to first send a key press to enter slideshow mode, then send arrow keys to navigate between slides.
The key press action is described using a prop called keyPressAction
, which is available on the WebFrame component. Its value must be an object with the following properties:
name
- the name of the key to be pressed. (See below for list of key names.)modifiers
- a list of modifier keys to be activated for the key press.- Possible values are:
"Shift"
,"Control"
,"Alt"
,"Meta"
- On a Mac keyboard,
"Alt"
is equal to Option and"Meta"
is equal to Command. - You should combine the keys with a plus sign. E.g.
"Shift+Meta"
- Possible values are:
key
- a unique identifier for this specific key press.- Should be an integer greater than zero.
The key
property is required because a key press is functionally an event occurring at a specific moment in time (the simulated key is pressed and depressed). Because the same keys can be pressed over and over, we need a way to tell VCS when a key press has just happened. The key
property accomplishes this. When you update key
to a new value, VCS will send the simulated event to the embedded browser.
Key names
The following key names are supported:
- Digits 0 - 9
- Letters A - Z
- ASCII special characters, e.g. !, @, +, >, etc.
- Function keys F1 - F12
- Enter
- Escape
- Backspace
- Tab
- Arrow keys ArrowUp, ArrowDown, ArrowLeft, ArrowRight
- PageDown, PageUp
You can combine these with the modifiers listed previously.
Code example
The following example functions create key press actions to control a Google Slides document.
Note that the returned object from these functions would be used as the keyPressAction
prop value for a WebFrame component. (In a real application, you'd probably want to store kpkey
in a React ref within the component that contains the WebFrame.)