Add messaging support (experimental)
This commit is contained in:
parent
d3d7fc3848
commit
6bbabc1f33
@ -200,7 +200,7 @@
|
|||||||
"react/no-did-mount-set-state": 1,
|
"react/no-did-mount-set-state": 1,
|
||||||
"react/no-did-update-set-state": 1,
|
"react/no-did-update-set-state": 1,
|
||||||
"react/no-direct-mutation-state": 1,
|
"react/no-direct-mutation-state": 1,
|
||||||
"react/no-set-state": 1,
|
"react/no-set-state": 0,
|
||||||
"react/no-unknown-property": 1,
|
"react/no-unknown-property": 1,
|
||||||
"react/prefer-es6-class": 0,
|
"react/prefer-es6-class": 0,
|
||||||
// "react/prop-types": 1,
|
// "react/prop-types": 1,
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
const Alert = require('./alert.js');
|
const Alert = require('./alert.js');
|
||||||
|
const Input = require('./input.js');
|
||||||
const Notifications = require('./notifications.js');
|
const Notifications = require('./notifications.js');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const _ = require('underscore');
|
const _ = require('underscore');
|
||||||
@ -47,6 +48,7 @@ function app() {
|
|||||||
return (<div className="app">
|
return (<div className="app">
|
||||||
<Alert />
|
<Alert />
|
||||||
<Notifications />
|
<Notifications />
|
||||||
|
<Input />
|
||||||
<div className="videos">
|
<div className="videos">
|
||||||
{videos}
|
{videos}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
39
src/client/components/input.js
Normal file
39
src/client/components/input.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
const React = require('react');
|
||||||
|
const peers = require('../peer/peers.js');
|
||||||
|
const notify = require('../action/notify.js');
|
||||||
|
|
||||||
|
const Input = React.createClass({
|
||||||
|
getInitialState() {
|
||||||
|
return {
|
||||||
|
visible: false,
|
||||||
|
message: ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
handleChange(e) {
|
||||||
|
this.setState({
|
||||||
|
message: e.target.value
|
||||||
|
});
|
||||||
|
},
|
||||||
|
handleSubmit(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const { message } = this.state;
|
||||||
|
peers.message(message);
|
||||||
|
notify.info('You: ' + message);
|
||||||
|
this.setState({ message: '' });
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
const { message } = this.state;
|
||||||
|
return (
|
||||||
|
<form className="input" onSubmit={this.handleSubmit}>
|
||||||
|
<input
|
||||||
|
onChange={this.handleChange}
|
||||||
|
placeholder="Enter your message..."
|
||||||
|
type="text"
|
||||||
|
value={message}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Input;
|
||||||
@ -15,7 +15,7 @@ let peers = {};
|
|||||||
* @param {MediaStream} [stream]
|
* @param {MediaStream} [stream]
|
||||||
*/
|
*/
|
||||||
function create({ socket, user, initiator, stream }) {
|
function create({ socket, user, initiator, stream }) {
|
||||||
debug('create peer: %s', user.id);
|
debug('create peer: %s, stream:', user.id, stream);
|
||||||
notify.warn('Connecting to peer...');
|
notify.warn('Connecting to peer...');
|
||||||
|
|
||||||
if (peers[user.id]) {
|
if (peers[user.id]) {
|
||||||
@ -57,6 +57,12 @@ function create({ socket, user, initiator, stream }) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
peer.on('data', object => {
|
||||||
|
object = JSON.parse(new window.TextDecoder('utf-8').decode(object));
|
||||||
|
debug('peer: %s, message: %o', user.id, object);
|
||||||
|
notify.info('' + user.id + ': ' + object.message);
|
||||||
|
});
|
||||||
|
|
||||||
peer.once('close', () => {
|
peer.once('close', () => {
|
||||||
debug('peer: %s, close', user.id);
|
debug('peer: %s, close', user.id);
|
||||||
notify.error('Peer connection closed');
|
notify.error('Peer connection closed');
|
||||||
@ -93,4 +99,9 @@ function destroy(userId) {
|
|||||||
delete peers[userId];
|
delete peers[userId];
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { create, get, getIds, destroy, clear };
|
function message(message) {
|
||||||
|
message = JSON.stringify({ message });
|
||||||
|
_.each(peers, peer => peer.send(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { create, get, getIds, destroy, clear, message };
|
||||||
|
|||||||
@ -180,17 +180,16 @@ body.call {
|
|||||||
|
|
||||||
.notification {
|
.notification {
|
||||||
color: @color-info;
|
color: @color-info;
|
||||||
text-shadow: 0 0 0.1rem @color-info;
|
padding: 0.25rem;
|
||||||
|
background-color: rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification.error {
|
.notification.error {
|
||||||
color: @color-error;
|
color: @color-error;
|
||||||
text-shadow: 0 0 0.1rem @color-error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.notification.warning {
|
.notification.warning {
|
||||||
color: @color-warning;
|
color: @color-warning;
|
||||||
text-shadow: 0 0 0.1rem @color-warning;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -207,7 +206,7 @@ body.call {
|
|||||||
.video-container {
|
.video-container {
|
||||||
background-color: black;
|
background-color: black;
|
||||||
box-shadow: 0px 0px 5px black;
|
box-shadow: 0px 0px 5px black;
|
||||||
border-radius: @video-size / 2;
|
border-radius: 10px;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
width: @video-size;
|
width: @video-size;
|
||||||
@ -215,7 +214,7 @@ body.call {
|
|||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
|
||||||
video {
|
video {
|
||||||
border-radius: @video-size / 2;
|
border-radius: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
object-fit: cover;
|
object-fit: cover;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@ -241,6 +240,24 @@ body.call {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.input {
|
||||||
|
position: fixed;
|
||||||
|
left: 10pxpx;
|
||||||
|
bottom: 15px;
|
||||||
|
z-index: 3;
|
||||||
|
|
||||||
|
input {
|
||||||
|
box-shadow: 0px 0px 5px black;
|
||||||
|
background-color: black;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
border: none;
|
||||||
|
color: #ccc;
|
||||||
|
padding: 0.5rem;
|
||||||
|
font-family: @font-monospace;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.fade-enter {
|
.fade-enter {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user