package com.sjyt.icom.asst.service;

import com.sjyt.icom.asst.common.exception.SrsErrorStatusException;
import com.sjyt.icom.asst.common.model.sdp.AnswerDto;
import com.sjyt.icom.asst.common.model.sdp.OfferDTO;
import com.sjyt.icom.asst.service.httpapi.SrsHttpApi;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * <p>TODO</p>
 *
 * @author renyanru
 * @version V1.0.0
 * @date 2022/6/16 12:45
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class TestSrsHttpApi {
    @Autowired
    private SrsHttpApi srsHttpApi;

    @Test
    public void testPost() {
        OfferDTO offerDto = OfferDTO.builder().api("https://101.37.66.30/rtc/v1/publish/")
                .sdp("v=0\r\no=- 7703503545190617348 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0 1\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 63 103 104 9 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:d6S2\r\na=ice-pwd:OGJYRMh8RTzMXvEVbuRXly+r\r\na=ice-options:trickle\r\na=fingerprint:sha-256 0E:4B:36:13:DC:A7:02:A4:5B:4B:43:6F:37:1A:DC:FF:C0:85:F7:FB:57:1C:08:D9:D3:76:1D:EE:C0:D5:9F:A6\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=sendonly\r\na=msid:- 05166a0e-ef35-4000-947f-b4d237e587e6\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:103 ISAC/16000\r\na=rtpmap:104 ISAC/32000\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:106 CN/32000\r\na=rtpmap:105 CN/16000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:112 telephone-event/32000\r\na=rtpmap:113 telephone-event/16000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3939064954 cname:WQYFIaTIIwYk4Hue\r\na=ssrc:3939064954 msid:- 05166a0e-ef35-4000-947f-b4d237e587e6\r\na=ssrc:3939064954 mslabel:-\r\na=ssrc:3939064954 label:05166a0e-ef35-4000-947f-b4d237e587e6\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 121 125 107 108 109 124 120 123 119 35 36 41 42 116 117 118\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:d6S2\r\na=ice-pwd:OGJYRMh8RTzMXvEVbuRXly+r\r\na=ice-options:trickle\r\na=fingerprint:sha-256 0E:4B:36:13:DC:A7:02:A4:5B:4B:43:6F:37:1A:DC:FF:C0:85:F7:FB:57:1C:08:D9:D3:76:1D:EE:C0:D5:9F:A6\r\na=setup:actpass\r\na=mid:1\r\na=extmap:14 urn:ietf:params:rtp-hdrext:toffset\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:13 urn:3gpp:video-orientation\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\na=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\na=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\na=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\na=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\na=sendonly\r\na=msid:- b326858a-fd33-4030-9964-e0d3e16abcf5\r\na=rtcp-mux\r\na=rtcp-rsize\r\na=rtpmap:96 VP8/90000\r\na=rtcp-fb:96 goog-remb\r\na=rtcp-fb:96 transport-cc\r\na=rtcp-fb:96 ccm fir\r\na=rtcp-fb:96 nack\r\na=rtcp-fb:96 nack pli\r\na=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtpmap:98 VP9/90000\r\na=rtcp-fb:98 goog-remb\r\na=rtcp-fb:98 transport-cc\r\na=rtcp-fb:98 ccm fir\r\na=rtcp-fb:98 nack\r\na=rtcp-fb:98 nack pli\r\na=fmtp:98 profile-id=0\r\na=rtpmap:99 rtx/90000\r\na=fmtp:99 apt=98\r\na=rtpmap:100 VP9/90000\r\na=rtcp-fb:100 goog-remb\r\na=rtcp-fb:100 transport-cc\r\na=rtcp-fb:100 ccm fir\r\na=rtcp-fb:100 nack\r\na=rtcp-fb:100 nack pli\r\na=fmtp:100 profile-id=2\r\na=rtpmap:101 rtx/90000\r\na=fmtp:101 apt=100\r\na=rtpmap:127 H264/90000\r\na=rtcp-fb:127 goog-remb\r\na=rtcp-fb:127 transport-cc\r\na=rtcp-fb:127 ccm fir\r\na=rtcp-fb:127 nack\r\na=rtcp-fb:127 nack pli\r\na=fmtp:127 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\na=rtpmap:121 rtx/90000\r\na=fmtp:121 apt=127\r\na=rtpmap:125 H264/90000\r\na=rtcp-fb:125 goog-remb\r\na=rtcp-fb:125 transport-cc\r\na=rtcp-fb:125 ccm fir\r\na=rtcp-fb:125 nack\r\na=rtcp-fb:125 nack pli\r\na=fmtp:125 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f\r\na=rtpmap:107 rtx/90000\r\na=fmtp:107 apt=125\r\na=rtpmap:108 H264/90000\r\na=rtcp-fb:108 goog-remb\r\na=rtcp-fb:108 transport-cc\r\na=rtcp-fb:108 ccm fir\r\na=rtcp-fb:108 nack\r\na=rtcp-fb:108 nack pli\r\na=fmtp:108 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\na=rtpmap:109 rtx/90000\r\na=fmtp:109 apt=108\r\na=rtpmap:124 H264/90000\r\na=rtcp-fb:124 goog-remb\r\na=rtcp-fb:124 transport-cc\r\na=rtcp-fb:124 ccm fir\r\na=rtcp-fb:124 nack\r\na=rtcp-fb:124 nack pli\r\na=fmtp:124 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\na=rtpmap:120 rtx/90000\r\na=fmtp:120 apt=124\r\na=rtpmap:123 H264/90000\r\na=rtcp-fb:123 goog-remb\r\na=rtcp-fb:123 transport-cc\r\na=rtcp-fb:123 ccm fir\r\na=rtcp-fb:123 nack\r\na=rtcp-fb:123 nack pli\r\na=fmtp:123 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f\r\na=rtpmap:119 rtx/90000\r\na=fmtp:119 apt=123\r\na=rtpmap:35 H264/90000\r\na=rtcp-fb:35 goog-remb\r\na=rtcp-fb:35 transport-cc\r\na=rtcp-fb:35 ccm fir\r\na=rtcp-fb:35 nack\r\na=rtcp-fb:35 nack pli\r\na=fmtp:35 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=4d001f\r\na=rtpmap:36 rtx/90000\r\na=fmtp:36 apt=35\r\na=rtpmap:41 AV1/90000\r\na=rtcp-fb:41 goog-remb\r\na=rtcp-fb:41 transport-cc\r\na=rtcp-fb:41 ccm fir\r\na=rtcp-fb:41 nack\r\na=rtcp-fb:41 nack pli\r\na=rtpmap:42 rtx/90000\r\na=fmtp:42 apt=41\r\na=rtpmap:116 red/90000\r\na=rtpmap:117 rtx/90000\r\na=fmtp:117 apt=116\r\na=rtpmap:118 ulpfec/90000\r\na=ssrc-group:FID 1115532288 2992526420\r\na=ssrc:1115532288 cname:WQYFIaTIIwYk4Hue\r\na=ssrc:1115532288 msid:- b326858a-fd33-4030-9964-e0d3e16abcf5\r\na=ssrc:1115532288 mslabel:-\r\na=ssrc:1115532288 label:b326858a-fd33-4030-9964-e0d3e16abcf5\r\na=ssrc:2992526420 cname:WQYFIaTIIwYk4Hue\r\na=ssrc:2992526420 msid:- b326858a-fd33-4030-9964-e0d3e16abcf5\r\na=ssrc:2992526420 mslabel:-\r\na=ssrc:2992526420 label:b326858a-fd33-4030-9964-e0d3e16abcf5\r\n")
                .streamurl("webrtc://101.37.66.30:443/live/1539138886658297856/1539138886658297857?token?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsImV4cCI6MTY1NTc5Nzg4MSwiaWF0IjoxNjU1Nzk0MjgxLCJ1c2VybmFtZSI6Ijg4NGIxZTUxYjM1YTQ3ZDZiZjUxY2I1MmEyMmFkNjcyIn0.PqRGrVEcZ6gLHa5iqYPmgcsUH8vQTE9oUWj1HdmzShA=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJhdXRoMCIsImV4cCI6MTY1NTc5Nzg4MSwiaWF0IjoxNjU1Nzk0MjgxLCJ1c2VybmFtZSI6Ijg4NGIxZTUxYjM1YTQ3ZDZiZjUxY2I1MmEyMmFkNjcyIn0.PqRGrVEcZ6gLHa5iqYPmgcsUH8vQTE9oUWj1HdmzShA&uid=884b1e51b35a47d6bf51cb52a22ad672&uid=884b1e51b35a47d6bf51cb52a22ad672")
                .build();
        AnswerDto publish=null;
        try {
            publish= srsHttpApi.publish(offerDto);
        }catch (SrsErrorStatusException e){
            System.out.println(1);
        }
        System.out.println(publish);
    }

}
