@jasolar/tracker-sdk 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -662,6 +662,14 @@ var Tracker = /*#__PURE__*/function () {
662
662
  var _this2 = this;
663
663
  var update = function update() {
664
664
  var wasInactive = _this2._checkInactive();
665
+
666
+ // 如果确实已经处于非活跃状态太久,但定时器还没来得及触发 (例如电脑休眠唤醒)
667
+ // 此时应主动触发 leave(),并重置会话
668
+ if (wasInactive && !_this2.isTimedOut && _this2.current) {
669
+ console.log('[Tracker SDK] Activity detected after long inactivity, forcing timeout leave');
670
+ _this2.leave(false, true, 'timeout');
671
+ _this2.sessionId = resetSession();
672
+ }
665
673
  _this2.lastActiveTime = now();
666
674
  refreshSession(); // 用户活跃时刷新 Session 有效期
667
675
 
@@ -734,6 +742,8 @@ var Tracker = /*#__PURE__*/function () {
734
742
  key: "_startTimeoutCheck",
735
743
  value: function _startTimeoutCheck() {
736
744
  var _this3 = this;
745
+ this._stopTimeoutCheck(); // 确保不重复启动定时器
746
+
737
747
  // 动态计算检测间隔:超时时间的 1/6,但不超过 30 秒,不少于 5 秒
738
748
  var checkInterval = Math.min(Math.max(this.options.sessionTimeout / 6, 5 * 1000), 30 * 1000);
739
749
  console.log('[Tracker SDK] Timeout check interval:', (checkInterval / 1000).toFixed(1), 's');
@@ -741,7 +751,7 @@ var Tracker = /*#__PURE__*/function () {
741
751
  // 只要有 current 且未处于超时状态,就检测是否超时
742
752
  if (_this3.current && !_this3.isTimedOut && _this3._checkInactive()) {
743
753
  console.log('[Tracker SDK] User inactive for too long, triggering auto leave');
744
- _this3.leave(true, true); // 强制上报离开事件,标记为超时
754
+ _this3.leave(false, true, 'timeout'); // 使用 lastActiveTime 结算,标记为超时
745
755
 
746
756
  // 重置 Session,认为会话结束
747
757
  _this3.sessionId = resetSession();
package/dist/index.esm.js CHANGED
@@ -660,6 +660,14 @@ var Tracker = /*#__PURE__*/function () {
660
660
  var _this2 = this;
661
661
  var update = function update() {
662
662
  var wasInactive = _this2._checkInactive();
663
+
664
+ // 如果确实已经处于非活跃状态太久,但定时器还没来得及触发 (例如电脑休眠唤醒)
665
+ // 此时应主动触发 leave(),并重置会话
666
+ if (wasInactive && !_this2.isTimedOut && _this2.current) {
667
+ console.log('[Tracker SDK] Activity detected after long inactivity, forcing timeout leave');
668
+ _this2.leave(false, true, 'timeout');
669
+ _this2.sessionId = resetSession();
670
+ }
663
671
  _this2.lastActiveTime = now();
664
672
  refreshSession(); // 用户活跃时刷新 Session 有效期
665
673
 
@@ -732,6 +740,8 @@ var Tracker = /*#__PURE__*/function () {
732
740
  key: "_startTimeoutCheck",
733
741
  value: function _startTimeoutCheck() {
734
742
  var _this3 = this;
743
+ this._stopTimeoutCheck(); // 确保不重复启动定时器
744
+
735
745
  // 动态计算检测间隔:超时时间的 1/6,但不超过 30 秒,不少于 5 秒
736
746
  var checkInterval = Math.min(Math.max(this.options.sessionTimeout / 6, 5 * 1000), 30 * 1000);
737
747
  console.log('[Tracker SDK] Timeout check interval:', (checkInterval / 1000).toFixed(1), 's');
@@ -739,7 +749,7 @@ var Tracker = /*#__PURE__*/function () {
739
749
  // 只要有 current 且未处于超时状态,就检测是否超时
740
750
  if (_this3.current && !_this3.isTimedOut && _this3._checkInactive()) {
741
751
  console.log('[Tracker SDK] User inactive for too long, triggering auto leave');
742
- _this3.leave(true, true); // 强制上报离开事件,标记为超时
752
+ _this3.leave(false, true, 'timeout'); // 使用 lastActiveTime 结算,标记为超时
743
753
 
744
754
  // 重置 Session,认为会话结束
745
755
  _this3.sessionId = resetSession();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jasolar/tracker-sdk",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "type": "module",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",