baseRRWebReplayer.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import {useCallback, useEffect, useRef} from 'react';
  2. import styled from '@emotion/styled';
  3. import RRWebPlayer from '@sentry-internal/rrweb-player';
  4. import {space} from 'sentry/styles/space';
  5. type RRWebEvents = ConstructorParameters<typeof RRWebPlayer>[0]['props']['events'];
  6. interface Props {
  7. className?: string;
  8. events?: RRWebEvents;
  9. }
  10. function BaseRRWebReplayerComponent({events, className}: Props) {
  11. const playerEl = useRef<HTMLDivElement>(null);
  12. const initPlayer = useCallback(() => {
  13. if (events === undefined) {
  14. return;
  15. }
  16. if (playerEl.current === null) {
  17. return;
  18. }
  19. // eslint-disable-next-line no-new
  20. new RRWebPlayer({
  21. target: playerEl.current,
  22. props: {events, autoPlay: false},
  23. });
  24. }, [events]);
  25. useEffect(() => void initPlayer(), [initPlayer]);
  26. return <div ref={playerEl} className={className} />;
  27. }
  28. const BaseRRWebReplayer = styled(BaseRRWebReplayerComponent)`
  29. .replayer-mouse {
  30. position: absolute;
  31. width: 32px;
  32. height: 32px;
  33. transition:
  34. left 0.05s linear,
  35. top 0.05s linear;
  36. background-size: contain;
  37. background-repeat: no-repeat;
  38. background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTkiIHZpZXdCb3g9IjAgMCAxMiAxOSIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTAgMTZWMEwxMS42IDExLjZINC44TDQuNCAxMS43TDAgMTZaIiBmaWxsPSJ3aGl0ZSIvPgo8cGF0aCBkPSJNOS4xIDE2LjdMNS41IDE4LjJMMC43OTk5OTkgNy4xTDQuNSA1LjZMOS4xIDE2LjdaIiBmaWxsPSJ3aGl0ZSIvPgo8cGF0aCBkPSJNNC42NzQ1MSA4LjYxODUxTDIuODMwMzEgOS4zOTI3MUw1LjkyNzExIDE2Ljc2OTVMNy43NzEzMSAxNS45OTUzTDQuNjc0NTEgOC42MTg1MVoiIGZpbGw9ImJsYWNrIi8+CjxwYXRoIGQ9Ik0xIDIuNFYxMy42TDQgMTAuN0w0LjQgMTAuNkg5LjJMMSAyLjRaIiBmaWxsPSJibGFjayIvPgo8L3N2Zz4K');
  39. border-color: transparent;
  40. }
  41. .replayer-mouse:after {
  42. content: '';
  43. display: inline-block;
  44. width: 32px;
  45. height: 32px;
  46. background: ${p => p.theme.purple300};
  47. border-radius: 100%;
  48. transform: translate(-50%, -50%);
  49. opacity: 0.3;
  50. }
  51. .replayer-mouse.active:after {
  52. animation: click 0.2s ease-in-out 1;
  53. }
  54. .replayer-mouse.touch-device {
  55. background-image: none;
  56. width: 70px;
  57. height: 70px;
  58. border-radius: 100%;
  59. margin-left: -37px;
  60. margin-top: -37px;
  61. border: 4px solid rgba(73, 80, 246, 0);
  62. transition:
  63. left 0s linear,
  64. top 0s linear,
  65. border-color 0.2s ease-in-out;
  66. }
  67. .replayer-mouse.touch-device.touch-active {
  68. border-color: ${p => p.theme.purple200};
  69. transition:
  70. left 0.25s linear,
  71. top 0.25s linear,
  72. border-color 0.2s ease-in-out;
  73. }
  74. .replayer-mouse.touch-device:after {
  75. opacity: 0;
  76. }
  77. .replayer-mouse.touch-device.active:after {
  78. animation: touch-click 0.2s ease-in-out 1;
  79. }
  80. .replayer-mouse-tail {
  81. position: absolute;
  82. pointer-events: none;
  83. }
  84. @keyframes click {
  85. 0% {
  86. opacity: 0.3;
  87. width: 20px;
  88. height: 20px;
  89. }
  90. 50% {
  91. opacity: 0.5;
  92. width: 10px;
  93. height: 10px;
  94. }
  95. }
  96. @keyframes touch-click {
  97. 0% {
  98. opacity: 0;
  99. width: 20px;
  100. height: 20px;
  101. }
  102. 50% {
  103. opacity: 0.5;
  104. width: 10px;
  105. height: 10px;
  106. }
  107. }
  108. .replayer-wrapper > iframe {
  109. border: none;
  110. }
  111. .rr-player {
  112. width: auto !important;
  113. height: auto !important;
  114. }
  115. .rr-player__frame {
  116. width: 100% !important;
  117. border-radius: 3px 3px 0 0;
  118. border: 1px solid ${p => p.theme.border};
  119. overflow: hidden;
  120. }
  121. .rr-player iframe {
  122. width: 100% !important;
  123. height: 100% !important;
  124. position: absolute;
  125. top: 0;
  126. right: 0;
  127. bottom: 0;
  128. left: 0;
  129. border: 0;
  130. }
  131. .replayer-wrapper {
  132. transform: scale(0.6) translate(0, 0) !important;
  133. transform-origin: top left;
  134. width: 166.66%;
  135. height: 166.66%;
  136. overflow: hidden;
  137. position: relative;
  138. box-shadow: inset 0 -1px 3px rgba(0, 0, 0, 0.08);
  139. }
  140. .replayer-mouse,
  141. .replayer-mouse:after {
  142. z-index: ${p => p.theme.zIndex.tooltip};
  143. }
  144. .rr-controller {
  145. width: 100%;
  146. display: block;
  147. padding: ${space(2)} 0;
  148. background: ${p => p.theme.background};
  149. border-radius: 0 0 3px 3px;
  150. border: 1px solid ${p => p.theme.border};
  151. border-top: none;
  152. position: relative;
  153. color: ${p => p.theme.textColor};
  154. }
  155. .rr-timeline {
  156. width: 100%;
  157. display: grid;
  158. grid-template-columns: 90px 1fr 90px;
  159. align-items: center;
  160. }
  161. .rr-timeline__time {
  162. text-align: center;
  163. color: ${p => p.theme.textColor};
  164. }
  165. .rr-progress {
  166. width: 100%;
  167. height: 12px;
  168. position: relative;
  169. cursor: pointer;
  170. &:before {
  171. content: '';
  172. background: ${p => p.theme.innerBorder};
  173. border-radius: 3px;
  174. display: block;
  175. height: 6px;
  176. position: absolute;
  177. left: 0;
  178. right: 0;
  179. top: 3px;
  180. }
  181. }
  182. .rr-progress.disabled {
  183. cursor: not-allowed;
  184. }
  185. .rr-progress__step {
  186. height: 6px;
  187. position: absolute;
  188. left: 0;
  189. top: 3px;
  190. border-radius: 3px;
  191. background: ${p => p.theme.purple200};
  192. }
  193. .rr-progress__handler {
  194. width: 20px;
  195. height: 20px;
  196. border-radius: 50%;
  197. position: absolute;
  198. top: 6px;
  199. transform: translate(-50%, -50%);
  200. background: ${p => p.theme.purple300};
  201. }
  202. .rr-controller__btns {
  203. display: grid;
  204. grid-auto-flow: column;
  205. grid-auto-columns: max-content;
  206. gap: ${space(0.75)};
  207. align-items: center;
  208. justify-content: center;
  209. font-size: ${p => p.theme.fontSizeSmall};
  210. }
  211. .rr-controller__btns button {
  212. color: ${p => p.theme.textColor};
  213. width: 28px;
  214. height: 28px;
  215. display: flex;
  216. padding: 0;
  217. align-items: center;
  218. justify-content: center;
  219. background: none;
  220. border: none;
  221. border-radius: 50%;
  222. cursor: pointer;
  223. transition: background 200ms ease;
  224. > svg {
  225. fill: ${p => p.theme.textColor};
  226. }
  227. }
  228. .rr-controller__btns button:active {
  229. background: ${p => p.theme.innerBorder};
  230. }
  231. .rr-controller__btns button.active {
  232. color: ${p => p.theme.white};
  233. background: ${p => p.theme.active};
  234. }
  235. .rr-controller__btns button:disabled {
  236. cursor: not-allowed;
  237. }
  238. .switch {
  239. height: 1em;
  240. display: flex;
  241. align-items: center;
  242. }
  243. .switch.disabled {
  244. opacity: 0.5;
  245. }
  246. .label {
  247. margin: 0 8px;
  248. }
  249. .switch input[type='checkbox'] {
  250. position: absolute;
  251. visibility: hidden;
  252. }
  253. .switch label {
  254. width: 32px;
  255. height: 16px;
  256. position: relative;
  257. cursor: pointer;
  258. display: flex;
  259. align-items: center;
  260. margin: 0;
  261. padding: 2px 3px;
  262. }
  263. .switch.disabled label {
  264. cursor: not-allowed;
  265. }
  266. .switch label:before {
  267. content: '';
  268. position: absolute;
  269. top: 0;
  270. left: 0;
  271. right: 0;
  272. bottom: 0;
  273. border: 1px solid ${p => p.theme.border};
  274. border-radius: 16px;
  275. }
  276. .switch label:after {
  277. content: '';
  278. width: 10px;
  279. height: 10px;
  280. border-radius: 50%;
  281. transition: all 200ms ease;
  282. background: ${p => p.theme.border};
  283. z-index: 2;
  284. }
  285. .switch input[type='checkbox']:checked + label:after {
  286. background: ${p => p.theme.active};
  287. transform: translateX(16px);
  288. }
  289. `;
  290. export default BaseRRWebReplayer;