1+ import EventEmitter from '/js/lib/eventemitter.js' ;
2+ import inherit from '/js/lib/inherit.js' ;
3+
14/**
25 * PeerHandler
36 * @param options
@@ -12,8 +15,6 @@ function PeerHandler(options) {
1215 const RTCSessionDescription =
1316 window . RTCSessionDescription || window . mozRTCSessionDescription || window . webkitRTCSessionDescription ;
1417 const RTCIceCandidate = window . RTCIceCandidate || window . mozRTCIceCandidate || window . webkitRTCIceCandidate ;
15- const browserVersion = DetectRTC . browser . version ;
16- const isEdge = DetectRTC . browser . isEdge && browserVersion >= 15063 ; // 15버전 이상
1718
1819 const that = this ;
1920 const send = options . send ;
@@ -31,22 +32,14 @@ function PeerHandler(options) {
3132 } ;
3233
3334 let localStream = null ;
35+ let resolution = {
36+ width : 1280 ,
37+ height : 720 ,
38+ } ;
3439 let peer = null ; // offer or answer peer
3540 let peerConnectionOptions = {
3641 optional : [ { DtlsSrtpKeyAgreement : 'true' } ] ,
3742 } ;
38- let mediaConstraints = {
39- mandatory : {
40- OfferToReceiveAudio : true ,
41- OfferToReceiveVideo : true ,
42- } ,
43- } ;
44-
45- // edge is not supported
46- if ( isEdge ) {
47- peerConnectionOptions = { } ;
48- mediaConstraints = { } ;
49- }
5043
5144 /**
5245 * getUserMedia
@@ -78,19 +71,20 @@ function PeerHandler(options) {
7871 addTrack ( peer , localStream ) ; // addTrack 제외시 recvonly로 SDP 생성됨
7972 }
8073
81- peer . createOffer (
82- ( SDP ) => {
74+ peer
75+ . createOffer ( )
76+ . then ( ( SDP ) => {
8377 peer . setLocalDescription ( SDP ) ;
8478 console . log ( 'Sending offer description' , SDP ) ;
8579
8680 send ( {
8781 to : 'all' ,
8882 sdp : SDP ,
8983 } ) ;
90- } ,
91- onSdpError ,
92- mediaConstraints
93- ) ;
84+ } )
85+ . catch ( ( error ) => {
86+ console . error ( 'Error setLocalDescription' , error ) ;
87+ } ) ;
9488 }
9589
9690 /**
@@ -238,6 +232,31 @@ function PeerHandler(options) {
238232 }
239233 }
240234
235+ /**
236+ * 전송중인 영상 해상도를 다이나믹하게 변경합니다.
237+ */
238+ function changeResolution ( ) {
239+ localStream . getVideoTracks ( ) . forEach ( ( track ) => {
240+ console . log ( 'changeResolution' , track , track . getConstraints ( ) , track . applyConstraints ) ;
241+
242+ if ( resolution . height > 90 ) {
243+ resolution = {
244+ width : 160 ,
245+ height : 90 ,
246+ } ;
247+ } else {
248+ resolution = {
249+ width : 1280 ,
250+ height : 720 ,
251+ } ;
252+ }
253+
254+ track . applyConstraints ( resolution ) . then ( ( ) => {
255+ console . log ( 'changeResolution result' , track . getConstraints ( ) ) ;
256+ } ) ;
257+ } ) ;
258+ }
259+
241260 /**
242261 * signaling
243262 * @param data
@@ -278,6 +297,9 @@ function PeerHandler(options) {
278297 */
279298 this . getUserMedia = getUserMedia ;
280299 this . signaling = signaling ;
300+ this . changeResolution = changeResolution ;
281301}
282302
283303inherit ( EventEmitter , PeerHandler ) ;
304+
305+ export default PeerHandler ;
0 commit comments