|
1 |
| -import React, { useEffect, useState, Component } from 'react'; |
| 1 | +import React, { Component } from 'react'; |
2 | 2 | import { Provider } from 'react-redux';
|
3 | 3 |
|
4 | 4 | import { store } from './src/store';
|
5 | 5 | import App from './src/components/App';
|
6 | 6 | import ConversationWindow from './src/components/ConversationWindow';
|
7 | 7 | import ConversationList from './src/components/ConversationList';
|
8 | 8 | import { Channelize } from './channelize-websdk/dist/index';
|
9 |
| -// import React, { useEffect } from 'react'; |
10 | 9 |
|
11 | 10 | if (process.env.NODE_ENV === 'development') {
|
12 | 11 | GLOBAL.XMLHttpRequest = GLOBAL.originalXMLHttpRequest || GLOBAL.XMLHttpRequest;
|
13 | 12 | console.disableYellowBox = true;
|
14 | 13 | }
|
15 | 14 |
|
16 |
| -const PUBLIC_KEY = "qHvonVEyIxDLa6zh"; //Channelize.io public key |
17 |
| -const LOGGEDIN_USER_ID = "20697" ;//User id of loggedin user |
18 |
| -const CH_ACCESS_TOKEN = "IM8At4OKh7lqDWZWWxJd6YtK5VWheqiYg5rttJgA9gG3PKVbDG2IbI9BQn2ihZu0"; //Channelize access token of loggedin userid |
19 |
| -const ANOTHER_USER_ID = "18859"; //The user id of another user to start chat |
| 15 | +const PUBLIC_KEY; //Channelize.io public key |
| 16 | +const LOGGEDIN_USER_ID;//User id of loggedin user |
| 17 | +const CH_ACCESS_TOKEN; //Channelize access token of loggedin userid |
| 18 | +const ANOTHER_USER_ID; //The user id of another user to start chat |
20 | 19 |
|
21 |
| -export default (props) => { |
22 |
| - const [conversation, setConversation] = useState(''); |
| 20 | +export default class Example extends Component { |
| 21 | + constructor(props) { |
| 22 | + super(props); |
23 | 23 |
|
24 |
| - const client = new Channelize.client({publicKey: PUBLIC_KEY}); |
25 |
| - |
26 |
| - // let conversation; |
27 |
| - useEffect(() => { |
28 |
| - console.log('1111'); |
29 |
| - getConversation(); |
30 |
| - }, []); |
| 24 | + this.state = { |
| 25 | + conversation: null |
| 26 | + } |
| 27 | + } |
31 | 28 |
|
32 |
| - const getConversation = async () => { |
33 |
| - console.log('2222'); |
34 |
| - const res = await client.connect(LOGGEDIN_USER_ID, CH_ACCESS_TOKEN); |
35 |
| - console.log('res', res) |
36 |
| - const conversation = await client.Conversation.getConversation('1021') |
37 |
| - setConversation(conversation); |
38 |
| - }; |
| 29 | + componentDidMount() { |
| 30 | + console.log('app is launched'); |
| 31 | + } |
39 | 32 |
|
40 |
| - if (!conversation) { |
41 |
| - return null; |
| 33 | + componentWillUnmount() { |
| 34 | + console.log('app is killed'); |
42 | 35 | }
|
43 | 36 |
|
44 |
| - return ( |
45 |
| - <Provider store={store}> |
46 |
| - <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
47 |
| - <ConversationWindow conversation={conversation}/> |
48 |
| - </App> |
49 |
| - </Provider> |
50 |
| - ) |
| 37 | + render() { |
| 38 | + var client = new Channelize.client({publicKey: PUBLIC_KEY}); |
| 39 | + |
| 40 | + return ( |
| 41 | + <Provider store={store}> |
| 42 | + <App client={client} userId={LOGGEDIN_USER_ID} accessToken={CH_ACCESS_TOKEN}> |
| 43 | + <ConversationList /> |
| 44 | + <ConversationWindow /> |
| 45 | + </App> |
| 46 | + </Provider> |
| 47 | + ); |
| 48 | + } |
51 | 49 | }
|
0 commit comments