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
coverage/
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 mediaStream = stream && stream.stream || null
const url = stream && stream.url
console.log('stream', stream)
if ('srcObject' in video as unknown) {
if (video.srcObject !== mediaStream) {
console.log('setting srcObject')
video.srcObject = mediaStream
}
} else if (video.src !== url) {
console.log('setting src')
video.src = url || ''
}
videos[socket.id] = video

View File

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

View File

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