Fix video not showing

This commit is contained in:
Jerko Steiner 2019-11-14 00:18:15 -03:00
parent 03aa7696ba
commit dcbacc9a65
4 changed files with 28 additions and 11 deletions

2
.gitignore vendored
View File

@ -8,3 +8,5 @@ node_modules/
config.js config.js
coverage/ coverage/
config/local.json config/local.json
lib/
tsconfig.tsbuildinfo

View File

@ -37,11 +37,14 @@ export default class Video extends React.PureComponent<VideoProps> {
const video = this.videoRef.current! const video = this.videoRef.current!
const mediaStream = stream && stream.stream || null const mediaStream = stream && stream.stream || null
const url = stream && stream.url const url = stream && stream.url
console.log('stream', stream)
if ('srcObject' in video as unknown) { if ('srcObject' in video as unknown) {
if (video.srcObject !== mediaStream) { if (video.srcObject !== mediaStream) {
console.log('setting srcObject')
video.srcObject = mediaStream video.srcObject = mediaStream
} }
} else if (video.src !== url) { } else if (video.src !== url) {
console.log('setting src')
video.src = url || '' video.src = url || ''
} }
videos[socket.id] = video videos[socket.id] = video

View File

@ -70,7 +70,8 @@ describe('App', () => {
beforeEach(async () => { beforeEach(async () => {
state.streams = { state.streams = {
test: { test: {
mediaStream: new MediaStream(), userId: 'test',
stream: new MediaStream(),
url: 'blob://', url: 'blob://',
}, },
} }

View File

@ -12,7 +12,7 @@ function safeCreateObjectURL (stream: MediaStream) {
return createObjectURL(stream) return createObjectURL(stream)
} catch (err) { } catch (err) {
debug('Error using createObjectURL: %s', err) debug('Error using createObjectURL: %s', err)
return null return undefined
} }
} }
@ -20,18 +20,26 @@ export interface StreamsState {
[userId: string]: AddStreamPayload [userId: string]: AddStreamPayload
} }
function addStream (state: StreamsState, action: AddStreamAction) { function addStream (
state: StreamsState, action: AddStreamAction,
): StreamsState {
const { userId, stream } = action.payload const { userId, stream } = action.payload
return Object.freeze({
const userStream: AddStreamPayload = {
userId,
stream,
url: safeCreateObjectURL(stream),
}
return {
...state, ...state,
[userId]: { [userId]: userStream,
mediaStream: stream, }
url: safeCreateObjectURL(stream),
},
})
} }
function removeStream (state: StreamsState, action: RemoveStreamAction) { function removeStream (
state: StreamsState, action: RemoveStreamAction,
): StreamsState {
const { userId } = action.payload const { userId } = action.payload
const stream = state[userId] const stream = state[userId]
if (stream && stream.url) { if (stream && stream.url) {
@ -40,7 +48,10 @@ function removeStream (state: StreamsState, action: RemoveStreamAction) {
return omit(state, [userId]) return omit(state, [userId])
} }
export default function streams (state = defaultState, action: StreamAction) { export default function streams(
state = defaultState,
action: StreamAction,
): StreamsState {
switch (action.type) { switch (action.type) {
case STREAM_ADD: case STREAM_ADD:
return addStream(state, action) return addStream(state, action)