From 8b53826706ae715991162ebdd5b51427a2724a99 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 27 May 2020 15:05:53 +0800 Subject: [PATCH 1/3] update Former-commit-id: 811c8d95714d296ae1f8135dd80f36d05edc387c --- .../Infrastructure/Application/PagedList.cs | 4 +++ .../Infrastructure/Views/Shared/_Paged.cshtml | 28 ++++++------------- .../wwwroot/lib/jswebrtc/jswebrtc.min.js | 1 + .../wwwroot/lib/jswebrtc/player-via-html.html | 18 ++++++++++++ .../Areas/Admin/Controllers/UserController.cs | 6 +++- .../lib/local/jswebrtc/dist/jswebrtc.min.js | 1 + .../jswebrtc/examples/player-via-html.html | 18 ++++++++++++ .../jswebrtc/examples/player-via-js.html | 17 +++++++++++ 8 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 projects/IoTCenter/wwwroot/lib/jswebrtc/jswebrtc.min.js create mode 100644 projects/IoTCenter/wwwroot/lib/jswebrtc/player-via-html.html create mode 100644 projects/lib/local/jswebrtc/dist/jswebrtc.min.js create mode 100644 projects/lib/local/jswebrtc/examples/player-via-html.html create mode 100644 projects/lib/local/jswebrtc/examples/player-via-js.html diff --git a/projects/Infrastructure/Application/PagedList.cs b/projects/Infrastructure/Application/PagedList.cs index 9968bc80..4f66be67 100644 --- a/projects/Infrastructure/Application/PagedList.cs +++ b/projects/Infrastructure/Application/PagedList.cs @@ -77,6 +77,10 @@ namespace Infrastructure.Application public IEnumerable Validate(ValidationContext validationContext) { + if (PageIndex < 1) + { + yield return new ValidationResult("当前页索引必须大于等于1"); + } if (PageSize > 1000) { yield return new ValidationResult("分页数量超出系统限制"); diff --git a/projects/Infrastructure/Views/Shared/_Paged.cshtml b/projects/Infrastructure/Views/Shared/_Paged.cshtml index 23e7d03a..b2230d11 100644 --- a/projects/Infrastructure/Views/Shared/_Paged.cshtml +++ b/projects/Infrastructure/Views/Shared/_Paged.cshtml @@ -3,18 +3,14 @@ var links = Model.GetPageIndexs(); var url = Url.Content("~") + this.Context.Request.Path + this.Context.Request.QueryString; var pageIndexParam = "PageIndex"; - var firstUrl = url.RemoveParam("PageIndex"); - var prevUrl = Model.PageIndex - 1 == 1 ? firstUrl : url.SetParam(pageIndexParam, Model.PageIndex - 1); + var empty = "javascript:;"; + var firstUrl = url.RemoveParam(pageIndexParam); + var prevUrl = Model.PageIndex - 1 >= 1 ? url.SetParam(pageIndexParam, Model.PageIndex - 1) : empty; + var lastUrl = Model.TotalCount > 0 ? url.SetParam(pageIndexParam, Model.PageCount()) : empty; + var nextUrl = Model.PageIndex + 1 <= Model.PageCount() ? url.SetParam(pageIndexParam, Model.PageIndex + 1) : empty; - } \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/lib/jswebrtc/jswebrtc.min.js b/projects/IoTCenter/wwwroot/lib/jswebrtc/jswebrtc.min.js new file mode 100644 index 00000000..41d6b412 --- /dev/null +++ b/projects/IoTCenter/wwwroot/lib/jswebrtc/jswebrtc.min.js @@ -0,0 +1 @@ +var JSWebrtc={Player:null,VideoElement:null,CreateVideoElements:function(){var elements=document.querySelectorAll(".jswebrtc");for(var i=0;i=0)query_string=query_string.split("?")[1];var queries=query_string.split("&");for(var i=0;i=0){var params=app.substr(app.indexOf("?"));app=app.substr(0,app.indexOf("?"));if(params.indexOf("vhost=")>0){vhost=params.substr(params.indexOf("vhost=")+"vhost=".length);if(vhost.indexOf("&")>0){vhost=vhost.substr(0,vhost.indexOf("&"))}}}if(a.hostname==vhost){var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;if(re.test(a.hostname))vhost="__defaultVhost__"}var schema="rtmp";if(rtmp_url.indexOf("://")>0)schema=rtmp_url.substr(0,rtmp_url.indexOf("://"));var port=a.port;if(!port){if(schema==="http"){port=80}else if(schema==="https"){port=443}else if(schema==="rtmp"){port=1935}else if(schema==="webrtc"||schema==="rtc"){port=1985}}var ret={url:rtmp_url,schema:schema,server:a.hostname,port:port,vhost:vhost,app:app,stream:stream};JSWebrtc.FillQuery(a.search,ret);return ret},HttpPost:function(url,data){return new Promise(function(resolve,reject){var xhr=new XMLHttpRequest;xhr.onreadystatechange=function(){if(xhr.readyState===4&&(xhr.status>=200&&xhr.status<300)){var respone=JSON.parse(xhr.responseText);xhr.onreadystatechange=new Function;xhr=null;resolve(respone)}};xhr.open("POST",url,true);xhr.timeout=5e3;xhr.responseType="text";xhr.setRequestHeader("Content-Type","application/json");xhr.send(data)})}};if(document.readyState==="complete"){JSWebrtc.CreateVideoElements()}else{document.addEventListener("DOMContentLoaded",JSWebrtc.CreateVideoElements)}JSWebrtc.VideoElement=function(){"use strict";var VideoElement=function(element){var url=element.dataset.url;if(!url){throw"VideoElement has no `data-url` attribute"}var addStyles=function(element,styles){for(var name in styles){element.style[name]=styles[name]}};this.container=element;addStyles(this.container,{display:"inline-block",position:"relative",minWidth:"80px",minHeight:"80px"});this.video=document.createElement("video");this.video.width=960;this.video.height=540;addStyles(this.video,{display:"block",width:"100%"});this.container.appendChild(this.video);this.playButton=document.createElement("div");this.playButton.innerHTML=VideoElement.PLAY_BUTTON;addStyles(this.playButton,{zIndex:2,position:"absolute",top:"0",bottom:"0",left:"0",right:"0",maxWidth:"75px",maxHeight:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.playButton);var options={video:this.video};for(var option in element.dataset){try{options[option]=JSON.parse(element.dataset[option])}catch(err){options[option]=element.dataset[option]}}this.player=new JSWebrtc.Player(url,options);element.playerInstance=this.player;if(options.poster&&!options.autoplay){options.decodeFirstFrame=false;this.poster=new Image;this.poster.src=options.poster;this.poster.addEventListener("load",this.posterLoaded);addStyles(this.poster,{display:"block",zIndex:1,position:"absolute",top:0,left:0,bottom:0,right:0});this.container.appendChild(this.poster)}if(!this.player.options.streaming){this.container.addEventListener("click",this.onClick.bind(this))}if(options.autoplay){this.playButton.style.display="none"}if(this.player.audioOut&&!this.player.audioOut.unlocked){var unlockAudioElement=this.container;if(options.autoplay){this.unmuteButton=document.createElement("div");this.unmuteButton.innerHTML=VideoElement.UNMUTE_BUTTON;addStyles(this.unmuteButton,{zIndex:2,position:"absolute",bottom:"10px",right:"20px",width:"75px",height:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.unmuteButton);unlockAudioElement=this.unmuteButton}this.unlockAudioBound=this.onUnlockAudio.bind(this,unlockAudioElement);unlockAudioElement.addEventListener("touchstart",this.unlockAudioBound,false);unlockAudioElement.addEventListener("click",this.unlockAudioBound,true)}};VideoElement.prototype.onUnlockAudio=function(element,ev){if(this.unmuteButton){ev.preventDefault();ev.stopPropagation()}this.player.audioOut.unlock(function(){if(this.unmuteButton){this.unmuteButton.style.display="none"}element.removeEventListener("touchstart",this.unlockAudioBound);element.removeEventListener("click",this.unlockAudioBound)}.bind(this))};VideoElement.prototype.onClick=function(ev){if(this.player.isPlaying){this.player.pause();this.playButton.style.display="block"}else{this.player.play();this.playButton.style.display="none";if(this.poster){this.poster.style.display="none"}}};VideoElement.PLAY_BUTTON=''+''+''+"";VideoElement.UNMUTE_BUTTON=''+''+''+''+''+""+"";return VideoElement}();JSWebrtc.Player=function(){"use strict";var Player=function(url,options){this.options=options||{};if(!url.match(/^webrtc?:\/\//)){throw"JSWebrtc just work with webrtc"}if(!this.options.video){throw"VideoElement is null"}this.urlParams=JSWebrtc.ParseUrl(url);this.pc=null;this.autoplay=!!options.autoplay||false;this.paused=true;if(this.autoplay)this.options.video.muted=true;this.startLoading()};Player.prototype.startLoading=function(){var _self=this;if(_self.pc){_self.pc.close()}_self.pc=new RTCPeerConnection(null);_self.pc.ontrack=function(event){_self.options.video["srcObject"]=event.streams[0]};_self.pc.addTransceiver("audio",{direction:"recvonly"});_self.pc.addTransceiver("video",{direction:"recvonly"});_self.pc.createOffer().then(function(offer){return _self.pc.setLocalDescription(offer).then(function(){return offer})}).then(function(offer){return new Promise(function(resolve,reject){var port=_self.urlParams.port||1985;var api=_self.urlParams.user_query.play||"/rtc/v1/play/";if(api.lastIndexOf("/")!=api.length-1){api+="/"}var url="http://"+_self.urlParams.server+":"+port+api;for(var key in _self.urlParams.user_query){if(key!="api"&&key!="play"){url+="&"+key+"="+_self.urlParams.user_query[key]}}var data={api:url,streamurl:_self.urlParams.url,clientip:null,sdp:offer.sdp};console.log("offer: "+JSON.stringify(data));JSWebrtc.HttpPost(url,JSON.stringify(data)).then(function(res){console.log("answer: "+JSON.stringify(res));resolve(res.sdp)},function(rej){reject(rej)})})}).then(function(answer){return _self.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:answer}))}).catch(function(reason){throw reason});if(this.autoplay){this.play()}};Player.prototype.play=function(ev){if(this.animationId){return}this.animationId=requestAnimationFrame(this.update.bind(this));this.paused=false};Player.prototype.pause=function(ev){if(this.paused){return}cancelAnimationFrame(this.animationId);this.animationId=null;this.isPlaying=false;this.paused=true;this.options.video.pause();if(this.options.onPause){this.options.onPause(this)}};Player.prototype.stop=function(ev){this.pause()};Player.prototype.destroy=function(){this.pause();this.pc&&this.pc.close()&&this.pc.destroy();this.audioOut&&this.audioOut.destroy()};Player.prototype.update=function(){this.animationId=requestAnimationFrame(this.update.bind(this));if(this.options.video.readyState<4){return}if(!this.isPlaying){this.isPlaying=true;this.options.video.play();if(this.options.onPlay){this.options.onPlay(this)}}};return Player}(); \ No newline at end of file diff --git a/projects/IoTCenter/wwwroot/lib/jswebrtc/player-via-html.html b/projects/IoTCenter/wwwroot/lib/jswebrtc/player-via-html.html new file mode 100644 index 00000000..e8bb81c3 --- /dev/null +++ b/projects/IoTCenter/wwwroot/lib/jswebrtc/player-via-html.html @@ -0,0 +1,18 @@ + + + + + + WebRTCPlayer + + + +
+ + + \ No newline at end of file diff --git a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs index 20e65796..bb347ce1 100644 --- a/projects/UserCenter/Areas/Admin/Controllers/UserController.cs +++ b/projects/UserCenter/Areas/Admin/Controllers/UserController.cs @@ -28,7 +28,11 @@ namespace UserCenter.Areas.Admin.Controllers public override IQueryable Query(SearchUserModel model, IQueryable query) { - return query.WhereIf(!model.IsDeleted, o => o.IsDeleted == null); + if (model.IsDeleted) + { + return query.Where(o => o.IsDeleted != null); + } + return query.Where(o => o.IsDeleted == null); } public override IQueryable Include(IQueryable query) diff --git a/projects/lib/local/jswebrtc/dist/jswebrtc.min.js b/projects/lib/local/jswebrtc/dist/jswebrtc.min.js new file mode 100644 index 00000000..41d6b412 --- /dev/null +++ b/projects/lib/local/jswebrtc/dist/jswebrtc.min.js @@ -0,0 +1 @@ +var JSWebrtc={Player:null,VideoElement:null,CreateVideoElements:function(){var elements=document.querySelectorAll(".jswebrtc");for(var i=0;i=0)query_string=query_string.split("?")[1];var queries=query_string.split("&");for(var i=0;i=0){var params=app.substr(app.indexOf("?"));app=app.substr(0,app.indexOf("?"));if(params.indexOf("vhost=")>0){vhost=params.substr(params.indexOf("vhost=")+"vhost=".length);if(vhost.indexOf("&")>0){vhost=vhost.substr(0,vhost.indexOf("&"))}}}if(a.hostname==vhost){var re=/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;if(re.test(a.hostname))vhost="__defaultVhost__"}var schema="rtmp";if(rtmp_url.indexOf("://")>0)schema=rtmp_url.substr(0,rtmp_url.indexOf("://"));var port=a.port;if(!port){if(schema==="http"){port=80}else if(schema==="https"){port=443}else if(schema==="rtmp"){port=1935}else if(schema==="webrtc"||schema==="rtc"){port=1985}}var ret={url:rtmp_url,schema:schema,server:a.hostname,port:port,vhost:vhost,app:app,stream:stream};JSWebrtc.FillQuery(a.search,ret);return ret},HttpPost:function(url,data){return new Promise(function(resolve,reject){var xhr=new XMLHttpRequest;xhr.onreadystatechange=function(){if(xhr.readyState===4&&(xhr.status>=200&&xhr.status<300)){var respone=JSON.parse(xhr.responseText);xhr.onreadystatechange=new Function;xhr=null;resolve(respone)}};xhr.open("POST",url,true);xhr.timeout=5e3;xhr.responseType="text";xhr.setRequestHeader("Content-Type","application/json");xhr.send(data)})}};if(document.readyState==="complete"){JSWebrtc.CreateVideoElements()}else{document.addEventListener("DOMContentLoaded",JSWebrtc.CreateVideoElements)}JSWebrtc.VideoElement=function(){"use strict";var VideoElement=function(element){var url=element.dataset.url;if(!url){throw"VideoElement has no `data-url` attribute"}var addStyles=function(element,styles){for(var name in styles){element.style[name]=styles[name]}};this.container=element;addStyles(this.container,{display:"inline-block",position:"relative",minWidth:"80px",minHeight:"80px"});this.video=document.createElement("video");this.video.width=960;this.video.height=540;addStyles(this.video,{display:"block",width:"100%"});this.container.appendChild(this.video);this.playButton=document.createElement("div");this.playButton.innerHTML=VideoElement.PLAY_BUTTON;addStyles(this.playButton,{zIndex:2,position:"absolute",top:"0",bottom:"0",left:"0",right:"0",maxWidth:"75px",maxHeight:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.playButton);var options={video:this.video};for(var option in element.dataset){try{options[option]=JSON.parse(element.dataset[option])}catch(err){options[option]=element.dataset[option]}}this.player=new JSWebrtc.Player(url,options);element.playerInstance=this.player;if(options.poster&&!options.autoplay){options.decodeFirstFrame=false;this.poster=new Image;this.poster.src=options.poster;this.poster.addEventListener("load",this.posterLoaded);addStyles(this.poster,{display:"block",zIndex:1,position:"absolute",top:0,left:0,bottom:0,right:0});this.container.appendChild(this.poster)}if(!this.player.options.streaming){this.container.addEventListener("click",this.onClick.bind(this))}if(options.autoplay){this.playButton.style.display="none"}if(this.player.audioOut&&!this.player.audioOut.unlocked){var unlockAudioElement=this.container;if(options.autoplay){this.unmuteButton=document.createElement("div");this.unmuteButton.innerHTML=VideoElement.UNMUTE_BUTTON;addStyles(this.unmuteButton,{zIndex:2,position:"absolute",bottom:"10px",right:"20px",width:"75px",height:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.unmuteButton);unlockAudioElement=this.unmuteButton}this.unlockAudioBound=this.onUnlockAudio.bind(this,unlockAudioElement);unlockAudioElement.addEventListener("touchstart",this.unlockAudioBound,false);unlockAudioElement.addEventListener("click",this.unlockAudioBound,true)}};VideoElement.prototype.onUnlockAudio=function(element,ev){if(this.unmuteButton){ev.preventDefault();ev.stopPropagation()}this.player.audioOut.unlock(function(){if(this.unmuteButton){this.unmuteButton.style.display="none"}element.removeEventListener("touchstart",this.unlockAudioBound);element.removeEventListener("click",this.unlockAudioBound)}.bind(this))};VideoElement.prototype.onClick=function(ev){if(this.player.isPlaying){this.player.pause();this.playButton.style.display="block"}else{this.player.play();this.playButton.style.display="none";if(this.poster){this.poster.style.display="none"}}};VideoElement.PLAY_BUTTON=''+''+''+"";VideoElement.UNMUTE_BUTTON=''+''+''+''+''+""+"";return VideoElement}();JSWebrtc.Player=function(){"use strict";var Player=function(url,options){this.options=options||{};if(!url.match(/^webrtc?:\/\//)){throw"JSWebrtc just work with webrtc"}if(!this.options.video){throw"VideoElement is null"}this.urlParams=JSWebrtc.ParseUrl(url);this.pc=null;this.autoplay=!!options.autoplay||false;this.paused=true;if(this.autoplay)this.options.video.muted=true;this.startLoading()};Player.prototype.startLoading=function(){var _self=this;if(_self.pc){_self.pc.close()}_self.pc=new RTCPeerConnection(null);_self.pc.ontrack=function(event){_self.options.video["srcObject"]=event.streams[0]};_self.pc.addTransceiver("audio",{direction:"recvonly"});_self.pc.addTransceiver("video",{direction:"recvonly"});_self.pc.createOffer().then(function(offer){return _self.pc.setLocalDescription(offer).then(function(){return offer})}).then(function(offer){return new Promise(function(resolve,reject){var port=_self.urlParams.port||1985;var api=_self.urlParams.user_query.play||"/rtc/v1/play/";if(api.lastIndexOf("/")!=api.length-1){api+="/"}var url="http://"+_self.urlParams.server+":"+port+api;for(var key in _self.urlParams.user_query){if(key!="api"&&key!="play"){url+="&"+key+"="+_self.urlParams.user_query[key]}}var data={api:url,streamurl:_self.urlParams.url,clientip:null,sdp:offer.sdp};console.log("offer: "+JSON.stringify(data));JSWebrtc.HttpPost(url,JSON.stringify(data)).then(function(res){console.log("answer: "+JSON.stringify(res));resolve(res.sdp)},function(rej){reject(rej)})})}).then(function(answer){return _self.pc.setRemoteDescription(new RTCSessionDescription({type:"answer",sdp:answer}))}).catch(function(reason){throw reason});if(this.autoplay){this.play()}};Player.prototype.play=function(ev){if(this.animationId){return}this.animationId=requestAnimationFrame(this.update.bind(this));this.paused=false};Player.prototype.pause=function(ev){if(this.paused){return}cancelAnimationFrame(this.animationId);this.animationId=null;this.isPlaying=false;this.paused=true;this.options.video.pause();if(this.options.onPause){this.options.onPause(this)}};Player.prototype.stop=function(ev){this.pause()};Player.prototype.destroy=function(){this.pause();this.pc&&this.pc.close()&&this.pc.destroy();this.audioOut&&this.audioOut.destroy()};Player.prototype.update=function(){this.animationId=requestAnimationFrame(this.update.bind(this));if(this.options.video.readyState<4){return}if(!this.isPlaying){this.isPlaying=true;this.options.video.play();if(this.options.onPlay){this.options.onPlay(this)}}};return Player}(); \ No newline at end of file diff --git a/projects/lib/local/jswebrtc/examples/player-via-html.html b/projects/lib/local/jswebrtc/examples/player-via-html.html new file mode 100644 index 00000000..e8bb81c3 --- /dev/null +++ b/projects/lib/local/jswebrtc/examples/player-via-html.html @@ -0,0 +1,18 @@ + + + + + + WebRTCPlayer + + + +
+ + + \ No newline at end of file diff --git a/projects/lib/local/jswebrtc/examples/player-via-js.html b/projects/lib/local/jswebrtc/examples/player-via-js.html new file mode 100644 index 00000000..89758c6b --- /dev/null +++ b/projects/lib/local/jswebrtc/examples/player-via-js.html @@ -0,0 +1,17 @@ + + + + + + WebRTCPlayer + + + + + + + \ No newline at end of file From da84cd703e83af76ad5230ed93142c53c2ec8f61 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 27 May 2020 15:16:04 +0800 Subject: [PATCH 2/3] update Former-commit-id: db295113a9a81c6acf80b6d55eeee8504de0e80e --- projects/Infrastructure/Web/BaseStartup.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 80a4c74e..48171c82 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -35,7 +35,6 @@ using Microsoft.IdentityModel.Tokens; using Microsoft.OpenApi.Models; using Newtonsoft.Json; using System; -using System.Buffers; using System.Globalization; using System.IO; using System.Linq; @@ -264,7 +263,11 @@ namespace Infrastructure.Web { OnTokenValidated = context => { - if (DateTime.UtcNow > context.SecurityToken.ValidTo) + if (context.SecurityToken == null) + { + context.Fail("token error"); + } + else if (DateTime.UtcNow > context.SecurityToken.ValidTo) { context.Fail("token time out"); } From 21955aa2e0a604398c6affd63ace0a1a7b0c8553 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Wed, 27 May 2020 17:11:17 +0800 Subject: [PATCH 3/3] update Former-commit-id: 27636fc008cd469a368bd38f5c96bcfe096e111b --- .../DisplayTemplates/EmailAddress.cshtml | 1 + projects/IoTCenter/Views/Home/Device.cshtml | 2 +- .../publish/docker-compose.override.yml | 6 +++++ .../linux-x64/publish/docker-compose.prod.yml | 6 +++++ .../src/linux-x64/publish/docker-compose.yml | 27 ++++++++++++++++++- .../publish/nginx/nginx.development.conf | 4 +-- 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 projects/Infrastructure/Views/Shared/DisplayTemplates/EmailAddress.cshtml diff --git a/projects/Infrastructure/Views/Shared/DisplayTemplates/EmailAddress.cshtml b/projects/Infrastructure/Views/Shared/DisplayTemplates/EmailAddress.cshtml new file mode 100644 index 00000000..692d36d7 --- /dev/null +++ b/projects/Infrastructure/Views/Shared/DisplayTemplates/EmailAddress.cshtml @@ -0,0 +1 @@ +@Model \ No newline at end of file diff --git a/projects/IoTCenter/Views/Home/Device.cshtml b/projects/IoTCenter/Views/Home/Device.cshtml index 12e74908..00272bff 100644 --- a/projects/IoTCenter/Views/Home/Device.cshtml +++ b/projects/IoTCenter/Views/Home/Device.cshtml @@ -1,5 +1,5 @@ @section bread{ - + }