Skip to content

Commit

Permalink
Merge pull request #135 from Chatmosphere/Chat-and-Stage
Browse files Browse the repository at this point in the history
Chat and stage - first implementation
  • Loading branch information
dkgrieshammer authored Feb 10, 2022
2 parents 1d5fd2c + 7fc0f83 commit 7de7ec0
Show file tree
Hide file tree
Showing 8 changed files with 34,017 additions and 37,639 deletions.
46,241 changes: 21,080 additions & 25,161 deletions package-lock.json

Large diffs are not rendered by default.

160 changes: 160 additions & 0 deletions src/addons/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { useCallback, useState } from 'react'
import styled from 'styled-components'
import Card from "../../components/common/Card"
import { useConferenceStore } from '../../store/ConferenceStore'
import { MdMessage } from 'react-icons/md'

const SendButton = styled.button`
`
const Input = styled.div`
position:absolute;
bottom: 10px;
right: 10px;
left: 10px;
display: flex;
border-radius: 4px;
height: 48px;
flex-direction: row;
background: rgba(255, 255, 255, 1);
border: 1px solid rgba(220, 222, 225, 1);
justify-content: space-between;
`
const StyledTextarea = styled.textarea`
display: table-cell;
vertical-align: middle;
resize: none;
margin: 5px;
flex-grow: 3;
border: none;
outline: none;
`

const ContentArea = styled.div`
position: absolute;
right: 15px;
left: 15px;
top: 80px;
bottom: 80px;
overflow: scroll;
`

const ChatElement = styled.div`
margin-bottom:15px;
width: 100%;
text-align: left;
`


const UserName = styled.div`
color: #79809a;
font-size: 1em;
line-height: 1.2em;
padding: 0 0 3px 0;
font-weight: bolder;
`
const MessageText = styled.p`
color: #272a35;
font-size: 1em;
line-height: 1.2em;
margin: 0;
padding: 0;
`
const Button = styled.button`
border: none;
height: 50px;
width: 50px;
font-size: 1.4rem;
line-height: 1.4rem;
border-radius:50px;
background: none;
:hover {
background-color:#fefefe;
}
:active {
background-color:#efefef;
}
`

const Label = styled.span`
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
word-wrap: normal !important;
`


const Modal = ({callback}) => {

const conference = useConferenceStore(store => store.conferenceObject)
const users = useConferenceStore(store => store.users, (oldState, newState) => Object.keys(oldState).length === Object.keys(newState).length)
const messages = useConferenceStore(store => store.messages)

const sendMessage = useCallback((msg) => {
const el = document.querySelector<HTMLInputElement>('#chatInput')
const txt = el?.value
if(txt) {
el.value = ""
conference?.sendTextMessage(txt)
}
// document.querySelector<HTMLInputElement>('#chatInput').value = ''
},[conference])


return (
<Card title="Chat" callback={callback}>
<ContentArea>
{
messages.map((message, key) => {
if(users[message.id]) {
return (
<ChatElement key={key}>
<UserName>
{users?.[message.id].user._displayName}
</UserName>
<MessageText>
{message.text}
</MessageText>
</ChatElement>
)
}
return (<ChatElement key={key}>
<UserName>
You
</UserName>
<MessageText>
{message.text}
</MessageText>
</ChatElement>)
})
}
</ContentArea>

<Input>
<StyledTextarea id="chatInput"/>
<SendButton onClick={sendMessage}>Send</SendButton>
</Input>
</Card>
)
}


const Chat = () => {

const [show, toggleShow] = useState(false)

return (
<>
<Button onClick={() => toggleShow(!show)}><MdMessage /> <Label>Chat</Label></Button>
{show && <Modal callback={() => toggleShow(!show)} />}
</>
)
}

export default Chat
39 changes: 19 additions & 20 deletions src/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback } from "react"
import React from "react"
import styled from 'styled-components'
import { useAddonsStore } from "../../addons/addonsStore"
import Chat from "../../addons/Chat"


