Added chat support

This commit is contained in:
Håvar Aambø Fosstveit
2018-03-01 16:19:37 +01:00
parent 9a7e149c35
commit 494250153e
18 changed files with 617 additions and 7 deletions
+31
View File
@@ -0,0 +1,31 @@
const initialState =
{
showChat : false,
disabledInput : false,
badge : 0
};
const chatbehavior = (state = initialState, action) =>
{
switch (action.type)
{
case 'TOGGLE_CHAT':
{
const showChat = !state.showChat;
return { ...state, showChat };
}
case 'TOGGLE_INPUT_DISABLED':
{
const disabledInput = !state.disabledInput;
return { ...state, disabledInput };
}
default:
return state;
}
};
export default chatbehavior;
+45
View File
@@ -0,0 +1,45 @@
import
{
createNewMessage
} from './helper';
const initialState = [];
const chatmessages = (state = initialState, action) =>
{
switch (action.type)
{
case 'ADD_NEW_USER_MESSAGE':
{
const { text } = action.payload;
const message = createNewMessage(text, 'client', 'Me');
return [ ...state, message ];
}
case 'ADD_NEW_RESPONSE_MESSAGE':
{
const { message } = action.payload;
return [ ...state, message ];
}
case 'ADD_CHAT_HISTORY':
{
const { chatHistory } = action.payload;
return [ ...state, ...chatHistory ];
}
case 'DROP_MESSAGES':
{
return [];
}
default:
return state;
}
};
export default chatmessages;
+10
View File
@@ -0,0 +1,10 @@
export function createNewMessage(text, sender, name)
{
return {
type : 'message',
text,
time : Date.now(),
name,
sender
};
}
+5 -1
View File
@@ -5,6 +5,8 @@ import producers from './producers';
import peers from './peers';
import consumers from './consumers';
import notifications from './notifications';
import chatmessages from './chatmessages';
import chatbehavior from './chatbehavior';
const reducers = combineReducers(
{
@@ -13,7 +15,9 @@ const reducers = combineReducers(
producers,
peers,
consumers,
notifications
notifications,
chatmessages,
chatbehavior
});
export default reducers;
+14
View File
@@ -1,5 +1,9 @@
import randomString from 'random-string';
import * as stateActions from './stateActions';
import
{
createNewMessage
} from './reducers/helper';
export const joinRoom = (
{ roomId, peerName, displayName, device, useSimulcast, produce }) =>
@@ -81,6 +85,16 @@ export const restartIce = () =>
};
};
export const sendChatMessage = (text, name) =>
{
const message = createNewMessage(text, 'response', name);
return {
type : 'SEND_CHAT_MESSAGE',
payload : { message }
};
};
// This returns a redux-thunk action (a function).
export const notify = ({ type = 'info', text, timeout }) =>
{
+9
View File
@@ -108,6 +108,15 @@ export default ({ dispatch, getState }) => (next) =>
break;
}
case 'SEND_CHAT_MESSAGE':
{
const { message } = action.payload;
client.sendChatMessage(message);
break;
}
}
return next(action);
+45
View File
@@ -220,3 +220,48 @@ export const removeAllNotifications = () =>
type : 'REMOVE_ALL_NOTIFICATIONS'
};
};
export const toggleChat = () =>
{
return {
type : 'TOGGLE_CHAT'
};
};
export const toggleInputDisabled = () =>
{
return {
type : 'TOGGLE_INPUT_DISABLED'
};
};
export const addUserMessage = (text) =>
{
return {
type : 'ADD_NEW_USER_MESSAGE',
payload : { text }
};
};
export const addResponseMessage = (message) =>
{
return {
type : 'ADD_NEW_RESPONSE_MESSAGE',
payload : { message }
};
};
export const addChatHistory = (chatHistory) =>
{
return {
type : 'ADD_CHAT_HISTORY',
payload : { chatHistory }
};
};
export const dropMessages = () =>
{
return {
type : 'DROP_MESSAGES'
};
};