Stop using local stream after hangup

This commit is contained in:
Jerko Steiner 2019-11-18 09:42:18 -03:00
parent c89886bbfa
commit ff5a20e13f
4 changed files with 22 additions and 10 deletions

View File

@ -3,13 +3,22 @@ export const createObjectURL = jest.fn()
export const revokeObjectURL = jest.fn()
export class MediaStream {
getTracks() {
return [{
stop: jest.fn(),
}, {
stop: jest.fn(),
}]
}
getVideoTracks () {
return [{
enabled: true,
stop: jest.fn(),
}]
}
getAudioTracks () {
return [{
stop: jest.fn(),
enabled: true,
}]
}

View File

@ -8,6 +8,7 @@ import { EventEmitter } from 'events'
import { createStore, Store, GetState } from '../store'
import { ClientSocket } from '../socket'
import { Dispatch } from 'redux'
import { MediaStream } from '../window'
describe('SocketActions', () => {
const roomName = 'bla'
@ -128,7 +129,13 @@ describe('SocketActions', () => {
describe('stream', () => {
it('adds a stream to streamStore', () => {
const stream = {}
const stream = {
getTracks() {
return [{
stop: jest.fn(),
}]
},
}
peer.emit(constants.PEER_EVENT_STREAM, stream)
expect(store.getState().streams).toEqual({
@ -143,7 +150,7 @@ describe('SocketActions', () => {
describe('close', () => {
beforeEach(() => {
const stream = {}
const stream = new MediaStream()
peer.emit(constants.PEER_EVENT_STREAM, stream)
expect(store.getState().streams).toEqual({
b: {

View File

@ -23,14 +23,7 @@ export interface NotificationProps {
const Notification = React.memo(
function Notification(props: NotificationProps) {
const { dismiss, notification } = props
// React.useEffect(() => {
// const timeout = setTimeout(dismiss, props.timeout, notification.id)
// return () => {
// clearTimeout(timeout)
// dismiss(notification.id)
// }
// }, [])
const { notification } = props
return (
<div className={classnames(notification.type, 'notification')}>
{notification.message}

View File

@ -43,6 +43,9 @@ function removeStream (
): StreamsState {
const { userId } = payload
const stream = state[userId]
if (stream && stream.stream) {
stream.stream.getTracks().forEach(track => track.stop())
}
if (stream && stream.url) {
revokeObjectURL(stream.url)
}