index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React from 'react';
  2. import { useTokenKeys } from '../../hooks/useTokenKeys';
  3. import { Spin } from '@douyinfe/semi-ui';
  4. import { useParams } from 'react-router-dom';
  5. import { useTranslation } from 'react-i18next';
  6. const ChatPage = () => {
  7. const { t } = useTranslation();
  8. const { id } = useParams();
  9. const { keys, serverAddress, isLoading } = useTokenKeys(id);
  10. const comLink = (key) => {
  11. // console.log('chatLink:', chatLink);
  12. if (!serverAddress || !key) return '';
  13. let link = '';
  14. if (id) {
  15. let chats = localStorage.getItem('chats');
  16. if (chats) {
  17. chats = JSON.parse(chats);
  18. if (Array.isArray(chats) && chats.length > 0) {
  19. for (let k in chats[id]) {
  20. link = chats[id][k];
  21. link = link.replaceAll(
  22. '{address}',
  23. encodeURIComponent(serverAddress),
  24. );
  25. link = link.replaceAll('{key}', 'sk-' + key);
  26. }
  27. }
  28. }
  29. }
  30. return link;
  31. };
  32. const iframeSrc = keys.length > 0 ? comLink(keys[0]) : '';
  33. return !isLoading && iframeSrc ? (
  34. <iframe
  35. src={iframeSrc}
  36. style={{ width: '100%', height: '100%', border: 'none' }}
  37. title='Token Frame'
  38. allow='camera;microphone'
  39. />
  40. ) : (
  41. <div className="fixed inset-0 w-screen h-screen flex items-center justify-center bg-white/80 z-[1000]">
  42. <div className="flex flex-col items-center">
  43. <Spin
  44. size="large"
  45. spinning={true}
  46. tip={null}
  47. />
  48. <span className="whitespace-nowrap mt-2 text-center" style={{ color: 'var(--semi-color-primary)' }}>
  49. {t('正在跳转...')}
  50. </span>
  51. </div>
  52. </div>
  53. );
  54. };
  55. export default ChatPage;