Added chat support
This commit is contained in:
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,10 @@
|
||||
export function createNewMessage(text, sender, name)
|
||||
{
|
||||
return {
|
||||
type : 'message',
|
||||
text,
|
||||
time : Date.now(),
|
||||
name,
|
||||
sender
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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 }) =>
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user