diff --git a/trunk/research/players/srs_gb28181.html b/trunk/research/players/srs_gb28181.html index b2094fa4c..7d3a82d0f 100644 --- a/trunk/research/players/srs_gb28181.html +++ b/trunk/research/players/srs_gb28181.html @@ -123,8 +123,9 @@
- 需要后台配置rtc功能才能正常启用, rtc配置请参考如下 - https://github.com/ossrs/srs/issues/307#issuecomment-602193458 +
RTC播放,需要后台启用RTC功能才能正常播放, + RTC配置参考 +

@@ -1090,82 +1091,83 @@
                 startPlay($("#txt_rtc_url").val());
             });
 
+
+            $("#rtc_player_modal").on("hide", function(){
+                console.log("rtc stop");
+                if (pc) {
+                    pc.close();
+                 }
+             });
+
             var startPlay = function(url) {
-            $('#rtc_media_player').show();
-            var urlObject = parse_rtmp_url(url);
-            var schema = window.location.protocol;
+                    $('#rtc_media_player').show();
+                    var urlObject = parse_rtmp_url(url);
+                    var schema = window.location.protocol;
 
-            // Close PC when user replay.
-            if (pc) {
-                pc.close();
-            }
-
-         
-
-            pc = new RTCPeerConnection(null);
-            pc.onaddstream = function (event) {
-                console.debug(event.stream);
-                $('#rtc_media_player').prop('srcObject', event.stream);
-            };
-            new Promise(function(resolve, reject) {
-                pc.addTransceiver("audio", {direction: "recvonly"});
-                pc.addTransceiver("video", {direction: "recvonly"});
-
-                pc.createOffer(function(offer){
-                    resolve(offer);
-                },function(reason){
-                    reject(reason);
-                });
-            }).then(function(offer) {
-                return pc.setLocalDescription(offer).then(function(){ return offer; });
-            }).then(function(offer) {
-                return new Promise(function(resolve, reject) {
-                    var port = urlObject.port || 1985;
-
-                    // @see https://github.com/rtcdn/rtcdn-draft
-                    var api = urlObject.user_query.play || '/rtc/v1/play/';
-                    if (api.lastIndexOf('/') != api.length - 1) {
-                        api += '/';
+                    // Close PC when user replay.
+                    if (pc) {
+                        pc.close();
                     }
 
-                    var url = schema + '//' + urlObject.server + ':' + port + api;
-                    for (var key in urlObject.user_query) {
-                        if (key != 'api' && key != 'play') {
-                            url += '&' + key + '=' + urlObject.user_query[key];
-                        }
-                    }
-                    // Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
-                    url = url.replace(api + '&', api + '?');
-
-                    // @see https://github.com/rtcdn/rtcdn-draft
-                    var data = {
-                        api: url, streamurl: urlObject.url, clientip: null, sdp: offer.sdp
+                    pc = new RTCPeerConnection(null);
+                    pc.onaddstream = function (event) {
+                        console.debug(event.stream);
+                        $('#rtc_media_player').prop('srcObject', event.stream);
                     };
-                    console.log("offer: " + JSON.stringify(data));
+                    new Promise(function(resolve, reject) {
+                        pc.addTransceiver("audio", {direction: "recvonly"});
+                        pc.addTransceiver("video", {direction: "recvonly"});
 
-                    $.ajax({
-                        type: "POST", url: url, data: JSON.stringify(data),
-                        contentType:'application/json', dataType: 'json'
-                    }).done(function(data) {
-                        console.log("answer: " + JSON.stringify(data));
-                        resolve(data.sdp);
-                    }).fail(function(reason){
-                        reject(reason);
+                        pc.createOffer(function(offer){
+                            resolve(offer);
+                        },function(reason){
+                            reject(reason);
+                        });
+                    }).then(function(offer) {
+                        return pc.setLocalDescription(offer).then(function(){ return offer; });
+                    }).then(function(offer) {
+                        return new Promise(function(resolve, reject) {
+                            var port = urlObject.port || 1985;
+
+                            // @see https://github.com/rtcdn/rtcdn-draft
+                            var api = urlObject.user_query.play || '/rtc/v1/play/';
+                            if (api.lastIndexOf('/') != api.length - 1) {
+                                api += '/';
+                            }
+
+                            var url = schema + '//' + urlObject.server + ':' + port + api;
+                            for (var key in urlObject.user_query) {
+                                if (key != 'api' && key != 'play') {
+                                    url += '&' + key + '=' + urlObject.user_query[key];
+                                }
+                            }
+                            // Replace /rtc/v1/play/&k=v to /rtc/v1/play/?k=v
+                            url = url.replace(api + '&', api + '?');
+
+                            // @see https://github.com/rtcdn/rtcdn-draft
+                            var data = {
+                                api: url, streamurl: urlObject.url, clientip: null, sdp: offer.sdp
+                            };
+                            console.log("offer: " + JSON.stringify(data));
+
+                            $.ajax({
+                                type: "POST", url: url, data: JSON.stringify(data),
+                                contentType:'application/json', dataType: 'json'
+                            }).done(function(data) {
+                                console.log("answer: " + JSON.stringify(data));
+                                resolve(data.sdp);
+                            }).fail(function(reason){
+                                reject(reason);
+                            });
+                        });
+                    }).then(function(answer) {
+                        return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
+                    }).catch(function(reason) {
+                        throw reason;
                     });
-                });
-            }).then(function(answer) {
-                return pc.setRemoteDescription(new RTCSessionDescription({type: 'answer', sdp: answer}));
-            }).catch(function(reason) {
-                throw reason;
-            });
-        };
-
-  
-            
+                };
         }
 
-
-
         apply_url_change();
     };