modified lib-jitsi-meet dev repo
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RTCSessionDescription.js 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import sdpTransform from 'sdp-transform';
  2. /**
  3. * RTCSessionDescription implementation.
  4. */
  5. export default class RTCSessionDescription {
  6. /**
  7. * RTCSessionDescription constructor.
  8. * @param {object} [data]
  9. * @param {string} [data.type] "offer" / "answer".
  10. * @param {string} [data.sdp] SDP string.
  11. * @param {object} [data._sdpObject] SDP object generated by the
  12. * sdp-transform library.
  13. */
  14. constructor(data) {
  15. // @type {string}
  16. this._sdp = null;
  17. // @type {object}
  18. this._sdpObject = null;
  19. // @type {string}
  20. this._type = null;
  21. switch (data.type) {
  22. case 'offer':
  23. break;
  24. case 'answer':
  25. break;
  26. default:
  27. throw new TypeError(`invalid type "${data.type}"`);
  28. }
  29. this._type = data.type;
  30. if (typeof data.sdp === 'string') {
  31. this._sdp = data.sdp;
  32. try {
  33. this._sdpObject = sdpTransform.parse(data.sdp);
  34. } catch (error) {
  35. throw new Error(`invalid sdp: ${error}`);
  36. }
  37. } else if (typeof data._sdpObject === 'object') {
  38. this._sdpObject = data._sdpObject;
  39. try {
  40. this._sdp = sdpTransform.write(data._sdpObject);
  41. } catch (error) {
  42. throw new Error(`invalid sdp object: ${error}`);
  43. }
  44. } else {
  45. throw new TypeError('invalid sdp or _sdpObject');
  46. }
  47. }
  48. /**
  49. * Get type field.
  50. * @return {string}
  51. */
  52. get type() {
  53. return this._type;
  54. }
  55. /**
  56. * Get sdp field.
  57. * @return {string}
  58. */
  59. get sdp() {
  60. return this._sdp;
  61. }
  62. /**
  63. * Gets the internal sdp object.
  64. * @return {object}
  65. * @private
  66. */
  67. get sdpObject() {
  68. return this._sdpObject;
  69. }
  70. }