mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
sync from rtc client js
This commit is contained in:
parent
a390042f38
commit
514f81304a
@ -16,25 +16,27 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const VERSION$1 = '1.0.1';
|
const VERSION$1 = '1.0.1';
|
||||||
const BUILD_DATE = 'Mon Jul 04 2022 19:50:55 GMT+0800 (China Standard Time)';
|
const BUILD_DATE = 'Mon Mar 27 2023 19:11:59 GMT+0800 (China Standard Time)';
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isFirefox() {
|
function isFirefox() {
|
||||||
return window.navigator.userAgent.match('Firefox') !== null;
|
return window.navigator.userAgent.match('Firefox') !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isChrome() {
|
function isChrome() {
|
||||||
return window.navigator.userAgent.match('Chrome') !== null;
|
return window.navigator.userAgent.match('Chrome') !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isEdge() {
|
function isEdge() {
|
||||||
return window.navigator.userAgent.match(/Edge\/(\d+).(\d+)$/) !== null;
|
return window.navigator.userAgent.match(/Edge\/(\d+).(\d+)$/) !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class AudioSourceInfo
|
* @class AudioSourceInfo
|
||||||
* @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'.
|
* @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'.
|
||||||
@ -42,13 +44,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const AudioSourceInfo = {
|
const AudioSourceInfo = {
|
||||||
MIC: 'mic',
|
MIC: 'mic',
|
||||||
SCREENCAST: 'screen-cast',
|
SCREENCAST: 'screen-cast',
|
||||||
FILE: 'file',
|
FILE: 'file',
|
||||||
MIXED: 'mixed'
|
MIXED: 'mixed'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class VideoSourceInfo
|
* @class VideoSourceInfo
|
||||||
* @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'.
|
* @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'.
|
||||||
@ -56,13 +58,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const VideoSourceInfo = {
|
const VideoSourceInfo = {
|
||||||
CAMERA: 'camera',
|
CAMERA: 'camera',
|
||||||
SCREENCAST: 'screen-cast',
|
SCREENCAST: 'screen-cast',
|
||||||
FILE: 'file',
|
FILE: 'file',
|
||||||
MIXED: 'mixed'
|
MIXED: 'mixed'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class TrackKind
|
* @class TrackKind
|
||||||
* @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks.
|
* @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks.
|
||||||
@ -70,20 +72,17 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const TrackKind = {
|
const TrackKind = {
|
||||||
/**
|
/**
|
||||||
* Audio tracks.
|
* Audio tracks.
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
AUDIO: 'audio',
|
AUDIO: 'audio',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Video tracks.
|
* Video tracks.
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
VIDEO: 'video',
|
VIDEO: 'video',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Both audio and video tracks.
|
* Both audio and video tracks.
|
||||||
* @type string
|
* @type string
|
||||||
@ -98,7 +97,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @param {number} width
|
* @param {number} width
|
||||||
* @param {number} height
|
* @param {number} height
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resolution {
|
class Resolution {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(width, height) {
|
constructor(width, height) {
|
||||||
@ -113,10 +111,8 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @instance
|
* @instance
|
||||||
* @memberof Owt.Base.Resolution
|
* @memberof Owt.Base.Resolution
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -5531,7 +5527,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {Owt.Base.AudioSourceInfo} source Source info of this audio track.
|
* @param {Owt.Base.AudioSourceInfo} source Source info of this audio track.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AudioTrackConstraints {
|
class AudioTrackConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
@ -5544,8 +5539,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @desc Values could be "mic", "screen-cast", "file" or "mixed".
|
* @desc Values could be "mic", "screen-cast", "file" or "mixed".
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
/**
|
/**
|
||||||
* @member {string} deviceId
|
* @member {string} deviceId
|
||||||
@ -5554,11 +5547,10 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @instance
|
* @instance
|
||||||
* @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId
|
* @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.deviceId = undefined;
|
this.deviceId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class VideoTrackConstraints
|
* @class VideoTrackConstraints
|
||||||
* @classDesc Constraints for creating a video MediaStreamTrack.
|
* @classDesc Constraints for creating a video MediaStreamTrack.
|
||||||
@ -5566,7 +5558,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {Owt.Base.VideoSourceInfo} source Source info of this video track.
|
* @param {Owt.Base.VideoSourceInfo} source Source info of this video track.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class VideoTrackConstraints {
|
class VideoTrackConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
@ -5579,8 +5570,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @desc Values could be "camera", "screen-cast", "file" or "mixed".
|
* @desc Values could be "camera", "screen-cast", "file" or "mixed".
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
/**
|
/**
|
||||||
* @member {string} deviceId
|
* @member {string} deviceId
|
||||||
@ -5591,22 +5580,21 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
this.deviceId = undefined;
|
this.deviceId = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Owt.Base.Resolution} resolution
|
* @member {Owt.Base.Resolution} resolution
|
||||||
* @memberof Owt.Base.VideoTrackConstraints
|
* @memberof Owt.Base.VideoTrackConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.resolution = undefined;
|
this.resolution = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {number} frameRate
|
* @member {number} frameRate
|
||||||
* @memberof Owt.Base.VideoTrackConstraints
|
* @memberof Owt.Base.VideoTrackConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.frameRate = undefined;
|
this.frameRate = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @class StreamConstraints
|
* @class StreamConstraints
|
||||||
@ -5616,7 +5604,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @param {?Owt.Base.AudioTrackConstraints} audioConstraints
|
* @param {?Owt.Base.AudioTrackConstraints} audioConstraints
|
||||||
* @param {?Owt.Base.VideoTrackConstraints} videoConstraints
|
* @param {?Owt.Base.VideoTrackConstraints} videoConstraints
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class StreamConstraints {
|
class StreamConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(audioConstraints = false, videoConstraints = false) {
|
constructor(audioConstraints = false, videoConstraints = false) {
|
||||||
@ -5631,22 +5618,20 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @memberof Owt.Base.MediaStreamDeviceConstraints
|
* @memberof Owt.Base.MediaStreamDeviceConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.video = videoConstraints;
|
this.video = videoConstraints;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
|
|
||||||
function isVideoConstrainsForScreenCast(constraints) {
|
function isVideoConstrainsForScreenCast(constraints) {
|
||||||
return typeof constraints.video === 'object' && constraints.video.source === VideoSourceInfo.SCREENCAST;
|
return typeof constraints.video === 'object' && constraints.video.source === VideoSourceInfo.SCREENCAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class MediaStreamFactory
|
* @class MediaStreamFactory
|
||||||
* @classDesc A factory to create MediaStream. You can also create MediaStream by yourself.
|
* @classDesc A factory to create MediaStream. You can also create MediaStream by yourself.
|
||||||
* @memberof Owt.Base
|
* @memberof Owt.Base
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class MediaStreamFactory {
|
class MediaStreamFactory {
|
||||||
/**
|
/**
|
||||||
* @function createMediaStream
|
* @function createMediaStream
|
||||||
@ -5665,29 +5650,23 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
if (typeof constraints !== 'object' || !constraints.audio && !constraints.video) {
|
if (typeof constraints !== 'object' || !constraints.audio && !constraints.video) {
|
||||||
return Promise.reject(new TypeError('Invalid constrains'));
|
return Promise.reject(new TypeError('Invalid constrains'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.SCREENCAST) {
|
if (!isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.SCREENCAST) {
|
||||||
return Promise.reject(new TypeError('Cannot share screen without video.'));
|
return Promise.reject(new TypeError('Cannot share screen without video.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints) && !isChrome() && !isFirefox()) {
|
if (isVideoConstrainsForScreenCast(constraints) && !isChrome() && !isFirefox()) {
|
||||||
return Promise.reject(new TypeError('Screen sharing only supports Chrome and Firefox.'));
|
return Promise.reject(new TypeError('Screen sharing only supports Chrome and Firefox.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source !== AudioSourceInfo.SCREENCAST) {
|
if (isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source !== AudioSourceInfo.SCREENCAST) {
|
||||||
return Promise.reject(new TypeError('Cannot capture video from screen cast while capture audio from' + ' other source.'));
|
return Promise.reject(new TypeError('Cannot capture video from screen cast while capture audio from' + ' other source.'));
|
||||||
} // Check and convert constraints.
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check and convert constraints.
|
||||||
if (!constraints.audio && !constraints.video) {
|
if (!constraints.audio && !constraints.video) {
|
||||||
return Promise.reject(new TypeError('At least one of audio and video must be requested.'));
|
return Promise.reject(new TypeError('At least one of audio and video must be requested.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaConstraints = Object.create({});
|
const mediaConstraints = Object.create({});
|
||||||
|
|
||||||
if (typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.MIC) {
|
if (typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.MIC) {
|
||||||
mediaConstraints.audio = Object.create({});
|
mediaConstraints.audio = Object.create({});
|
||||||
|
|
||||||
if (isEdge()) {
|
if (isEdge()) {
|
||||||
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
|
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
|
||||||
} else {
|
} else {
|
||||||
@ -5702,14 +5681,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
mediaConstraints.audio = constraints.audio;
|
mediaConstraints.audio = constraints.audio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof constraints.video === 'object') {
|
if (typeof constraints.video === 'object') {
|
||||||
mediaConstraints.video = Object.create({});
|
mediaConstraints.video = Object.create({});
|
||||||
|
|
||||||
if (typeof constraints.video.frameRate === 'number') {
|
if (typeof constraints.video.frameRate === 'number') {
|
||||||
mediaConstraints.video.frameRate = constraints.video.frameRate;
|
mediaConstraints.video.frameRate = constraints.video.frameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraints.video.resolution && constraints.video.resolution.width && constraints.video.resolution.height) {
|
if (constraints.video.resolution && constraints.video.resolution.width && constraints.video.resolution.height) {
|
||||||
if (constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
if (constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
||||||
mediaConstraints.video.width = constraints.video.resolution.width;
|
mediaConstraints.video.width = constraints.video.resolution.width;
|
||||||
@ -5721,27 +5697,23 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
mediaConstraints.video.height.exact = constraints.video.resolution.height;
|
mediaConstraints.video.height.exact = constraints.video.resolution.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof constraints.video.deviceId === 'string') {
|
if (typeof constraints.video.deviceId === 'string') {
|
||||||
mediaConstraints.video.deviceId = {
|
mediaConstraints.video.deviceId = {
|
||||||
exact: constraints.video.deviceId
|
exact: constraints.video.deviceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirefox() && constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
if (isFirefox() && constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
||||||
mediaConstraints.video.mediaSource = 'screen';
|
mediaConstraints.video.mediaSource = 'screen';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mediaConstraints.video = constraints.video;
|
mediaConstraints.video = constraints.video;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints)) {
|
if (isVideoConstrainsForScreenCast(constraints)) {
|
||||||
return navigator.mediaDevices.getDisplayMedia(mediaConstraints);
|
return navigator.mediaDevices.getDisplayMedia(mediaConstraints);
|
||||||
} else {
|
} else {
|
||||||
return navigator.mediaDevices.getUserMedia(mediaConstraints);
|
return navigator.mediaDevices.getUserMedia(mediaConstraints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
@ -5782,34 +5754,26 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.listener = {};
|
this.listener = {};
|
||||||
this.type = type | '';
|
this.type = type | '';
|
||||||
}
|
}
|
||||||
|
|
||||||
on(event, fn) {
|
on(event, fn) {
|
||||||
if (!this.listener[event]) {
|
if (!this.listener[event]) {
|
||||||
this.listener[event] = [];
|
this.listener[event] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listener[event].push(fn);
|
this.listener[event].push(fn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
off(event, fn) {
|
off(event, fn) {
|
||||||
if (this.listener[event]) {
|
if (this.listener[event]) {
|
||||||
var index = this.listener[event].indexOf(fn);
|
var index = this.listener[event].indexOf(fn);
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
this.listener[event].splice(index, 1);
|
this.listener[event].splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
offAll() {
|
offAll() {
|
||||||
this.listener = {};
|
this.listener = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(event, data) {
|
dispatch(event, data) {
|
||||||
if (this.listener[event]) {
|
if (this.listener[event]) {
|
||||||
this.listener[event].map(each => {
|
this.listener[event].map(each => {
|
||||||
@ -5817,10 +5781,8 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bind = function bind(fn, thisArg) {
|
var bind = function bind(fn, thisArg) {
|
||||||
@ -7861,11 +7823,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
usedatachannel: false
|
usedatachannel: false
|
||||||
};
|
};
|
||||||
this.options = Object.assign({}, defaults, options);
|
this.options = Object.assign({}, defaults, options);
|
||||||
|
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
setLogger();
|
setLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.e = {
|
this.e = {
|
||||||
onicecandidate: this._onIceCandidate.bind(this),
|
onicecandidate: this._onIceCandidate.bind(this),
|
||||||
ontrack: this._onTrack.bind(this),
|
ontrack: this._onTrack.bind(this),
|
||||||
@ -7878,13 +7838,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
};
|
};
|
||||||
this._remoteStream = null;
|
this._remoteStream = null;
|
||||||
this._localStream = null;
|
this._localStream = null;
|
||||||
|
this._tracks = [];
|
||||||
this.pc = new RTCPeerConnection(null);
|
this.pc = new RTCPeerConnection(null);
|
||||||
this.pc.onicecandidate = this.e.onicecandidate;
|
this.pc.onicecandidate = this.e.onicecandidate;
|
||||||
this.pc.onicecandidateerror = this.e.onicecandidateerror;
|
this.pc.onicecandidateerror = this.e.onicecandidateerror;
|
||||||
this.pc.ontrack = this.e.ontrack;
|
this.pc.ontrack = this.e.ontrack;
|
||||||
this.pc.onconnectionstatechange = this.e.onconnectionstatechange;
|
this.pc.onconnectionstatechange = this.e.onconnectionstatechange;
|
||||||
this.datachannel = null;
|
this.datachannel = null;
|
||||||
|
|
||||||
if (this.options.usedatachannel) {
|
if (this.options.usedatachannel) {
|
||||||
this.datachannel = this.pc.createDataChannel('chat');
|
this.datachannel = this.pc.createDataChannel('chat');
|
||||||
this.datachannel.onclose = this.e.ondatachannelclose;
|
this.datachannel.onclose = this.e.ondatachannelclose;
|
||||||
@ -7892,12 +7852,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.datachannel.onmessage = this.e.ondatachannelmsg;
|
this.datachannel.onmessage = this.e.ondatachannelmsg;
|
||||||
this.datachannel.onopen = this.e.ondatachannelopen;
|
this.datachannel.onopen = this.e.ondatachannelopen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable)) this.start();else this.receive();
|
if (!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable)) this.start();else this.receive();
|
||||||
}
|
}
|
||||||
|
|
||||||
receive() {
|
receive() {
|
||||||
|
|
||||||
|
//debug.error(this.TAG,'this not implement');
|
||||||
const AudioTransceiverInit = {
|
const AudioTransceiverInit = {
|
||||||
direction: 'recvonly',
|
direction: 'recvonly',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
@ -7906,15 +7865,12 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
direction: 'recvonly',
|
direction: 'recvonly',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.videoEnable) {
|
if (this.options.videoEnable) {
|
||||||
this.pc.addTransceiver('video', VideoTransceiverInit);
|
this.pc.addTransceiver('video', VideoTransceiverInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.audioEnable) {
|
if (this.options.audioEnable) {
|
||||||
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pc.createOffer().then(desc => {
|
this.pc.createOffer().then(desc => {
|
||||||
log(this.TAG, 'offer:', desc.sdp);
|
log(this.TAG, 'offer:', desc.sdp);
|
||||||
this.pc.setLocalDescription(desc).then(() => {
|
this.pc.setLocalDescription(desc).then(() => {
|
||||||
@ -7928,13 +7884,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
let ret = response.data; //JSON.parse(response.data);
|
let ret = response.data; //JSON.parse(response.data);
|
||||||
|
|
||||||
if (ret.code != 0) {
|
if (ret.code != 0) {
|
||||||
// mean failed for offer/anwser exchange
|
// mean failed for offer/anwser exchange
|
||||||
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let anwser = {};
|
let anwser = {};
|
||||||
anwser.sdp = ret.sdp;
|
anwser.sdp = ret.sdp;
|
||||||
anwser.type = 'answer';
|
anwser.type = 'answer';
|
||||||
@ -7950,11 +7904,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, e);
|
error(this.TAG, e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
let videoConstraints = false;
|
let videoConstraints = false;
|
||||||
let audioConstraints = false;
|
let audioConstraints = false;
|
||||||
|
|
||||||
if (this.options.useCamera) {
|
if (this.options.useCamera) {
|
||||||
if (this.options.videoEnable) videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
if (this.options.videoEnable) videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
||||||
if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC);
|
if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC);
|
||||||
@ -7969,11 +7921,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.resolution.w != 0 && this.options.resolution.h != 0 && typeof videoConstraints == 'object') {
|
if (this.options.resolution.w != 0 && this.options.resolution.h != 0 && typeof videoConstraints == 'object') {
|
||||||
videoConstraints.resolution = new Resolution(this.options.resolution.w, this.options.resolution.h);
|
videoConstraints.resolution = new Resolution(this.options.resolution.w, this.options.resolution.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStreamFactory.createMediaStream(new StreamConstraints(audioConstraints, videoConstraints)).then(stream => {
|
MediaStreamFactory.createMediaStream(new StreamConstraints(audioConstraints, videoConstraints)).then(stream => {
|
||||||
this._localStream = stream;
|
this._localStream = stream;
|
||||||
this.dispatch(Events$1.WEBRTC_ON_LOCAL_STREAM, stream);
|
this.dispatch(Events$1.WEBRTC_ON_LOCAL_STREAM, stream);
|
||||||
@ -7985,7 +7935,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
direction: 'sendrecv',
|
direction: 'sendrecv',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.simulcast && stream.getVideoTracks().length > 0) {
|
if (this.options.simulcast && stream.getVideoTracks().length > 0) {
|
||||||
VideoTransceiverInit.sendEncodings = [{
|
VideoTransceiverInit.sendEncodings = [{
|
||||||
rid: 'h',
|
rid: 'h',
|
||||||
@ -8003,7 +7952,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
scaleResolutionDownBy: 4
|
scaleResolutionDownBy: 4
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.audioEnable) {
|
if (this.options.audioEnable) {
|
||||||
if (stream.getAudioTracks().length > 0) {
|
if (stream.getAudioTracks().length > 0) {
|
||||||
this.pc.addTransceiver(stream.getAudioTracks()[0], AudioTransceiverInit);
|
this.pc.addTransceiver(stream.getAudioTracks()[0], AudioTransceiverInit);
|
||||||
@ -8012,7 +7960,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.videoEnable) {
|
if (this.options.videoEnable) {
|
||||||
if (stream.getVideoTracks().length > 0) {
|
if (stream.getVideoTracks().length > 0) {
|
||||||
this.pc.addTransceiver(stream.getVideoTracks()[0], VideoTransceiverInit);
|
this.pc.addTransceiver(stream.getVideoTracks()[0], VideoTransceiverInit);
|
||||||
@ -8021,14 +7968,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.pc.addTransceiver('video', VideoTransceiverInit);
|
this.pc.addTransceiver('video', VideoTransceiverInit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
stream.getTracks().forEach((track,idx)=>{
|
stream.getTracks().forEach((track,idx)=>{
|
||||||
debug.log(this.TAG,track);
|
debug.log(this.TAG,track);
|
||||||
this.pc.addTrack(track);
|
this.pc.addTrack(track);
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.pc.createOffer().then(desc => {
|
this.pc.createOffer().then(desc => {
|
||||||
log(this.TAG, 'offer:', desc.sdp);
|
log(this.TAG, 'offer:', desc.sdp);
|
||||||
this.pc.setLocalDescription(desc).then(() => {
|
this.pc.setLocalDescription(desc).then(() => {
|
||||||
@ -8042,13 +7988,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
let ret = response.data; //JSON.parse(response.data);
|
let ret = response.data; //JSON.parse(response.data);
|
||||||
|
|
||||||
if (ret.code != 0) {
|
if (ret.code != 0) {
|
||||||
// mean failed for offer/anwser exchange
|
// mean failed for offer/anwser exchange
|
||||||
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let anwser = {};
|
let anwser = {};
|
||||||
anwser.sdp = ret.sdp;
|
anwser.sdp = ret.sdp;
|
||||||
anwser.type = 'answer';
|
anwser.type = 'answer';
|
||||||
@ -8064,9 +8008,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, e);
|
error(this.TAG, e);
|
||||||
});
|
});
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.dispatch(Events$1.CAPTURE_STREAM_FAILED); //debug.error(this.TAG,e);
|
this.dispatch(Events$1.CAPTURE_STREAM_FAILED);
|
||||||
}); //const offerOptions = {};
|
//debug.error(this.TAG,e);
|
||||||
|
});
|
||||||
|
|
||||||
|
//const offerOptions = {};
|
||||||
/*
|
/*
|
||||||
if (typeof this.pc.addTransceiver === 'function') {
|
if (typeof this.pc.addTransceiver === 'function') {
|
||||||
// |direction| seems not working on Safari.
|
// |direction| seems not working on Safari.
|
||||||
@ -8081,48 +8027,48 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
|
|
||||||
_onIceCandidate(event) {
|
_onIceCandidate(event) {
|
||||||
if (event.candidate) {
|
if (event.candidate) {
|
||||||
log('Remote ICE candidate: \n ' + event.candidate.candidate); // Send the candidate to the remote peer
|
log(this.TAG, 'Remote ICE candidate: \n ' + event.candidate.candidate);
|
||||||
|
// Send the candidate to the remote peer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTrack(event) {
|
_onTrack(event) {
|
||||||
|
this._tracks.push(event.track);
|
||||||
if (this.options.element && event.streams && event.streams.length > 0) {
|
if (this.options.element && event.streams && event.streams.length > 0) {
|
||||||
this.options.element.srcObject = event.streams[0];
|
this.options.element.srcObject = event.streams[0];
|
||||||
this._remoteStream = event.streams[0];
|
this._remoteStream = event.streams[0];
|
||||||
this.dispatch(Events$1.WEBRTC_ON_REMOTE_STREAMS, event);
|
this.dispatch(Events$1.WEBRTC_ON_REMOTE_STREAMS, event);
|
||||||
} else {
|
} else {
|
||||||
error('element pararm is failed');
|
if (this.pc.getReceivers().length == this._tracks.length) {
|
||||||
|
log(this.TAG, 'play remote stream ');
|
||||||
|
this._remoteStream = new MediaStream(this._tracks);
|
||||||
|
this.options.element.srcObject = this._remoteStream;
|
||||||
|
} else {
|
||||||
|
error(this.TAG, 'wait stream track finish');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onIceCandidateError(event) {
|
_onIceCandidateError(event) {
|
||||||
this.dispatch(Events$1.WEBRTC_ICE_CANDIDATE_ERROR, event);
|
this.dispatch(Events$1.WEBRTC_ICE_CANDIDATE_ERROR, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onconnectionstatechange(event) {
|
_onconnectionstatechange(event) {
|
||||||
this.dispatch(Events$1.WEBRTC_ON_CONNECTION_STATE_CHANGE, this.pc.connectionState);
|
this.dispatch(Events$1.WEBRTC_ON_CONNECTION_STATE_CHANGE, this.pc.connectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelOpen(event) {
|
_onDataChannelOpen(event) {
|
||||||
log(this.TAG, 'ondatachannel open:', event);
|
log(this.TAG, 'ondatachannel open:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_OPEN, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_OPEN, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelMsg(event) {
|
_onDataChannelMsg(event) {
|
||||||
log(this.TAG, 'ondatachannel msg:', event);
|
log(this.TAG, 'ondatachannel msg:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_MSG, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_MSG, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelErr(event) {
|
_onDataChannelErr(event) {
|
||||||
log(this.TAG, 'ondatachannel err:', event);
|
log(this.TAG, 'ondatachannel err:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_ERR, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_ERR, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelClose(event) {
|
_onDataChannelClose(event) {
|
||||||
log(this.TAG, 'ondatachannel close:', event);
|
log(this.TAG, 'ondatachannel close:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_CLOSE, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_CLOSE, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMsg(data) {
|
sendMsg(data) {
|
||||||
if (this.datachannel != null) {
|
if (this.datachannel != null) {
|
||||||
this.datachannel.send(data);
|
this.datachannel.send(data);
|
||||||
@ -8130,47 +8076,42 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, 'data channel is null');
|
error(this.TAG, 'data channel is null');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDataChannel() {
|
closeDataChannel() {
|
||||||
if (this.datachannel) {
|
if (this.datachannel) {
|
||||||
this.datachannel.close();
|
this.datachannel.close();
|
||||||
this.datachannel = null;
|
this.datachannel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.closeDataChannel();
|
this.closeDataChannel();
|
||||||
|
|
||||||
if (this.pc) {
|
if (this.pc) {
|
||||||
this.pc.close();
|
this.pc.close();
|
||||||
this.pc = null;
|
this.pc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options) {
|
if (this.options) {
|
||||||
this.options = null;
|
this.options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._localStream) {
|
if (this._localStream) {
|
||||||
this._localStream.getTracks().forEach((track, idx) => {
|
this._localStream.getTracks().forEach((track, idx) => {
|
||||||
track.stop();
|
track.stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._remoteStream) {
|
if (this._remoteStream) {
|
||||||
this._remoteStream.getTracks().forEach((track, idx) => {
|
this._remoteStream.getTracks().forEach((track, idx) => {
|
||||||
track.stop();
|
track.stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this._tracks.forEach((track, idx) => {
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
this._tracks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get remoteStream() {
|
get remoteStream() {
|
||||||
return this._remoteStream;
|
return this._remoteStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
get localStream() {
|
get localStream() {
|
||||||
return this._localStream;
|
return this._localStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const quickScan = [{
|
const quickScan = [{
|
||||||
@ -8224,20 +8165,17 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
let resolutions = [];
|
let resolutions = [];
|
||||||
let ok = 0;
|
let ok = 0;
|
||||||
let err = 0;
|
let err = 0;
|
||||||
|
|
||||||
for (let i = 0; i < quickScan.length; ++i) {
|
for (let i = 0; i < quickScan.length; ++i) {
|
||||||
let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
||||||
videoConstraints.resolution = new Resolution(quickScan[i].width, quickScan[i].height);
|
videoConstraints.resolution = new Resolution(quickScan[i].width, quickScan[i].height);
|
||||||
MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => {
|
MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => {
|
||||||
resolutions.push(quickScan[i]);
|
resolutions.push(quickScan[i]);
|
||||||
ok++;
|
ok++;
|
||||||
|
|
||||||
if (ok + err == quickScan.length) {
|
if (ok + err == quickScan.length) {
|
||||||
resolve(resolutions);
|
resolve(resolutions);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
err++;
|
err++;
|
||||||
|
|
||||||
if (ok + err == quickScan.length) {
|
if (ok + err == quickScan.length) {
|
||||||
resolve(resolutions);
|
resolve(resolutions);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -16,25 +16,27 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const VERSION$1 = '1.0.1';
|
const VERSION$1 = '1.0.1';
|
||||||
const BUILD_DATE = 'Mon Jul 04 2022 19:50:55 GMT+0800 (China Standard Time)';
|
const BUILD_DATE = 'Mon Mar 27 2023 19:11:59 GMT+0800 (China Standard Time)';
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isFirefox() {
|
function isFirefox() {
|
||||||
return window.navigator.userAgent.match('Firefox') !== null;
|
return window.navigator.userAgent.match('Firefox') !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isChrome() {
|
function isChrome() {
|
||||||
return window.navigator.userAgent.match('Chrome') !== null;
|
return window.navigator.userAgent.match('Chrome') !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
// eslint-disable-next-line require-jsdoc
|
||||||
function isEdge() {
|
function isEdge() {
|
||||||
return window.navigator.userAgent.match(/Edge\/(\d+).(\d+)$/) !== null;
|
return window.navigator.userAgent.match(/Edge\/(\d+).(\d+)$/) !== null;
|
||||||
} // eslint-disable-next-line require-jsdoc
|
}
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class AudioSourceInfo
|
* @class AudioSourceInfo
|
||||||
* @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'.
|
* @classDesc Source info about an audio track. Values: 'mic', 'screen-cast', 'file', 'mixed'.
|
||||||
@ -42,13 +44,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const AudioSourceInfo = {
|
const AudioSourceInfo = {
|
||||||
MIC: 'mic',
|
MIC: 'mic',
|
||||||
SCREENCAST: 'screen-cast',
|
SCREENCAST: 'screen-cast',
|
||||||
FILE: 'file',
|
FILE: 'file',
|
||||||
MIXED: 'mixed'
|
MIXED: 'mixed'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class VideoSourceInfo
|
* @class VideoSourceInfo
|
||||||
* @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'.
|
* @classDesc Source info about a video track. Values: 'camera', 'screen-cast', 'file', 'mixed'.
|
||||||
@ -56,13 +58,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const VideoSourceInfo = {
|
const VideoSourceInfo = {
|
||||||
CAMERA: 'camera',
|
CAMERA: 'camera',
|
||||||
SCREENCAST: 'screen-cast',
|
SCREENCAST: 'screen-cast',
|
||||||
FILE: 'file',
|
FILE: 'file',
|
||||||
MIXED: 'mixed'
|
MIXED: 'mixed'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class TrackKind
|
* @class TrackKind
|
||||||
* @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks.
|
* @classDesc Kind of a track. Values: 'audio' for audio track, 'video' for video track, 'av' for both audio and video tracks.
|
||||||
@ -70,20 +72,17 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @readonly
|
* @readonly
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const TrackKind = {
|
const TrackKind = {
|
||||||
/**
|
/**
|
||||||
* Audio tracks.
|
* Audio tracks.
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
AUDIO: 'audio',
|
AUDIO: 'audio',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Video tracks.
|
* Video tracks.
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
VIDEO: 'video',
|
VIDEO: 'video',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Both audio and video tracks.
|
* Both audio and video tracks.
|
||||||
* @type string
|
* @type string
|
||||||
@ -98,7 +97,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @param {number} width
|
* @param {number} width
|
||||||
* @param {number} height
|
* @param {number} height
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resolution {
|
class Resolution {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(width, height) {
|
constructor(width, height) {
|
||||||
@ -113,10 +111,8 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @instance
|
* @instance
|
||||||
* @memberof Owt.Base.Resolution
|
* @memberof Owt.Base.Resolution
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -5531,7 +5527,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {Owt.Base.AudioSourceInfo} source Source info of this audio track.
|
* @param {Owt.Base.AudioSourceInfo} source Source info of this audio track.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class AudioTrackConstraints {
|
class AudioTrackConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
@ -5544,8 +5539,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @desc Values could be "mic", "screen-cast", "file" or "mixed".
|
* @desc Values could be "mic", "screen-cast", "file" or "mixed".
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
/**
|
/**
|
||||||
* @member {string} deviceId
|
* @member {string} deviceId
|
||||||
@ -5554,11 +5547,10 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @instance
|
* @instance
|
||||||
* @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId
|
* @see https://w3c.github.io/mediacapture-main/#def-constraint-deviceId
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.deviceId = undefined;
|
this.deviceId = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class VideoTrackConstraints
|
* @class VideoTrackConstraints
|
||||||
* @classDesc Constraints for creating a video MediaStreamTrack.
|
* @classDesc Constraints for creating a video MediaStreamTrack.
|
||||||
@ -5566,7 +5558,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
* @param {Owt.Base.VideoSourceInfo} source Source info of this video track.
|
* @param {Owt.Base.VideoSourceInfo} source Source info of this video track.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class VideoTrackConstraints {
|
class VideoTrackConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(source) {
|
constructor(source) {
|
||||||
@ -5579,8 +5570,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @desc Values could be "camera", "screen-cast", "file" or "mixed".
|
* @desc Values could be "camera", "screen-cast", "file" or "mixed".
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.source = source;
|
this.source = source;
|
||||||
/**
|
/**
|
||||||
* @member {string} deviceId
|
* @member {string} deviceId
|
||||||
@ -5591,22 +5580,21 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
this.deviceId = undefined;
|
this.deviceId = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {Owt.Base.Resolution} resolution
|
* @member {Owt.Base.Resolution} resolution
|
||||||
* @memberof Owt.Base.VideoTrackConstraints
|
* @memberof Owt.Base.VideoTrackConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.resolution = undefined;
|
this.resolution = undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @member {number} frameRate
|
* @member {number} frameRate
|
||||||
* @memberof Owt.Base.VideoTrackConstraints
|
* @memberof Owt.Base.VideoTrackConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.frameRate = undefined;
|
this.frameRate = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @class StreamConstraints
|
* @class StreamConstraints
|
||||||
@ -5616,7 +5604,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @param {?Owt.Base.AudioTrackConstraints} audioConstraints
|
* @param {?Owt.Base.AudioTrackConstraints} audioConstraints
|
||||||
* @param {?Owt.Base.VideoTrackConstraints} videoConstraints
|
* @param {?Owt.Base.VideoTrackConstraints} videoConstraints
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class StreamConstraints {
|
class StreamConstraints {
|
||||||
// eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
constructor(audioConstraints = false, videoConstraints = false) {
|
constructor(audioConstraints = false, videoConstraints = false) {
|
||||||
@ -5631,22 +5618,20 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
* @memberof Owt.Base.MediaStreamDeviceConstraints
|
* @memberof Owt.Base.MediaStreamDeviceConstraints
|
||||||
* @instance
|
* @instance
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.video = videoConstraints;
|
this.video = videoConstraints;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // eslint-disable-next-line require-jsdoc
|
// eslint-disable-next-line require-jsdoc
|
||||||
|
|
||||||
function isVideoConstrainsForScreenCast(constraints) {
|
function isVideoConstrainsForScreenCast(constraints) {
|
||||||
return typeof constraints.video === 'object' && constraints.video.source === VideoSourceInfo.SCREENCAST;
|
return typeof constraints.video === 'object' && constraints.video.source === VideoSourceInfo.SCREENCAST;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class MediaStreamFactory
|
* @class MediaStreamFactory
|
||||||
* @classDesc A factory to create MediaStream. You can also create MediaStream by yourself.
|
* @classDesc A factory to create MediaStream. You can also create MediaStream by yourself.
|
||||||
* @memberof Owt.Base
|
* @memberof Owt.Base
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
class MediaStreamFactory {
|
class MediaStreamFactory {
|
||||||
/**
|
/**
|
||||||
* @function createMediaStream
|
* @function createMediaStream
|
||||||
@ -5665,29 +5650,23 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
if (typeof constraints !== 'object' || !constraints.audio && !constraints.video) {
|
if (typeof constraints !== 'object' || !constraints.audio && !constraints.video) {
|
||||||
return Promise.reject(new TypeError('Invalid constrains'));
|
return Promise.reject(new TypeError('Invalid constrains'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.SCREENCAST) {
|
if (!isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.SCREENCAST) {
|
||||||
return Promise.reject(new TypeError('Cannot share screen without video.'));
|
return Promise.reject(new TypeError('Cannot share screen without video.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints) && !isChrome() && !isFirefox()) {
|
if (isVideoConstrainsForScreenCast(constraints) && !isChrome() && !isFirefox()) {
|
||||||
return Promise.reject(new TypeError('Screen sharing only supports Chrome and Firefox.'));
|
return Promise.reject(new TypeError('Screen sharing only supports Chrome and Firefox.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source !== AudioSourceInfo.SCREENCAST) {
|
if (isVideoConstrainsForScreenCast(constraints) && typeof constraints.audio === 'object' && constraints.audio.source !== AudioSourceInfo.SCREENCAST) {
|
||||||
return Promise.reject(new TypeError('Cannot capture video from screen cast while capture audio from' + ' other source.'));
|
return Promise.reject(new TypeError('Cannot capture video from screen cast while capture audio from' + ' other source.'));
|
||||||
} // Check and convert constraints.
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Check and convert constraints.
|
||||||
if (!constraints.audio && !constraints.video) {
|
if (!constraints.audio && !constraints.video) {
|
||||||
return Promise.reject(new TypeError('At least one of audio and video must be requested.'));
|
return Promise.reject(new TypeError('At least one of audio and video must be requested.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const mediaConstraints = Object.create({});
|
const mediaConstraints = Object.create({});
|
||||||
|
|
||||||
if (typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.MIC) {
|
if (typeof constraints.audio === 'object' && constraints.audio.source === AudioSourceInfo.MIC) {
|
||||||
mediaConstraints.audio = Object.create({});
|
mediaConstraints.audio = Object.create({});
|
||||||
|
|
||||||
if (isEdge()) {
|
if (isEdge()) {
|
||||||
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
|
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
|
||||||
} else {
|
} else {
|
||||||
@ -5702,14 +5681,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
mediaConstraints.audio = constraints.audio;
|
mediaConstraints.audio = constraints.audio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof constraints.video === 'object') {
|
if (typeof constraints.video === 'object') {
|
||||||
mediaConstraints.video = Object.create({});
|
mediaConstraints.video = Object.create({});
|
||||||
|
|
||||||
if (typeof constraints.video.frameRate === 'number') {
|
if (typeof constraints.video.frameRate === 'number') {
|
||||||
mediaConstraints.video.frameRate = constraints.video.frameRate;
|
mediaConstraints.video.frameRate = constraints.video.frameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constraints.video.resolution && constraints.video.resolution.width && constraints.video.resolution.height) {
|
if (constraints.video.resolution && constraints.video.resolution.width && constraints.video.resolution.height) {
|
||||||
if (constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
if (constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
||||||
mediaConstraints.video.width = constraints.video.resolution.width;
|
mediaConstraints.video.width = constraints.video.resolution.width;
|
||||||
@ -5721,27 +5697,23 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
mediaConstraints.video.height.exact = constraints.video.resolution.height;
|
mediaConstraints.video.height.exact = constraints.video.resolution.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof constraints.video.deviceId === 'string') {
|
if (typeof constraints.video.deviceId === 'string') {
|
||||||
mediaConstraints.video.deviceId = {
|
mediaConstraints.video.deviceId = {
|
||||||
exact: constraints.video.deviceId
|
exact: constraints.video.deviceId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFirefox() && constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
if (isFirefox() && constraints.video.source === VideoSourceInfo.SCREENCAST) {
|
||||||
mediaConstraints.video.mediaSource = 'screen';
|
mediaConstraints.video.mediaSource = 'screen';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mediaConstraints.video = constraints.video;
|
mediaConstraints.video = constraints.video;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isVideoConstrainsForScreenCast(constraints)) {
|
if (isVideoConstrainsForScreenCast(constraints)) {
|
||||||
return navigator.mediaDevices.getDisplayMedia(mediaConstraints);
|
return navigator.mediaDevices.getDisplayMedia(mediaConstraints);
|
||||||
} else {
|
} else {
|
||||||
return navigator.mediaDevices.getUserMedia(mediaConstraints);
|
return navigator.mediaDevices.getUserMedia(mediaConstraints);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copyright (C) <2018> Intel Corporation
|
// Copyright (C) <2018> Intel Corporation
|
||||||
@ -5782,34 +5754,26 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.listener = {};
|
this.listener = {};
|
||||||
this.type = type | '';
|
this.type = type | '';
|
||||||
}
|
}
|
||||||
|
|
||||||
on(event, fn) {
|
on(event, fn) {
|
||||||
if (!this.listener[event]) {
|
if (!this.listener[event]) {
|
||||||
this.listener[event] = [];
|
this.listener[event] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listener[event].push(fn);
|
this.listener[event].push(fn);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
off(event, fn) {
|
off(event, fn) {
|
||||||
if (this.listener[event]) {
|
if (this.listener[event]) {
|
||||||
var index = this.listener[event].indexOf(fn);
|
var index = this.listener[event].indexOf(fn);
|
||||||
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
this.listener[event].splice(index, 1);
|
this.listener[event].splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
offAll() {
|
offAll() {
|
||||||
this.listener = {};
|
this.listener = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(event, data) {
|
dispatch(event, data) {
|
||||||
if (this.listener[event]) {
|
if (this.listener[event]) {
|
||||||
this.listener[event].map(each => {
|
this.listener[event].map(each => {
|
||||||
@ -5817,10 +5781,8 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var bind = function bind(fn, thisArg) {
|
var bind = function bind(fn, thisArg) {
|
||||||
@ -7861,11 +7823,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
usedatachannel: false
|
usedatachannel: false
|
||||||
};
|
};
|
||||||
this.options = Object.assign({}, defaults, options);
|
this.options = Object.assign({}, defaults, options);
|
||||||
|
|
||||||
if (this.options.debug) {
|
if (this.options.debug) {
|
||||||
setLogger();
|
setLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.e = {
|
this.e = {
|
||||||
onicecandidate: this._onIceCandidate.bind(this),
|
onicecandidate: this._onIceCandidate.bind(this),
|
||||||
ontrack: this._onTrack.bind(this),
|
ontrack: this._onTrack.bind(this),
|
||||||
@ -7878,13 +7838,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
};
|
};
|
||||||
this._remoteStream = null;
|
this._remoteStream = null;
|
||||||
this._localStream = null;
|
this._localStream = null;
|
||||||
|
this._tracks = [];
|
||||||
this.pc = new RTCPeerConnection(null);
|
this.pc = new RTCPeerConnection(null);
|
||||||
this.pc.onicecandidate = this.e.onicecandidate;
|
this.pc.onicecandidate = this.e.onicecandidate;
|
||||||
this.pc.onicecandidateerror = this.e.onicecandidateerror;
|
this.pc.onicecandidateerror = this.e.onicecandidateerror;
|
||||||
this.pc.ontrack = this.e.ontrack;
|
this.pc.ontrack = this.e.ontrack;
|
||||||
this.pc.onconnectionstatechange = this.e.onconnectionstatechange;
|
this.pc.onconnectionstatechange = this.e.onconnectionstatechange;
|
||||||
this.datachannel = null;
|
this.datachannel = null;
|
||||||
|
|
||||||
if (this.options.usedatachannel) {
|
if (this.options.usedatachannel) {
|
||||||
this.datachannel = this.pc.createDataChannel('chat');
|
this.datachannel = this.pc.createDataChannel('chat');
|
||||||
this.datachannel.onclose = this.e.ondatachannelclose;
|
this.datachannel.onclose = this.e.ondatachannelclose;
|
||||||
@ -7892,12 +7852,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.datachannel.onmessage = this.e.ondatachannelmsg;
|
this.datachannel.onmessage = this.e.ondatachannelmsg;
|
||||||
this.datachannel.onopen = this.e.ondatachannelopen;
|
this.datachannel.onopen = this.e.ondatachannelopen;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable)) this.start();else this.receive();
|
if (!this.options.recvOnly && (this.options.audioEnable || this.options.videoEnable)) this.start();else this.receive();
|
||||||
}
|
}
|
||||||
|
|
||||||
receive() {
|
receive() {
|
||||||
|
|
||||||
|
//debug.error(this.TAG,'this not implement');
|
||||||
const AudioTransceiverInit = {
|
const AudioTransceiverInit = {
|
||||||
direction: 'recvonly',
|
direction: 'recvonly',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
@ -7906,15 +7865,12 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
direction: 'recvonly',
|
direction: 'recvonly',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.videoEnable) {
|
if (this.options.videoEnable) {
|
||||||
this.pc.addTransceiver('video', VideoTransceiverInit);
|
this.pc.addTransceiver('video', VideoTransceiverInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.audioEnable) {
|
if (this.options.audioEnable) {
|
||||||
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.pc.createOffer().then(desc => {
|
this.pc.createOffer().then(desc => {
|
||||||
log(this.TAG, 'offer:', desc.sdp);
|
log(this.TAG, 'offer:', desc.sdp);
|
||||||
this.pc.setLocalDescription(desc).then(() => {
|
this.pc.setLocalDescription(desc).then(() => {
|
||||||
@ -7928,13 +7884,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
let ret = response.data; //JSON.parse(response.data);
|
let ret = response.data; //JSON.parse(response.data);
|
||||||
|
|
||||||
if (ret.code != 0) {
|
if (ret.code != 0) {
|
||||||
// mean failed for offer/anwser exchange
|
// mean failed for offer/anwser exchange
|
||||||
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let anwser = {};
|
let anwser = {};
|
||||||
anwser.sdp = ret.sdp;
|
anwser.sdp = ret.sdp;
|
||||||
anwser.type = 'answer';
|
anwser.type = 'answer';
|
||||||
@ -7950,11 +7904,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, e);
|
error(this.TAG, e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
let videoConstraints = false;
|
let videoConstraints = false;
|
||||||
let audioConstraints = false;
|
let audioConstraints = false;
|
||||||
|
|
||||||
if (this.options.useCamera) {
|
if (this.options.useCamera) {
|
||||||
if (this.options.videoEnable) videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
if (this.options.videoEnable) videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
||||||
if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC);
|
if (this.options.audioEnable) audioConstraints = new AudioTrackConstraints(AudioSourceInfo.MIC);
|
||||||
@ -7969,11 +7921,9 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.resolution.w != 0 && this.options.resolution.h != 0 && typeof videoConstraints == 'object') {
|
if (this.options.resolution.w != 0 && this.options.resolution.h != 0 && typeof videoConstraints == 'object') {
|
||||||
videoConstraints.resolution = new Resolution(this.options.resolution.w, this.options.resolution.h);
|
videoConstraints.resolution = new Resolution(this.options.resolution.w, this.options.resolution.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
MediaStreamFactory.createMediaStream(new StreamConstraints(audioConstraints, videoConstraints)).then(stream => {
|
MediaStreamFactory.createMediaStream(new StreamConstraints(audioConstraints, videoConstraints)).then(stream => {
|
||||||
this._localStream = stream;
|
this._localStream = stream;
|
||||||
this.dispatch(Events$1.WEBRTC_ON_LOCAL_STREAM, stream);
|
this.dispatch(Events$1.WEBRTC_ON_LOCAL_STREAM, stream);
|
||||||
@ -7985,7 +7935,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
direction: 'sendrecv',
|
direction: 'sendrecv',
|
||||||
sendEncodings: []
|
sendEncodings: []
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.options.simulcast && stream.getVideoTracks().length > 0) {
|
if (this.options.simulcast && stream.getVideoTracks().length > 0) {
|
||||||
VideoTransceiverInit.sendEncodings = [{
|
VideoTransceiverInit.sendEncodings = [{
|
||||||
rid: 'h',
|
rid: 'h',
|
||||||
@ -8003,7 +7952,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
scaleResolutionDownBy: 4
|
scaleResolutionDownBy: 4
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.audioEnable) {
|
if (this.options.audioEnable) {
|
||||||
if (stream.getAudioTracks().length > 0) {
|
if (stream.getAudioTracks().length > 0) {
|
||||||
this.pc.addTransceiver(stream.getAudioTracks()[0], AudioTransceiverInit);
|
this.pc.addTransceiver(stream.getAudioTracks()[0], AudioTransceiverInit);
|
||||||
@ -8012,7 +7960,6 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
this.pc.addTransceiver('audio', AudioTransceiverInit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.videoEnable) {
|
if (this.options.videoEnable) {
|
||||||
if (stream.getVideoTracks().length > 0) {
|
if (stream.getVideoTracks().length > 0) {
|
||||||
this.pc.addTransceiver(stream.getVideoTracks()[0], VideoTransceiverInit);
|
this.pc.addTransceiver(stream.getVideoTracks()[0], VideoTransceiverInit);
|
||||||
@ -8021,14 +7968,13 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
this.pc.addTransceiver('video', VideoTransceiverInit);
|
this.pc.addTransceiver('video', VideoTransceiverInit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
stream.getTracks().forEach((track,idx)=>{
|
stream.getTracks().forEach((track,idx)=>{
|
||||||
debug.log(this.TAG,track);
|
debug.log(this.TAG,track);
|
||||||
this.pc.addTrack(track);
|
this.pc.addTrack(track);
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
this.pc.createOffer().then(desc => {
|
this.pc.createOffer().then(desc => {
|
||||||
log(this.TAG, 'offer:', desc.sdp);
|
log(this.TAG, 'offer:', desc.sdp);
|
||||||
this.pc.setLocalDescription(desc).then(() => {
|
this.pc.setLocalDescription(desc).then(() => {
|
||||||
@ -8042,13 +7988,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
let ret = response.data; //JSON.parse(response.data);
|
let ret = response.data; //JSON.parse(response.data);
|
||||||
|
|
||||||
if (ret.code != 0) {
|
if (ret.code != 0) {
|
||||||
// mean failed for offer/anwser exchange
|
// mean failed for offer/anwser exchange
|
||||||
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
this.dispatch(Events$1.WEBRTC_OFFER_ANWSER_EXCHANGE_FAILED, ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let anwser = {};
|
let anwser = {};
|
||||||
anwser.sdp = ret.sdp;
|
anwser.sdp = ret.sdp;
|
||||||
anwser.type = 'answer';
|
anwser.type = 'answer';
|
||||||
@ -8064,9 +8008,11 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, e);
|
error(this.TAG, e);
|
||||||
});
|
});
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
this.dispatch(Events$1.CAPTURE_STREAM_FAILED); //debug.error(this.TAG,e);
|
this.dispatch(Events$1.CAPTURE_STREAM_FAILED);
|
||||||
}); //const offerOptions = {};
|
//debug.error(this.TAG,e);
|
||||||
|
});
|
||||||
|
|
||||||
|
//const offerOptions = {};
|
||||||
/*
|
/*
|
||||||
if (typeof this.pc.addTransceiver === 'function') {
|
if (typeof this.pc.addTransceiver === 'function') {
|
||||||
// |direction| seems not working on Safari.
|
// |direction| seems not working on Safari.
|
||||||
@ -8081,48 +8027,48 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
|
|
||||||
_onIceCandidate(event) {
|
_onIceCandidate(event) {
|
||||||
if (event.candidate) {
|
if (event.candidate) {
|
||||||
log('Remote ICE candidate: \n ' + event.candidate.candidate); // Send the candidate to the remote peer
|
log(this.TAG, 'Remote ICE candidate: \n ' + event.candidate.candidate);
|
||||||
|
// Send the candidate to the remote peer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onTrack(event) {
|
_onTrack(event) {
|
||||||
|
this._tracks.push(event.track);
|
||||||
if (this.options.element && event.streams && event.streams.length > 0) {
|
if (this.options.element && event.streams && event.streams.length > 0) {
|
||||||
this.options.element.srcObject = event.streams[0];
|
this.options.element.srcObject = event.streams[0];
|
||||||
this._remoteStream = event.streams[0];
|
this._remoteStream = event.streams[0];
|
||||||
this.dispatch(Events$1.WEBRTC_ON_REMOTE_STREAMS, event);
|
this.dispatch(Events$1.WEBRTC_ON_REMOTE_STREAMS, event);
|
||||||
} else {
|
} else {
|
||||||
error('element pararm is failed');
|
if (this.pc.getReceivers().length == this._tracks.length) {
|
||||||
|
log(this.TAG, 'play remote stream ');
|
||||||
|
this._remoteStream = new MediaStream(this._tracks);
|
||||||
|
this.options.element.srcObject = this._remoteStream;
|
||||||
|
} else {
|
||||||
|
error(this.TAG, 'wait stream track finish');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onIceCandidateError(event) {
|
_onIceCandidateError(event) {
|
||||||
this.dispatch(Events$1.WEBRTC_ICE_CANDIDATE_ERROR, event);
|
this.dispatch(Events$1.WEBRTC_ICE_CANDIDATE_ERROR, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onconnectionstatechange(event) {
|
_onconnectionstatechange(event) {
|
||||||
this.dispatch(Events$1.WEBRTC_ON_CONNECTION_STATE_CHANGE, this.pc.connectionState);
|
this.dispatch(Events$1.WEBRTC_ON_CONNECTION_STATE_CHANGE, this.pc.connectionState);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelOpen(event) {
|
_onDataChannelOpen(event) {
|
||||||
log(this.TAG, 'ondatachannel open:', event);
|
log(this.TAG, 'ondatachannel open:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_OPEN, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_OPEN, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelMsg(event) {
|
_onDataChannelMsg(event) {
|
||||||
log(this.TAG, 'ondatachannel msg:', event);
|
log(this.TAG, 'ondatachannel msg:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_MSG, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_MSG, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelErr(event) {
|
_onDataChannelErr(event) {
|
||||||
log(this.TAG, 'ondatachannel err:', event);
|
log(this.TAG, 'ondatachannel err:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_ERR, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_ERR, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onDataChannelClose(event) {
|
_onDataChannelClose(event) {
|
||||||
log(this.TAG, 'ondatachannel close:', event);
|
log(this.TAG, 'ondatachannel close:', event);
|
||||||
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_CLOSE, event);
|
this.dispatch(Events$1.WEBRTC_ON_DATA_CHANNEL_CLOSE, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMsg(data) {
|
sendMsg(data) {
|
||||||
if (this.datachannel != null) {
|
if (this.datachannel != null) {
|
||||||
this.datachannel.send(data);
|
this.datachannel.send(data);
|
||||||
@ -8130,47 +8076,42 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
error(this.TAG, 'data channel is null');
|
error(this.TAG, 'data channel is null');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
closeDataChannel() {
|
closeDataChannel() {
|
||||||
if (this.datachannel) {
|
if (this.datachannel) {
|
||||||
this.datachannel.close();
|
this.datachannel.close();
|
||||||
this.datachannel = null;
|
this.datachannel = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.closeDataChannel();
|
this.closeDataChannel();
|
||||||
|
|
||||||
if (this.pc) {
|
if (this.pc) {
|
||||||
this.pc.close();
|
this.pc.close();
|
||||||
this.pc = null;
|
this.pc = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options) {
|
if (this.options) {
|
||||||
this.options = null;
|
this.options = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._localStream) {
|
if (this._localStream) {
|
||||||
this._localStream.getTracks().forEach((track, idx) => {
|
this._localStream.getTracks().forEach((track, idx) => {
|
||||||
track.stop();
|
track.stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._remoteStream) {
|
if (this._remoteStream) {
|
||||||
this._remoteStream.getTracks().forEach((track, idx) => {
|
this._remoteStream.getTracks().forEach((track, idx) => {
|
||||||
track.stop();
|
track.stop();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
this._tracks.forEach((track, idx) => {
|
||||||
|
track.stop();
|
||||||
|
});
|
||||||
|
this._tracks = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get remoteStream() {
|
get remoteStream() {
|
||||||
return this._remoteStream;
|
return this._remoteStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
get localStream() {
|
get localStream() {
|
||||||
return this._localStream;
|
return this._localStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const quickScan = [{
|
const quickScan = [{
|
||||||
@ -8224,20 +8165,17 @@ var ZLMRTCClient = (function (exports) {
|
|||||||
let resolutions = [];
|
let resolutions = [];
|
||||||
let ok = 0;
|
let ok = 0;
|
||||||
let err = 0;
|
let err = 0;
|
||||||
|
|
||||||
for (let i = 0; i < quickScan.length; ++i) {
|
for (let i = 0; i < quickScan.length; ++i) {
|
||||||
let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
let videoConstraints = new VideoTrackConstraints(VideoSourceInfo.CAMERA);
|
||||||
videoConstraints.resolution = new Resolution(quickScan[i].width, quickScan[i].height);
|
videoConstraints.resolution = new Resolution(quickScan[i].width, quickScan[i].height);
|
||||||
MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => {
|
MediaStreamFactory.createMediaStream(new StreamConstraints(false, videoConstraints)).then(stream => {
|
||||||
resolutions.push(quickScan[i]);
|
resolutions.push(quickScan[i]);
|
||||||
ok++;
|
ok++;
|
||||||
|
|
||||||
if (ok + err == quickScan.length) {
|
if (ok + err == quickScan.length) {
|
||||||
resolve(resolutions);
|
resolve(resolutions);
|
||||||
}
|
}
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
err++;
|
err++;
|
||||||
|
|
||||||
if (ok + err == quickScan.length) {
|
if (ok + err == quickScan.length) {
|
||||||
resolve(resolutions);
|
resolve(resolutions);
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user