SHARE
TWEET

Untitled

a guest Mar 26th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { useEffect } from 'react'
  2. import { getTime } from '../actions/time';
  3. import { EmptyMessageList, MessageList } from './MessageList';
  4.  
  5. const MessageListWebRTC = (props) => {
  6.     const {
  7.         inputValue,
  8.         setInputValue,
  9.         setMessages,
  10.         userName,
  11.         setForeignIdInputMode,
  12.         myPeerConn,
  13.         foreignPeerConn,
  14.     } = props.state;
  15.     let {
  16.         messages
  17.     } = props.state;
  18.  
  19.     const chatId = '2';
  20.     const variableName = true;
  21.     const onSubmit = (values) => {
  22.         if (inputValue !== '') {
  23.             const curTime = getTime();
  24.             const message = {
  25.                 name: userName,
  26.                 chat_id: Number(chatId),
  27.                 added_at: curTime,
  28.                 content: inputValue,
  29.             }
  30.             messages.push(message);
  31.             const messagesCopy = messages.slice()
  32.             setMessages(messagesCopy);
  33.             messages = messagesCopy;
  34.             myPeerConn.send(message);
  35.             setInputValue('');
  36.         }
  37.     };
  38.     useEffect(() => {
  39.         if (foreignPeerConn) {
  40.             foreignPeerConn.on('open', () => {
  41.                 foreignPeerConn.on('data', (message) => {
  42.                     messages.push(message);
  43.                     const messagesCopy = messages.slice()
  44.                     setMessages(messagesCopy);
  45.                     messages = messagesCopy;
  46.                 });
  47.             });
  48.         } else {
  49.             setForeignIdInputMode(true);
  50.         }
  51.     }, [foreignPeerConn, setForeignIdInputMode]);
  52.     if (messages === null) {
  53.         return EmptyMessageList(props, chatId, onSubmit, variableName, messages, setMessages);
  54.     }
  55.     return MessageList(props, chatId, onSubmit, variableName, userName, messages, setMessages)
  56. }
  57.  
  58. export default MessageListWebRTC;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top