@@ -21,7 +21,7 @@ let useLocalNetworkRoomShare = (window.localStorage.getItem("tl-rtc-file-use-loc
2121// 是否开启消息红点
2222let useMessageDot = ( window . localStorage . getItem ( "tl-rtc-file-use-message-dot" ) || "true" ) === 'true' ;
2323// 是否开启浏览器系统消息通知
24- let useWebMsgNotify = ( window . localStorage . getItem ( "tl-rtc-file-use-web-msg-notify" ) || "true " ) === 'true' ;
24+ let useWebMsgNotify = ( window . localStorage . getItem ( "tl-rtc-file-use-web-msg-notify" ) || "" ) === 'true' ;
2525
2626axios . get ( "/api/comm/initData?turn=" + useTurn , { } ) . then ( async ( initData ) => {
2727 let { data : {
@@ -1136,6 +1136,36 @@ axios.get("/api/comm/initData?turn="+useTurn, {}).then(async (initData) => {
11361136 return
11371137 }
11381138
1139+ //如果开启了系统弹窗 && 当前页面没有焦点
1140+ if ( this . webMsgNotify && ! document . hasFocus ( ) ) {
1141+ //修改标签页title
1142+ let title = document . title ;
1143+ let msg = data . title + " " + data . message ;
1144+ let time = 0 ;
1145+ let timer = null ;
1146+ timer = setInterval ( ( ) => {
1147+ time ++ ;
1148+ if ( time % 2 === 0 ) {
1149+ document . title = msg ;
1150+ } else {
1151+ document . title = title ;
1152+ }
1153+ if ( time > 10 ) {
1154+ clearInterval ( timer ) ;
1155+ document . title = title ;
1156+ }
1157+ } , 500 ) ;
1158+
1159+ //浏览器系统桌面消息通知
1160+ if ( window . Notification && Notification . permission === 'granted' ) {
1161+ new Notification ( "tl-rtc-file通知" + data . title , {
1162+ body : data . message ,
1163+ dir : 'auto' ,
1164+ icon : '../image/44826979.png'
1165+ } )
1166+ }
1167+ }
1168+
11391169 let levelTime = 1800 ;
11401170 for ( let len in lengthLevel ) {
11411171 if ( len > this . popUpList . length ) {
@@ -4669,6 +4699,17 @@ axios.get("/api/comm/initData?turn="+useTurn, {}).then(async (initData) => {
46694699 this . useWebMsgNotify = ! this . useWebMsgNotify ;
46704700
46714701 if ( this . useWebMsgNotify ) {
4702+ // 开启通知开关的时候,如果没有通知权限,请求浏览器通知权限
4703+ if ( window . Notification ) {
4704+ if ( Notification . permission !== "granted" ) {
4705+ Notification . requestPermission ( function ( status ) {
4706+ if ( Notification . permission !== status ) {
4707+ Notification . permission = status ;
4708+ }
4709+ } ) ;
4710+ }
4711+ }
4712+
46724713 window . localStorage . setItem ( "tl-rtc-file-use-web-message-notify" , true )
46734714 $ ( "#webMsgNotifyOpen" ) . css ( "display" , "inline" ) ;
46744715 $ ( "#webMsgNotifyClose" ) . css ( "display" , "none" ) ;
0 commit comments