1.0.1 • Published 2 years ago

ngx-antmedia v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

ngx-antmedia

An Angular 8+ wrapper for AntMedia

Installation

Active Versions

To install the last active version:

$ npm install webrtc-adapter ngx-antmedia

Using the library

WebRTC JavaScript SDK Guide - ant-media Ant Media Server provides a WebSocket interface in publishing and playing WebRTC streams. In this document, you will learn the basics of WebRTC JavaScript SDK and JavaScript Error Callbacks.

WebRTCAdaptor methods WebRTCAdaptor Object has following methods:

getUserMedia(mediaConstraints, audioConstraint): It's called to get access to audio and video sources in the browser.
openScreen(audioConstraint, openCamera): It's called to access the screen sharing session.
openStream(mediaConstraints): It's called to open screen, camera or audio resources.
closeStream(streamId): It's called to close streams. If you want to stop peer connection, call stop(streamId).
checkExtension(): It's called to check chrome screen share extension is avaiable. If exists it call callback with "screen_share_extension_available".
enableMicInMixedAudio(enable): It's called enable Microphone in Mixed Audio.
publish(streamId, token): It's called to publish stream.
joinRoom(roomName, streamId): It's called to Join Room function in N to N WebRTC Streaming.
play(streamId, token, roomId): It's called when play the stream in N to N WebRTC.
stop(streamId): It's called to stop the stream.
join(streamId): It's called to join the stream.
leaveFromRoom(roomName): It's called leave from room.
leave(streamId): It's called to leave the stream.
getStreamInfo(streamId): It's called to return information about a stream.
gotStream(stream): It's called to reassign stream values.
switchVideoCapture(streamId): It's called for provide to switch video capture.
switchDesktopCapture(streamId): It's called for switch desktop capture.
switchVideoSource(streamId, mediaConstraints, onEndedCallback): It's called for switch video source.
onTrack(event, streamId): It's called for track to peer connections.
iceCandidateReceived(event, streamId): It's called for ice candidate messages received.
initPeerConnection(streamId): It's called for starting Init peer connection.
closePeerConnection(streamId): It's called for close peer connection.
signallingState(streamId): It's called to return signalling state.
iceConnectionState(streamId): It's called to return Ice connection state.
gotDescription(configuration, streamId): It's called to check peer connection descriptions.
turnOffLocalCamera(): It's called to turn off local camera.
turnOnLocalCamera(): It's called to turn on local camera.
muteLocalMic(): It's called to mute local mic.
unmuteLocalMic(): It's called to unmute local mic. If there is audio it calls callbackError with "AudioAlreadyActive" parameter.
takeConfiguration(idOfStream, configuration, typeOfConfiguration): It's called to take configuration.
takeCandidate(idOfTheStream, tmpLabel, tmpCandidate): It's called to take candidate.
addIceCandidate(streamId, candidate): It's called to add ice candidate.
startPublishing(idOfStream): It's called to start Publishing.
getVideoSender(streamId): It's called to get Video Sender. If we have multiple video tracks in coming versions, this method may cause some issues.
changeBandwidth(bandwidth, streamId): It's called to change bandwidth is in kbps.
getStats(streamId): It's called for return WebRTC stats.
enableStats(streamId): It's called to enable stats, setting interval 5 sec.
closeWebSocket(streamId): It's called for close WebSocket connection. After calling this function, create new WebRTCAdaptor instance, don't use the the same objectone. * Because all streams are closed on server side as well when websocket connection is closed.
This documentation is for developers who need to callbacks and their descriptions for WebRTC operations.

WebRTC JavaScript Info Callbacks

initialized: WebSocket connection is initialized successfully in this state.

publish_started: WebRTC stream publishing has been started in this state.

publish_finished: WebRTC stream publishing has been finished in this state.

screen_share_extension_available: Screen Share extension is available in this state.

screen_share_stopped: Screen Share is stopped in this state.

closed: WebSocket connection is closed in this state.

pong: When client sent ping message, server answers pong message.

refreshConnection: When WebSocket connection is refreshed and stream is published in this state.

ice_connection_state_changed: If Ice Connection is changed, server sends changed info.

updated_stats: When Peer stats are changed, server sends updated values.

WebRTC JavaScript Error Callbacks WebSocketNotSupported: WebSocket connection is not supported for environment or connection is not in the correct state.

AbortError: Although the user and operating system both granted access to the hardware device, and no hardware issues occurred that would cause a NotReadableError, some problems occurred which prevented the device from being used.

NotAllowedError: The user has specified that the current browsing instance is not permitted access to the device, or the user has denied access for the current session, or the user has denied all access to user media devices globally.

NotFoundError: No media tracks of the type specified were found that satisfy the given constraints.

OverconstrainedError: The specified constraints resulted in no candidate devices which met the criteria requested. The error is an object of type OverconstrainedError and has a constraint property whose string value is the name of a constraint which was impossible to meet, and a message property containing a human-readable string explaining the problem.

SecurityError: User media support is disabled on the Document on which getUserMedia() was called. The mechanism by which user media support is enabled and disabled is left up to the individual user agent.

AudioAlreadyActive: If there is audio it calls callbackError with "AudioAlreadyActive.

Camera or Mic is being used by some other process that does not let read the devices: Error definition it is sent when media devices are used by another application.

VideoAlreadyActive: If there is video it calls callbackError with "VideoAlreadyActive.

NotSupportedError: Error definition it is sent when SSL is needed.

noStreamNameSpecified: Error definition it is sent when stream id is not specified in the message.

not_allowed_unregistered_streams: This is sent back to the user if the publisher wants to send a stream with an unregistered id and server is configured not to allow this kind of streams.

no_room_specified: This is sent back to the user when there is no room specified in joining the video conference.

unauthorized_access: This is sent back to the user when the token is not validated.

no_encoder_settings: This is sent back to the user when there are no encoder settings available in publishing the stream.

no_peer_associated_before: This is peer to peer connection error definition. It is sent back to the user when there is no peer associated with the stream.

notSetLocalDescription: It is sent when the local description is not sent successfully.

screen_share_permission_denied: It is sent when the user does not allow screen share

Using the WebRTCAdaptor in your projects as a Module In your project, run:

npm i ngx-antmedia --save-dev Then inside your javascript file initialize the WebRTCAdaptor

import { WebRTCAdaptor } from 'ngx-antmedia';

const webRTCAdaptor = new WebRTCAdaptor({
    websocket_url: "wss://your-domain.tld:5443/WebRTCAppEE/websocket",
    mediaConstraints: {
        video: true,
        audio: true,
    },
    peerconnection_config: {
        'iceServers': [{'urls': 'stun:stun1.l.google.com:19302'}]
    },
    sdp_constraints: {
        OfferToReceiveAudio : false,
        OfferToReceiveVideo : false,
    },
    localVideoId: "id-of-video-element", // <video id="id-of-video-element" autoplay muted></video>
    bandwidth: int|string, // default is 900 kbps, string can be 'unlimited'
    dataChannelEnabled: true|false, // enable or disable data channel
    callback: (info, obj) => {}, // check info callbacks bellow
    callbackError: function(error, message) {}, // check error callbacks bellow
});

// Then, in another part of your script, you can start streaming by calling the publish method
webRTCAdaptor.publish(streamId, token, subscriberId, subscriberCode, streamName);