Make calls work

This commit is contained in:
Jerko Steiner 2017-06-17 13:22:38 -04:00
parent 84fe55f342
commit e0474ccb4f
14 changed files with 40 additions and 19 deletions

View File

@ -18,10 +18,19 @@ From git source:
git clone https://github.com/jeremija/peer-calls.git git clone https://github.com/jeremija/peer-calls.git
cd peer-calls cd peer-calls
npm install npm install
npm run build
# for production
npm start npm start
npm run build
# for development
npm run start:watch
``` ```
To run a development version, type:
If you successfully completed the above steps, your commandline/terminal should If you successfully completed the above steps, your commandline/terminal should
show that your node server is listening. show that your node server is listening.

View File

@ -6,7 +6,7 @@
"main": "src/index.js", "main": "src/index.js",
"scripts": { "scripts": {
"start": "node src/index.js", "start": "node src/index.js",
"start:server": "nodemon src/index.js", "start:server": "nodemon src/index.js --ignore build/ --ignore src/client",
"start:watch": "chastifol [ npm run js:watch ] [ npm run css:watch ] [ npm run start:server ]", "start:watch": "chastifol [ npm run js:watch ] [ npm run css:watch ] [ npm run start:server ]",
"watch": "", "watch": "",
"build": "npm run css && npm run js", "build": "npm run css && npm run js",

View File

@ -1,4 +1,4 @@
window.localStorage = { debug: true } window.localStorage = { log: true }
import logger from 'redux-logger' import logger from 'redux-logger'
const store = require('../store.js') const store = require('../store.js')

View File

@ -23,9 +23,11 @@ export const init = () => dispatch => {
export const connect = () => dispatch => { export const connect = () => dispatch => {
return new Promise(resolve => { return new Promise(resolve => {
socket.once('connect', () => { socket.once('connect', () => {
dispatch(NotifyActions.warning('Connected to server socket'))
resolve(socket) resolve(socket)
}) })
socket.on('connect', () => {
dispatch(NotifyActions.warning('Connected to server socket'))
})
socket.on('disconnect', () => { socket.on('disconnect', () => {
dispatch(NotifyActions.error('Server socket disconnected')) dispatch(NotifyActions.error('Server socket disconnected'))
}) })

View File

@ -22,8 +22,10 @@ export default class Input extends React.Component {
this.submit() this.submit()
} }
handleKeyPress = e => { handleKeyPress = e => {
if (e.key === 'Enter') {
e.preventDefault() e.preventDefault()
e.key === 'Enter' && this.submit() this.submit()
}
} }
submit = () => { submit = () => {
const { notify } = this.props const { notify } = this.props

View File

@ -54,6 +54,14 @@ describe('components/Input', () => {
expect(peers.message.mock.calls).toEqual([[ message ]]) expect(peers.message.mock.calls).toEqual([[ message ]])
expect(notify.mock.calls).toEqual([[ `You: ${message}` ]]) expect(notify.mock.calls).toEqual([[ `You: ${message}` ]])
}) })
it('does nothing when other key pressed', () => {
TestUtils.Simulate.keyPress(input, {
key: 'test'
})
expect(peers.message.mock.calls.length).toBe(0)
expect(notify.mock.calls.length).toBe(0)
})
}) })
}) })

View File

@ -1,5 +1,5 @@
'use strict' 'use strict'
import App from './components/App.js' import App from './containers/App.js'
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import store from './store.js' import store from './store.js'

View File

@ -25,7 +25,7 @@ describe('handshake', () => {
describe('socket events', () => { describe('socket events', () => {
describe('users', () => { describe('users', () => {
it('add a peer for each new user and destroy peers for missing', () => { it('add a peer for each new user and destroy peers for missing', () => {
handshake(socket, 'bla') handshake({ socket, roomName: 'bla' })
// given // given
let payload = { let payload = {
@ -53,7 +53,7 @@ describe('handshake', () => {
let data let data
beforeEach(() => { beforeEach(() => {
data = {} data = {}
handshake(socket, 'bla') handshake({ socket, roomName: 'bla' })
socket.emit('users', { socket.emit('users', {
initiator: 'a', initiator: 'a',
users: [{ id: 'a' }, { id: 'b' }] users: [{ id: 'a' }, { id: 'b' }]
@ -88,7 +88,7 @@ describe('handshake', () => {
let ready = false let ready = false
socket.once('ready', () => { ready = true }) socket.once('ready', () => { ready = true })
handshake(socket, 'bla') handshake({ socket, roomName: 'bla' })
socket.emit('users', { socket.emit('users', {
initiator: 'a', initiator: 'a',

View File

@ -7,7 +7,7 @@ import store from '../store.js'
const debug = _debug('peercalls') const debug = _debug('peercalls')
const { dispatch } = store const { dispatch } = store
export default function init (socket, roomName, stream) { export default function handshake ({ socket, roomName, stream }) {
function createPeer (user, initiator) { function createPeer (user, initiator) {
return peers.create({ socket, user, initiator, stream }) return peers.create({ socket, user, initiator, stream })
} }

View File

@ -2,7 +2,7 @@ import { create } from './middlewares.js'
import reducers from './reducers' import reducers from './reducers'
import { applyMiddleware, createStore } from 'redux' import { applyMiddleware, createStore } from 'redux'
export const middlewares = create( export const middlewares = create(
window.localStorage && window.localStorage.debug window.localStorage && window.localStorage.log
) )
export default createStore( export default createStore(

View File

@ -8,7 +8,7 @@ const app = express()
const http = require('http').Server(app) const http = require('http').Server(app)
const io = require('socket.io')(http) const io = require('socket.io')(http)
app.set('view engine', 'jade') app.set('view engine', 'pug')
app.set('views', path.join(__dirname, '../views')) app.set('views', path.join(__dirname, '../views'))
app.use('/res', express.static(path.join(__dirname, '../res'))) app.use('/res', express.static(path.join(__dirname, '../res')))

View File

@ -8,12 +8,12 @@ html
meta(name="apple-mobile-web-app-capable" content="yes") meta(name="apple-mobile-web-app-capable" content="yes")
link(rel="apple-touch-icon" href="../res/icon.png") link(rel="apple-touch-icon" href="../res/icon.png")
link(rel="icon" sizes="256x256" href="../res/icon.png") link(rel="icon" sizes="256x256" href="../res/icon.png")
link(rel="stylesheet" type="text/css" href="../css/main.css") link(rel="stylesheet" type="text/css" href="../static/style.css")
body.call body.call
input#callId(type="hidden" value="#{callId}") input#callId(type="hidden" value=callId)
input#iceServers(type="hidden" value="#{JSON.stringify(iceServers)}") input#iceServers(type="hidden" value=JSON.stringify(iceServers))
div#container div#container
script(src='../js/index.js') script(src='../static/index.js')

View File

@ -9,10 +9,10 @@ html
meta(name="apple-mobile-web-app-capable" content="yes") meta(name="apple-mobile-web-app-capable" content="yes")
link(rel="apple-touch-icon" href="res/icon.png") link(rel="apple-touch-icon" href="res/icon.png")
link(rel="icon" sizes="256x256" href="res/icon.png") link(rel="icon" sizes="256x256" href="res/icon.png")
link(rel="stylesheet" type="text/css" href="css/main.css") link(rel="stylesheet" type="text/css" href="static/style.css")
body body
include ./_fork.jade include ./_fork.pug
div#container div#container