Screen Sharing on Website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Screen Sharing Implementation on Website

Screen demonstration in browser works via getDisplayMedia() API—user selects what to show: entire screen, window, or tab. Then the stream is sent via WebRTC as a separate video track.

Native Browser API

async function startScreenShare(): Promise<MediaStream> {
  const stream = await navigator.mediaDevices.getDisplayMedia({
    video: {
      displaySurface: 'monitor',  // 'monitor' | 'window' | 'browser'
      width: { ideal: 1920 },
      height: { ideal: 1080 },
      frameRate: { ideal: 30, max: 60 },
    },
    audio: {
      echoCancellation: false,
      noiseSuppression: false,
    },
    preferCurrentTab: false,
  });

  return stream;
}

Screen Share Component

import { useRef, useState, useCallback } from 'react';

function ScreenShareButton({ peerConnection }: { peerConnection: RTCPeerConnection | null }) {
  const [isSharing, setIsSharing] = useState(false);
  const screenStreamRef = useRef<MediaStream | null>(null);
  const screenSenderRef = useRef<RTCRtpSender | null>(null);

  const startSharing = useCallback(async () => {
    try {
      const stream = await startScreenShare();
      screenStreamRef.current = stream;

      const [videoTrack] = stream.getVideoTracks();
      const [audioTrack] = stream.getAudioTracks();

      if (peerConnection) {
        const senders = peerConnection.getSenders();
        const videoSender = senders.find(s => s.track?.kind === 'video');

        if (videoSender) {
          await videoSender.replaceTrack(videoTrack);
          screenSenderRef.current = videoSender;
        } else {
          screenSenderRef.current = peerConnection.addTrack(videoTrack, stream);
        }

        if (audioTrack) {
          peerConnection.addTrack(audioTrack, stream);
        }
      }

      setIsSharing(true);
      videoTrack.addEventListener('ended', stopSharing);
    } catch (err) {
      if ((err as DOMException).name !== 'NotAllowedError') {
        console.error('Screen share error:', err);
      }
    }
  }, [peerConnection]);

  const stopSharing = useCallback(async () => {
    screenStreamRef.current?.getTracks().forEach(t => t.stop());

    if (screenSenderRef.current && peerConnection) {
      const cameraStream = await navigator.mediaDevices.getUserMedia({ video: true });
      const [cameraTrack] = cameraStream.getVideoTracks();
      await screenSenderRef.current.replaceTrack(cameraTrack);
    }

    setIsSharing(false);
  }, [peerConnection]);

  return (
    <button
      onClick={isSharing ? stopSharing : startSharing}
      className={`p-3 rounded-full ${isSharing ? 'bg-red-600 text-white' : 'bg-gray-700 text-white'}`}
    >
      {isSharing ? 'Stop' : 'Share Screen'}
    </button>
  );
}

LiveKit Integration

import { createLocalScreenTracks, Track } from 'livekit-client';

async function shareScreen(room: Room) {
  const screenTracks = await createLocalScreenTracks({
    audio: true,
    video: {
      width: 1920,
      height: 1080,
      frameRate: 30,
    },
  });

  await room.localParticipant.publishTrack(screenTracks[0], {
    name: 'screen',
    source: Track.Source.ScreenShare,
  });

  if (screenTracks[1]) {
    await room.localParticipant.publishTrack(screenTracks[1], {
      name: 'screen-audio',
      source: Track.Source.ScreenShareAudio,
    });
  }

  screenTracks[0].on('ended', async () => {
    await room.localParticipant.unpublishTrack(screenTracks[0]);
  });
}

Displaying Another's Screen

function RemoteScreenShare({ participant }: { participant: RemoteParticipant }) {
  const videoRef = useRef<HTMLVideoElement>(null);

  const screenTrack = [...participant.videoTracks.values()]
    .find(pub => pub.source === Track.Source.ScreenShare)?.track;

  useEffect(() => {
    if (!screenTrack || !videoRef.current) return;
    screenTrack.attach(videoRef.current);
    return () => { screenTrack.detach(videoRef.current!); };
  }, [screenTrack]);

  if (!screenTrack) return null;

  return (
    <div className="fixed inset-0 z-50 bg-black flex items-center justify-center">
      <video ref={videoRef} autoPlay playsInline
        className="max-w-full max-h-full" />
      <span className="absolute top-4 left-4 text-white bg-black/60 px-3 py-1 rounded">
        {participant.name} is sharing screen
      </span>
    </div>
  );
}

Timeline

Screen sharing via getDisplayMedia in P2P—1 day. LiveKit/Daily integration in group—1–2 days.