| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import sdpTransform from 'sdp-transform';
-
- /**
- * RTCSessionDescription implementation.
- */
- export default class RTCSessionDescription {
- /**
- * RTCSessionDescription constructor.
- * @param {object} [data]
- * @param {string} [data.type] "offer" / "answer".
- * @param {string} [data.sdp] SDP string.
- * @param {object} [data._sdpObject] SDP object generated by the
- * sdp-transform library.
- */
- constructor(data) {
- // @type {string}
- this._sdp = null;
-
- // @type {object}
- this._sdpObject = null;
-
- // @type {string}
- this._type = null;
-
- switch (data.type) {
- case 'offer':
- break;
- case 'answer':
- break;
- default:
- throw new TypeError(`invalid type "${data.type}"`);
- }
-
- this._type = data.type;
-
- if (typeof data.sdp === 'string') {
- this._sdp = data.sdp;
- try {
- this._sdpObject = sdpTransform.parse(data.sdp);
- } catch (error) {
- throw new Error(`invalid sdp: ${error}`);
- }
- } else if (typeof data._sdpObject === 'object') {
- this._sdpObject = data._sdpObject;
- try {
- this._sdp = sdpTransform.write(data._sdpObject);
- } catch (error) {
- throw new Error(`invalid sdp object: ${error}`);
- }
- } else {
- throw new TypeError('invalid sdp or _sdpObject');
- }
- }
-
- /**
- * Get type field.
- * @return {string}
- */
- get type() {
- return this._type;
- }
-
- /**
- * Get sdp field.
- * @return {string}
- */
- get sdp() {
- return this._sdp;
- }
-
- /**
- * Gets the internal sdp object.
- * @return {object}
- * @private
- */
- get sdpObject() {
- return this._sdpObject;
- }
- }
|