New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screen sharing #96
Comments
PeerJS takes in an arbitrary stream when calling So it should already work. Eric On Thu, Oct 24, 2013 at 8:52 AM, kenianbei notifications@github.com wrote:
510-691-3951 |
Give it a try and if you run into trouble please reopen the issue and I'll fix it On Fri, Oct 25, 2013 at 10:41 AM, Eric Zhang really.ez@gmail.com wrote:
510-691-3951 |
I hadn't done my research on how screen sharing works, will test it out. Thanks for all your work... you guys are awesome! |
Hello, can u please help me to integrate screen sharing on PeerJS. |
For those looking for Screen Sharing, as said above, you need to use a MediaStream in the same way as what you would do for call. The way to get the MediaStream for screen sharing is: let screenStream = await navigator.mediaDevices.getDisplayMedia({
video: true
}); Then simply:
Hope this saves you 5 minutes ;) |
could you please provide source code for screen sharing in peerjs? |
Sorry I don't have time to provide a minimal working example for screen sharing. |
@theevann maybe my code will help you I'm using in my project and it's working constructor() {
this.peer = new Peer();
this.peer.on('open', (id) => {
this.id = id;
});
this.peer.on('call', (call) => {
call.answer();
call.on('stream', (remoteStream) => {
this.videoElementRef.nativeElement.srcObject = remoteStream;
});
});
}
public async buttonHandler(evento: Event, remotoId: string): Promise<void> {
evento.preventDefault();
const stream = await (navigator.mediaDevices as MyMediaDevices).getDisplayMedia(
{
video: { frameRate: 5, width: 1280, height: 720 },
}
);
const call = this.peer.call(remotoId, stream);
} |
@venkpath peer.call(remote_peer_key, screenStream); |
@saini3911 |
i use that to but it remove original user face media also |
i have made my project in expressjs and preerjs .. after other user connect to room why media stream is not connect .. like i other user have to refresh their tab 3-4 time to get media stream in peerjs why ? |
I too have this problem, this is my code `const socket = io('/') myPeer.on('call', call => { socket.on('user-connected', userId => { socket.on('user-disconnected', userId => { myPeer.on('open', id => { function connectToNewUser(userId, stream) { peers[userId] = call function addVideoStream(video, stream) { //new code const muteUnmute = () => { const playStop = () => { const setMuteButton = () => { const setUnmuteButton = () => { const setStopVideo = () => { const setPlayVideo = () => { ` I can't stream my screen with peerjs but video cam streaming is working properly |
I have the same problem.
Works fine and as expected
works wrong - "on.call" never called I thought that problem might be in https, but not. Https test didn't help. |
I was able to piece together a screen share app referencing the following:
I baked it into a Laravel project (using Livewire), but here is the template: <div class="relative pt-28">
<x-jet-button id="share" class="absolute z-10 top-8 right-12" onclick="share()">Share</x-jet-button>
@foreach( $teamUsers as $user)
<button onclick="watch('{{ $team->id . '-' . $user->id }}')">
<img class="h-10 w-10 rounded-full object-cover" src="{{ $user->profile_photo_url }}" alt="{{ $user->name }}">
</button>
@endforeach
<!-- Local Video Element-->
<video id="local-video" class="absolute top-0 right-0 w-48"></video>
<!-- Remote Video Element-->
<video id="remote-video" class="m-auto" style="width: 800px;" poster="https://thumbs.dreamstime.com/b/no-signal-screen-everything-plugged-tv-no-tv-signal-broadcast-screen-124890412.jpg"></video>
<style>
video {
background-color: lightgray;
}
</style>
@push('scripts')
<script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>
<script>
let peerID;
let screenShare;
const peer = new Peer('{{ $team->id . '-' . $peerID }}');
peer.on('open', function(id) {
console.log('My peer ID is: ' + id);
peerID = id
});
peer.on('call', (call) => {
console.log( 'CALL' )
call.answer( screenShare );
})
function share() {
navigator.mediaDevices.getDisplayMedia({ video: true }).then((stream) => {
screenShare = stream
let video = document.getElementById("local-video");
video.srcObject = stream;
video.play()
@this.stream()
})
}
function watch( remoteID ) {
console.log( remoteID )
// A stream is required to start a call, so call with an empty stream
// This allows the call to be answered with the screen share.
const videoTrack = createEmptyVideoTrack({ width: 500, height: 500 })
const mediaStream = new MediaStream([ videoTrack ]);
const call = peer.call(remoteID, mediaStream);
// `stream` is the MediaStream of the remote peer.
// Here you'd add it to an HTML video/canvas element.
call.on('stream', function(stream) {
console.log( 'STREAM', stream )
let video = document.getElementById("remote-video");
video.srcObject = stream;
video.play();
});
}
function createEmptyVideoTrack({ width, height }) {
const canvas = Object.assign(document.createElement('canvas'), { width, height });
canvas.getContext('2d').fillRect(0, 0, width, height);
const stream = canvas.captureStream();
const track = stream.getVideoTracks()[0];
return Object.assign(track, { enabled: false });
}
</script>
@endpush
</div> |
Any plans for adding screen sharing?
Example: https://www.webrtc-experiment.com/Pluginfree-Screen-Sharing/
The text was updated successfully, but these errors were encountered: