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 const revokeObjectURL = jest.fn()
export class MediaStream { export class MediaStream {
getTracks() {
return [{
stop: jest.fn(),
}, {
stop: jest.fn(),
}]
}
getVideoTracks () { getVideoTracks () {
return [{ return [{
enabled: true, enabled: true,
stop: jest.fn(),
}] }]
} }
getAudioTracks () { getAudioTracks () {
return [{ return [{
stop: jest.fn(),
enabled: true, enabled: true,
}] }]
} }

View File

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

View File

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

View File

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