Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@pusher/chatkit-client": "^1.13.3",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
Expand Down
48 changes: 45 additions & 3 deletions src/components/Event/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
import React from 'react';
import React, { useEffect } from 'react';
import { connect } from 'react-redux';
import { ChatManager, TokenProvider } from '@pusher/chatkit-client';
import EventDescription from './EventDescription';
import EventAgenda from './EventAgenda';

const Event = () => {
import { pusherLocator,apiURL } from '../../config';

const Event = (props) => {
const tokenProvider = new TokenProvider({
url: `${apiURL}/api/authenticate`,
});

useEffect(() => {
if (props.user) {
const chatManager = new ChatManager({
instanceLocator: pusherLocator,
userId: props.user.email,
tokenProvider
})

chatManager.connect()
.then(currentUser => {
console.log('Successful connection', currentUser)
currentUser.subscribeToRoomMultipart({
roomId: `${props.events.title}_1`,
hooks: {
onMessage: message => {
console.log("received message", message)
}
},
messageLimit: 10
})
})
.catch(err => {
console.log('Error on connection', err)
})
}
}, )

return (
<div>
<EventDescription />
Expand All @@ -11,4 +46,11 @@ const Event = () => {
);
};

export default Event;
const mapStateToProps = ({ eventReducer, authReducer }) => ({
loading: eventReducer.loading,
events: eventReducer.events,
loggedIn: authReducer.loggedIn,
user: authReducer.user,
});

export default connect(mapStateToProps, {})(Event);
3 changes: 2 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* Environment Variables */
export const apiURL = process.env.REACT_APP_API_HOST
export const apiURL = process.env.REACT_APP_API_HOST
export const pusherLocator = process.env.REACT_APP_PUSHER_INSTANCE_LOCATOR