Fix video not showing
This commit is contained in:
parent
03aa7696ba
commit
dcbacc9a65
2
.gitignore
vendored
2
.gitignore
vendored
@ -8,3 +8,5 @@ node_modules/
|
||||
config.js
|
||||
coverage/
|
||||
config/local.json
|
||||
lib/
|
||||
tsconfig.tsbuildinfo
|
||||
|
||||
@ -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
|
||||
|
||||
@ -70,7 +70,8 @@ describe('App', () => {
|
||||
beforeEach(async () => {
|
||||
state.streams = {
|
||||
test: {
|
||||
mediaStream: new MediaStream(),
|
||||
userId: 'test',
|
||||
stream: new MediaStream(),
|
||||
url: 'blob://',
|
||||
},
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user