@limrun/ui 0.4.0-rc.2 → 0.4.0-rc.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@limrun/ui",
3
- "version": "0.4.0-rc.2",
3
+ "version": "0.4.0-rc.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -27,6 +27,10 @@
27
27
  background-color: black;
28
28
  }
29
29
 
30
+ .rc-video-loading {
31
+ aspect-ratio: 9 / 19.5;
32
+ }
33
+
30
34
  .rc-video-ios {
31
35
  top: 1.6%;
32
36
  left: 3.9%;
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, useMemo, forwardRef, useImperativeHandle } from 'react';
1
+ import React, { useEffect, useRef, useMemo, useState, forwardRef, useImperativeHandle } from 'react';
2
2
  import { clsx } from 'clsx';
3
3
  import './remote-control.css';
4
4
 
@@ -134,6 +134,7 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
134
134
  ({ className, url, token, sessionId: propSessionId, openUrl }: RemoteControlProps, ref) => {
135
135
  const videoRef = useRef<HTMLVideoElement>(null);
136
136
  const frameRef = useRef<HTMLImageElement>(null);
137
+ const [videoLoaded, setVideoLoaded] = useState(false);
137
138
  const wsRef = useRef<WebSocket | null>(null);
138
139
  const peerConnectionRef = useRef<RTCPeerConnection | null>(null);
139
140
  const dataChannelRef = useRef<RTCDataChannel | null>(null);
@@ -752,6 +753,9 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
752
753
  };
753
754
 
754
755
  useEffect(() => {
756
+ // Reset video loaded state when connection params change
757
+ setVideoLoaded(false);
758
+
755
759
  // Start connection when component mounts
756
760
  start();
757
761
 
@@ -780,7 +784,12 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
780
784
  const resizeObserver = new ResizeObserver((entries) => {
781
785
  for (const entry of entries) {
782
786
  const videoWidth = entry.contentRect.width;
783
- frame.style.width = `${videoWidth * config.frameWidthMultiplier}px`;
787
+ const originalFrameWidth = frame.clientWidth;
788
+ const newFrameWidth = videoWidth * config.frameWidthMultiplier;
789
+ // The video is too small up until the first frame is visible, so we need to make sure we don't scale the frame down too much.
790
+ if (newFrameWidth > 0.9*originalFrameWidth) {
791
+ frame.style.width = `${videoWidth * config.frameWidthMultiplier}px`;
792
+ }
784
793
  video.style.borderRadius = `${videoWidth * config.videoBorderRadiusMultiplier}px`;
785
794
  }
786
795
  });
@@ -927,7 +936,11 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
927
936
  />
928
937
  <video
929
938
  ref={videoRef}
930
- className={clsx('rc-video', platform === 'ios' ? 'rc-video-ios' : 'rc-video-android')}
939
+ className={clsx(
940
+ 'rc-video',
941
+ platform === 'ios' ? 'rc-video-ios' : 'rc-video-android',
942
+ !videoLoaded && 'rc-video-loading',
943
+ )}
931
944
  style={
932
945
  config.loadingLogo
933
946
  ? {
@@ -945,6 +958,7 @@ export const RemoteControl = forwardRef<RemoteControlHandle, RemoteControlProps>
945
958
  onKeyDown={handleKeyboard}
946
959
  onKeyUp={handleKeyboard}
947
960
  onClick={handleVideoClick}
961
+ onPlaying={() => setVideoLoaded(true)}
948
962
  onFocus={() => {
949
963
  if (videoRef.current) {
950
964
  videoRef.current.style.outline = 'none';