Demo
getMediaElement.js: A reusable library for all WebRTC applications! /This library generates HTML Audio/Video element with rich user-interface and advance media controls. It gives you full control over each control button; and its functionality!
npm install getMediaElement
A working example:
Audio+Video Stream:
navigatormediaDevices;
If your media stream contains video tracks; then it will create HTMLVideoElement; otherwise; it will create HTMLAudioElement.
// you can pass HTML Video Elementdocumentbody; // you can pass HTML Audio Elementdocumentbody;
For audio-only element; you can pass "title":
documentbody; documentbody;
Features
- You can capture
onMuted
event; and disable audio/video tracks accordingly; or hold streams using "inactive" attribute in the SDP! - You can capture
onUnMuted
event; and enable audio/video tracks accordingly; or unhold streams using "sendrecv" attribute in the SDP! - You can capture
onRecordingStarted
and use RecordRTC to record audio/video streams. - You can capture
onRecordingStopped
and invokestopRecording
method of RecordRTC to stop audio/video recording. You can write recorded audio/video blobs to indexed-db using RecordRTC's newly introducedwriteToDisk
andgetFromDisk
methods. - You can capture
onZoomin
to understand that video is NOW in full-screen mode. - You can capture
onZoomout
to understand that video is NOW in normal mode. - You can capture
onTakeSnapshot
which will be fired if someone tries to take snapshot. - You can control
buttons
array to control which button should be displayed on media element. - You can use
toggle
method to change buttons' state at runtime! - You can manually pass "toggle" object to force default behaviour.
- You can use
showOnMouseEnter
to control whether buttons should be displayed on mouse enter.
Structure of getMediaElement.js
var mediaElement = ;
getMediaElement objects takes two arguments:
- HTMLVideoElement or HTMLAudioElement or MediaStream
- Options
Second argument accepts following objects and events:
buttons
; which is an array, allows you control media buttons to be displayed.width
; you can customize width of the media-container element by passing this object. Its default value is about "36%-of-screen".height
; you can customize height of the media-container element by passing this object. Its default value is "auto".onMuted
; which is fired if audio or video stream is muted. Remember, getMediaElement.js just mutes audio/video locally; you need to send websocket messages inonMuted
event to remote party.onUnMuted
; which is reverse ofonMuted
.onRecordingStarted
; you can implement audio-recording options using RecordRTC!onRecordingStopped
; RecordRTC supportsstopRecording
method as well!onZoomin
; it is fired when media element is in full-screen mode.onZoomout
; it is fired when user leaves full-screen mode either by presssingESC
key; or by clicking a button.onTakeSnapshot
; it is fired when user clicks to take snapshot. Snapshot is passed over callback in PNG format.
buttons
array
Possible options for mute-audio
mute-video
record-audio
record-video
full-screen
volume-slider
stop
toggle
array
Possible options for mute-audio
mute-video
record-audio
record-video
toggle
array and toggle
method
Difference between toggle
method allows you toggle buttons at runtime:
mediaElement;
However, toggle
array is only be passed once as second argument:
var mediaElement = ;
toggle
method
Using "toggle" method; you can customize media control buttons' state at runtime; e.g. Mute/UnMute or Zoom-in/Zoom-out etc.
var mediaElement = ; // anytime, latermediaElement;mediaElement;
"toggle" method accepts following values:
mute-audio
mute-video
record-audio
record-video
stop
"stop" be used to auto-remove media element:
mediaElement; // or simply; as a string argument, instead of an arraymediaElement;
How to acccess HTMLAudioElement or HTMLVideoElement?
There is a media
property that returns HTMLAudioElement or HTMLVideoElement:
var mediaElement = ; // Lets play the VideomediaElementmedia; // Lets pause the AudiomediaElementmedia; // Lets change width/height at runtimemediaElementstylewidth = mediaElementmediavideoWidth + 'px';mediaElementstyleheight = mediaElementmediavideoHeight + 'px';
RTCMultiConnection.js
getMediaElement andvar videosContainer = documentbody; // www.RTCMultiConnection.org/docs/onstream/rtcMultiConnection { var mediaElement = ; videosContainer;}; // www.RTCMultiConnection.org/docs/onstreamended/rtcMultiConnection { if emediaElementparentNode && emediaElementparentNodeparentNode && emediaElementparentNodeparentNodeparentNode emediaElementparentNodeparentNodeparentNode; };
License
getMediaElement is released under MIT licence . Copyright (c) 2013 Muaz Khan.