Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

40
LINES

< > BotCompany Repo | #1031659 // hjs_sendWindowVisibilityToWebSocket

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (2922L) is out of date.

sS hjs_sendWindowVisibilityToWebSocket() {
  ret hjs([[
    // version 1
    
    var isTabActive;
    
    function wsSendTabActive() {
      wsOnOpen(function() {
        console.log("isTabActive=" + isTabActive);
        console.log("Sending");
        ws.send(JSON.stringify({"isTabActive": isTabActive}));
      });
    }
    
    wsSendTabActive();
  
    window.onfocus = function () { 
      isTabActive = true; 
      wsSendTabActive();
    }; 
  
    window.onblur = function () { 
      isTabActive = false; 
      wsSendTabActive();
    };
    
    // version 2
    
    function wsSendVisibility() {
      wsOnOpen(function() {
        var vis = document.visibilityState;
        console.log("visibility=" + vis);
        ws.send(JSON.stringify({"visibility": vis}));
      });
    }
    
    wsSendVisibility();
    document.addEventListener("visibilityChange", wsSendVisibility);
  ]]);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031659
Snippet name: hjs_sendWindowVisibilityToWebSocket
Eternal ID of this version: #1031659/9
Text MD5: ce31cdd7684c4987e5cf2d16e95003d2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-27 08:12:22
Source code size: 942 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 200 / 282
Version history: 8 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1031706 - JSSendMouseEventsToWebSocket (only motion right now)