opentok-camera-filters
Advanced tools
Comparing version 1.3.0 to 1.3.1
{ | ||
"name": "opentok-camera-filters", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Streaming from a Canvas with Filters to an OpenTok Session", | ||
@@ -5,0 +5,0 @@ "main": "src/filter.js", |
@@ -16,4 +16,5 @@ [![Build Status](https://travis-ci.org/aullman/opentok-camera-filters.svg?branch=master)](https://travis-ci.org/aullman/opentok-camera-filters) | ||
* Firefox 49+ | ||
* Safari 11+ | ||
These filters require the Canvas [captureStream API](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream) which works in Chrome 51+ and Firefox 43+. Adding audio to the stream only started working in Firefox 49+. | ||
These filters require the Canvas [captureStream API](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream) which works in Chrome 51+, Firefox 43+ and Safari 11+ (and Safari on iOS 11). Adding audio to the stream only started working in Firefox 49+. | ||
@@ -20,0 +21,0 @@ # Usage |
@@ -9,5 +9,24 @@ const mockGetUserMedia = require('./mock-get-user-media'); | ||
let initialFilter; | ||
let exports; | ||
// Mock out getUserMedia and replace the stream with the canvas.captureStream() | ||
const cleanupOriginalStream = () => { | ||
if (exports && exports.originalStream) { | ||
if (global.MediaStreamTrack && global.MediaStreamTrack.prototype.stop) { | ||
// Newer spec | ||
exports.originalStream.getTracks().forEach((track) => { track.stop(); }); | ||
} else { | ||
// Older spec | ||
exports.originalStream.stop(); | ||
} | ||
exports.originalStream = null; | ||
} | ||
}; | ||
// Mock out getUserMedia and replace the original stream with the canvas.captureStream() | ||
mockGetUserMedia(stream => { | ||
cleanupOriginalStream(); | ||
if (exports) { | ||
exports.originalStream = stream; | ||
} | ||
videoElement = document.createElement('video'); | ||
@@ -46,3 +65,4 @@ videoElement.srcObject = stream; | ||
} | ||
return { | ||
exports = { | ||
setPublisher: publisher => { | ||
@@ -71,2 +91,3 @@ // We insert the canvas into the publisher element. captureStream() only works | ||
} | ||
cleanupOriginalStream(); | ||
}); | ||
@@ -81,2 +102,4 @@ }, | ||
}; | ||
return exports; | ||
}; |
@@ -24,6 +24,8 @@ /* global describe it expect OT beforeAll SESSION_ID TOKEN API_KEY jasmine spyOn */ | ||
it('stops drawing frames when the publisher is destroyed', done => { | ||
it('stops drawing frames and stops the stream when the publisher is destroyed', done => { | ||
spyOn(window, 'requestAnimationFrame').and.callThrough(); | ||
const publisher = OT.initPublisher(err => { | ||
expect(err).toBeFalsy(); | ||
const originalStream = filter.originalStream; | ||
expect(originalStream).toBeDefined(); | ||
publisher.on('destroyed', () => { | ||
@@ -33,2 +35,6 @@ // Check that filterTask isn't still being called after we destroyed the publisher | ||
expect(callCount).toBeGreaterThan(0); | ||
// Check that the original stream was stopped | ||
originalStream.getTracks().forEach(track => { | ||
expect(track.readyState).toEqual('ended'); | ||
}); | ||
setTimeout(() => { | ||
@@ -35,0 +41,0 @@ expect(window.requestAnimationFrame.calls.count()).toBe(callCount); |
8667269
483
127