const Container = styled.div`
Expand Down Expand Up @@ -35,28 +35,27 @@ export const Footer: React.FC = ({ children }) => {
return (
<Container>
<LeftBox></LeftBox>
<CenterBox id="footer_center">
{children}
<ConnectedFooterAddons />
<CenterBox>
{children}
</CenterBox>
<RightBox>

<Chat />
</RightBox>
</Container>
)
}

const ConnectedFooterAddons = () => {
const footerEl = useAddonsStore(
useCallback((store) => store.footerElements, []),
)

return (
<>
{footerEl?.map((b) => {
console.log(b)
return b?.el
})}
</>
)
}
// const ConnectedFooterAddons = () => {
// const footerEl = useAddonsStore(
// useCallback((store) => store.footerElements, []),
// )
//
// return (
// <>
// {footerEl?.map((b) => {
// console.log(b)
// return b?.el
// })}
// </>
// )
// }
4 changes: 2 additions & 2 deletions src/components/common/Card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ const Close = styled.button`
`

export const Card = ({title, children}) => {
export const Card = ({title, callback=()=>null, children}) => {

return (
<Box>
<Header>
<Title>{title}</Title>
<Close>Close</Close>
<Close onClick={callback}>Close</Close>
</Header>
{children}
</Box>
Expand Down
9 changes: 8 additions & 1 deletion src/store/ConferenceStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const useConferenceStore = create<IConferenceStore>((set,get) => {
users:{},
displayName:"Friendly Sphere",
error:undefined,
messages:[]
}

const produceAndSet = (callback:(newState:IConferenceStore)=>void)=>set(state => produce(state, newState => callback(newState)))
Expand Down Expand Up @@ -94,6 +95,10 @@ export const useConferenceStore = create<IConferenceStore>((set,get) => {
conference?.setDisplayName(get().displayName)
}

const _onMessageReceived = (id:string, text:string, nr:number) => {
set((store) => ({messages: [...store.messages, {id:id, text:text, nr:nr}]}))
}

const _onParticipantPropertyChanged = (e:any) => {
const id = e._id
const props = e._properties
Expand Down Expand Up @@ -125,6 +130,8 @@ export const useConferenceStore = create<IConferenceStore>((set,get) => {
conference.on(JitsiMeetJS.events.conference.CONFERENCE_JOINED, _onConferenceJoined)
conference.on(JitsiMeetJS.events.conference.TRACK_MUTE_CHANGED, _onTrackMuteChanged);
conference.on(JitsiMeetJS.events.conference.CONFERENCE_ERROR, _onConferenceError);
conference.on(JitsiMeetJS.events.conference.MESSAGE_RECEIVED, _onMessageReceived);
//conference.on(JitsiMeetJS.events.conference.DISPLAY_NAME_CHANGED, onUserNameChanged);
conference.on(JitsiMeetJS.events.conference.PARTICIPANT_PROPERTY_CHANGED, _onParticipantPropertyChanged)
conference.on(JitsiMeetJS.events.conference.DISPLAY_NAME_CHANGED, _onUserNameChanged);
// conference.on(JitsiMeetJS.events.conference.TRACK_AUDIO_LEVEL_CHANGED, on_remote_track_audio_level_changed);
Expand Down Expand Up @@ -190,4 +197,4 @@ export const useConferenceStore = create<IConferenceStore>((set,get) => {
if(process.env.NODE_ENV === 'development') {
// @ts-ignore: Unreachable code error
mountStoreDevtool('ConferenceStore', useConferenceStore)
}
}
2 changes: 1 addition & 1 deletion src/store/LocalStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ if (process.env.NODE_ENV === "development") {
document.body.appendChild(root);
// @ts-ignore: Unreachable code error
mountStoreDevtool("LocalStore", useLocalStore, root)
}
}
5 changes: 4 additions & 1 deletion src/store/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ declare type IJitsiConference={
setReceiverConstraints:(object)=>void
leave:()=>void
setLocalParticipantProperty:(key:string,value:any)=>void
sendTextMessage:(txt:string)=>void
}

declare type IJitsiEvents = {
declare interface IJitsiEvents {
track: {
LOCAL_TRACK_STOPPED
TRACK_AUDIO_OUTPUT_CHANGED
Expand All @@ -51,6 +52,7 @@ declare type IJitsiEvents = {
CONFERENCE_ERROR
PARTICIPANT_PROPERTY_CHANGED
DISPLAY_NAME_CHANGED
MESSAGE_RECEIVED
}
connection: {
CONNECTION_ESTABLISHED
Expand Down Expand Up @@ -136,6 +138,7 @@ declare type IConferenceStore = {
setDisplayName:(name:string)=>void //why here?
calculateVolume: (id:ID) => void // why here?
calculateVolumes: (localPos:IVector2) => void // why here?
messages: Array<{id:string, text:string, nr:number}>
}

declare type IConnectionStore = {
Expand Down
Loading

0 comments on commit 7de7ec0

Please sign in to comment.