Guest User

Untitled

a guest
Feb 2nd, 2023
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /* question: can I send a canvas.captureStream() object to Mux? this plays the first frame and stops. It feels like it's one unknown config setting away from working... I could be wrong. */
  2.  
  3. // snippets of react code, paste in appropriate places in your demo code.
  4. useEffect(() =>
  5. ...
  6.  
  7.  
  8. let realTracks = await getUserMedia({
  9. audio: true,
  10. video: true,
  11. });
  12.  
  13. const localTracks = canvasStream.current.getTracks().map(t => {
  14. // @ts-ignore
  15. const payload = {
  16. tid: t.id,
  17. name: t.id,
  18. muted: true,
  19. type: t.kind == 'video' ? TrackKind.Video : TrackKind.Audio,
  20. source: t.kind == 'video' ? TrackSource.Camera : TrackSource.Microphone,
  21. height: t.getSettings().height || 100,
  22. width: t.getSettings().width || 100,
  23. metadata: {},
  24. }
  25. return new LocalTrack(payload, t, "synthetic");
  26. });
  27.  
  28. console.log("tracks:", realTracks, localTracks);
  29. await localParticipant.publishTracks(localTracks);
  30.  
  31. /* above is my attempt to compare what the normal track marshalling spits out versus the shimmed LocalTrack constructor (aside: throws a type error in ts, and I couldn't find docs on this, but I presume the arguments here are LocalTrack(mapping, sourceObj, tagThatDoesNotMatter)*/
  32.  
  33.  
  34. // the bit that draws a simple canvas for testing purposes
  35. const cancan = useRef<HTMLCanvasElement>();
  36. const canvasStream = useRef<MediaStream>();
  37.  
  38. // draws a circle on the canvas on a setinterval just so that there's some movement in the canvas, to show it working.
  39. const drawSomething = () => {
  40. let c = cancan.current;
  41. const ctx = c.getContext("2d");
  42. ctx.beginPath();
  43. ctx.arc(Math.random()*100, Math.random()*100, 50, 0, 2 * Math.PI);
  44. ctx.stroke();
  45. }
  46.  
  47. useEffect(() => {
  48. if (cancan.current) {
  49. let c = cancan.current;
  50. setInterval(() => {
  51. drawSomething()
  52. }, 2000);
  53. canvasStream.current = c.captureStream(30);
  54. console.log(canvasStream.current);
  55. }
  56. }, [cancan]);
  57.  
  58. // the canvas we want to stream
  59. return (
  60. <canvas ref={cancan} style={{width:"400px", height:"225px", border: "1px solid red", backgroundColor:"#EEE"}} >
  61. </canvas>
  62. )
  63.  
Advertisement
Add Comment
Please, Sign In to add comment