@plasosdk/plaso-electron-sdk 1.0.6 → 1.0.26

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/index.html ADDED
@@ -0,0 +1,229 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+
8
+ <style>
9
+ * {
10
+ font-family: "Microsoft YaHei", sans-serif;
11
+ }
12
+
13
+ body {
14
+ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
15
+ }
16
+
17
+ #btn_reload {
18
+ width: 120px;
19
+ height: 40px;
20
+ background: #02c8f2;
21
+ border-radius: 4px;
22
+ border: none;
23
+ margin: 10px auto;
24
+ font-size: 20px;
25
+ display: block;
26
+ color: #fff;
27
+ cursor: pointer;
28
+ }
29
+
30
+ .contain {
31
+ position: absolute;
32
+ width: 80px;
33
+ height: 80px;
34
+ left: 50%;
35
+ top: 50%;
36
+ transform: translate(-50%, -50%);
37
+ font-size: 20px;
38
+ }
39
+
40
+ .animate {
41
+ position: absolute;
42
+ width: 100%;
43
+ height: 100%;
44
+ left: 0;
45
+ top: -25%;
46
+ border-radius: 10%;
47
+ z-index: 1;
48
+ transform: translateZ(0);
49
+ background: #8EEFC7;
50
+ animation: animate .6s -.1s linear infinite;
51
+ }
52
+
53
+ .shadow {
54
+ position: absolute;
55
+ left: 0;
56
+ width: 100%;
57
+ bottom: -9%;
58
+ height: 10%;
59
+ background: #DFE6EC;
60
+ border-radius: 50%;
61
+ -webkit-animation: shadow .6s -.1s linear infinite;
62
+ -moz-animation: shadow .6s -.1s linear infinite;
63
+ -o-animation: shadow .6s -.1s linear infinite;
64
+ animation: shadow .6s -.1s linear infinite;
65
+ }
66
+
67
+ @keyframes animate {
68
+ 17% {
69
+ border-bottom-right-radius: 10%;
70
+ }
71
+
72
+ 25% {
73
+ transform: translateY(25%) rotate(22.5deg);
74
+ }
75
+
76
+ 50% {
77
+ border-bottom-right-radius: 100%;
78
+ transform: translateY(50%) scale(1, .9) rotate(45deg);
79
+ }
80
+
81
+ 75% {
82
+ transform: translateY(25%) rotate(67.5deg);
83
+ }
84
+
85
+ 100% {
86
+ transform: translateY(0) rotate(90deg);
87
+ }
88
+ }
89
+
90
+ @keyframes shadow {
91
+ 50% {
92
+ transform: scale(1.25, 1);
93
+ }
94
+ }
95
+ </style>
96
+
97
+ <title></title>
98
+ </head>
99
+
100
+ <body>
101
+ <div id="react_body">
102
+ <div class="contain" id="loading" style="display:none">
103
+ <div class="animate"></div>
104
+ <div class="shadow"></div>
105
+ </div>
106
+ </div>
107
+ </body>
108
+
109
+ <script type="text/javascript">
110
+ //配置文件,主要是 thrift 接口地址和一些标识字符串
111
+ var globalAppInfo = {};
112
+
113
+ function getElectronRemote() {
114
+ let _remote;
115
+ try {
116
+ _remote = window.require('electron').remote;
117
+ if (!_remote) {
118
+ _remote = window.require('@electron/remote');
119
+ }
120
+ } catch (e) {
121
+ console.error(e);
122
+ throw new Error('illegal call, non electron environment');
123
+ }
124
+ return _remote;
125
+ }
126
+
127
+ const include = function (url) {
128
+ url = globalAppInfo.rhost + url;
129
+ let ele;
130
+ if (/\.css$/.test(url)) {
131
+ ele = document.createElement('link');
132
+ ele.rel = "stylesheet";
133
+ ele.type = "text/css";
134
+ ele.href = url;
135
+ } else {
136
+ ele = document.createElement('script');
137
+ ele.src = url;
138
+ }
139
+
140
+ document.head.appendChild(ele);
141
+ }
142
+
143
+
144
+ function init(classObj) {
145
+ let query;
146
+ if (classObj) {
147
+ globalAppInfo = Object.assign({}, classObj)
148
+ }
149
+ globalAppInfo.needFullScreen = false;
150
+
151
+ if (globalAppInfo.rhost && globalAppInfo.rhost.substring(globalAppInfo.rhost.length - 1) != '/') {
152
+ globalAppInfo.rhost += "/";
153
+ }
154
+ if (globalAppInfo.dhost && globalAppInfo.dhost.substring(globalAppInfo.dhost.length - 1) != '/') {
155
+ globalAppInfo.dhost += "/";
156
+ }
157
+
158
+ path = globalAppInfo.initjs || "js/all.js";
159
+ include(path);
160
+ }
161
+
162
+ if (typeof require == "function") {
163
+ const { ipcRenderer } = window.require('electron');
164
+ const { CLASS_WINDOW_MESG_TYPE } = require('./js/code');
165
+
166
+ const queryString = location.href.split('?')[1];
167
+ queryString.split('&').forEach((pair) => {
168
+ const [key, value] = pair.split('=');
169
+ if (key === 'openerId') openerId = Number(value);
170
+ });
171
+
172
+ ipcRenderer.on(CLASS_WINDOW_MESG_TYPE.INIT_CLASS_OPTIONS, (_, classObj) => {
173
+ if (classObj) init(classObj);
174
+ });
175
+
176
+ if(openerId){
177
+ const remote = getElectronRemote();
178
+ const webContents = remote.getCurrentWebContents();
179
+ ipcRenderer.sendTo(openerId, CLASS_WINDOW_MESG_TYPE.CLASS_READY, {webContentId: webContents.id});
180
+ }
181
+
182
+ }
183
+
184
+ /*
185
+ * 加载超时函数,立即执行
186
+ * param: timeLength :超时时间
187
+ */
188
+ (function timeOut(timeLength) {
189
+ const timer = setTimeout(
190
+ function () {
191
+ var loading = document.getElementById('loading');
192
+ if (loading) {
193
+ loading.style.width = "100%";
194
+ loading.style.textAlign = "center";
195
+ eval("loading.innerHTML = '加载超时!请点击重新加载<button id=\"btn_reload\" onclick=\"reload()\">重新加载</button>'");
196
+ if (typeof require == "function" && globalAppInfo.clientType === 'nw') {
197
+ var gui = require('nw.gui');
198
+ var win = gui.Window.get();
199
+ win.removeAllListeners();
200
+ }
201
+ }
202
+ },
203
+ timeLength * 1000
204
+ )
205
+ })(30);
206
+
207
+ function reload() {
208
+ if (typeof require == "function" && globalAppInfo.clientType === 'electron') {
209
+ var remote = getElectronRemote();
210
+ var curWindow = remote.getCurrentWindow();
211
+ curWindow.webContents.reloadIgnoringCache()
212
+ } else {
213
+ location.reload();
214
+ }
215
+ }
216
+ </script>
217
+
218
+ <script type="text/javascript">
219
+ if (globalAppInfo.background) {
220
+ document.body.style.background = globalAppInfo.background;
221
+ document.documentElement.style.background = globalAppInfo.background;
222
+ }
223
+ if (!globalAppInfo.noLoading) {
224
+ var loadingDom = document.getElementById("loading");
225
+ if (loadingDom) loadingDom.style.display = "";
226
+ }
227
+ </script>
228
+
229
+ </html>
package/js/code.js CHANGED
@@ -1,6 +1,10 @@
1
1
  const ERROR_CODE = {
2
2
  /** 非 electron 环境 */
3
3
  NO_ELECTRON_ENVIRONMENT: -1,
4
+ /** 获取remote 失败 */
5
+ GET_REMOTE_FAIL: -2,
6
+ /** 获取 屏幕信息 失败 */
7
+ GET_DISPLAY_INFO_FAIL: -3,
4
8
  COMMOM_ERROR: -99,
5
9
  };
6
10
 
@@ -17,6 +21,9 @@ const CLASS_WINDOW_MESG_TYPE = {
17
21
  LIVE_WINDOW_READY: 'liveWindowReady',
18
22
  /** 离开课堂 */
19
23
  ON_CLASS_FINISHED: 'onClassFinished',
24
+ /** 初始化进课堂参数 */
25
+ INIT_CLASS_OPTIONS: 'init_class_options',
26
+ CLASS_READY: 'class_ready',
20
27
  };
21
28
 
22
29
  const LEVEL = {
@@ -26,9 +33,16 @@ const LEVEL = {
26
33
  debug: 0,
27
34
  };
28
35
 
36
+ /** 渲染进程到主进程通讯的消息 */
37
+ const RENDER_TO_MAIN_MESG_TYPE = {
38
+ /** 初始化dump生成位置 */
39
+ PLASO_INIT_LOG_PATH: 'plaso-init-log-path',
40
+ };
41
+
29
42
  module.exports = {
30
43
  LESSON_TYPE,
31
44
  ERROR_CODE,
32
45
  CLASS_WINDOW_MESG_TYPE,
33
- LEVEL
46
+ LEVEL,
47
+ RENDER_TO_MAIN_MESG_TYPE
34
48
  };
package/js/common.js CHANGED
@@ -17,20 +17,19 @@ function getElectronRemote() {
17
17
  let _remote;
18
18
  try {
19
19
  _remote = window.require('electron').remote;
20
- } catch (e) {
21
- try {
20
+ if (!_remote) {
22
21
  _remote = window.require('@electron/remote');
23
- } catch (err) {
24
- console.error(err);
25
- throw new Error('illegal call, non electron environment');
26
22
  }
23
+ } catch (e) {
24
+ console.error(e);
25
+ throw new Error('illegal call, non electron environment');
27
26
  }
28
27
  return _remote;
29
28
  }
30
29
 
31
30
  function parseUrlParams(url) {
32
31
  const params = {};
33
- const queryString = url.split('?')[1];
32
+ const queryString = url.indexOf('?') > -1 ? url.split('?')[1] : url;
34
33
 
35
34
  if (!queryString) return params;
36
35
 
@@ -39,6 +38,8 @@ function parseUrlParams(url) {
39
38
  let decodedValue = decodeURIComponent(value || '');
40
39
  if (decodedValue === 'true' || decodedValue === 'false') {
41
40
  decodedValue = decodedValue === 'true';
41
+ } else if ( typeof decodedValue === 'string' && !isNaN(Number(decodedValue)) && Number(decodedValue) !== undefined && !decodedValue?.includes?.('.')) {
42
+ decodedValue = Number(decodedValue);
42
43
  }
43
44
  params[key] = decodedValue;
44
45
  });
@@ -47,7 +48,7 @@ function parseUrlParams(url) {
47
48
  }
48
49
 
49
50
  function getEnvironment(url) {
50
- const host = url ?? location.host
51
+ let host = (url ?? location.host)
51
52
  .replace('wwwr', 'www')
52
53
  .replace('devai', 'dev')
53
54
  .replace('testai', 'test')
@@ -56,15 +57,19 @@ function getEnvironment(url) {
56
57
  .replace('ai-cdn', 'www')
57
58
  .replace('ai.', 'www.')
58
59
  .toLocaleUpperCase();
60
+ const httpIndex = host.indexOf('://');
61
+ if(httpIndex > -1){
62
+ host = host.substring(httpIndex + 3);
63
+ }
59
64
  const index = host.indexOf('.');
60
65
  let environment = '';
61
66
  //先根据url判断环境。这里single页面访问会用到
62
- if (/^192\.|localhost/.test(host)) {
67
+ if (/^192\.|^127\.|localhost/.test(host)) {
63
68
  environment = 'local';
64
69
  } else {
65
70
  environment = host.substring(0, index);
66
71
  }
67
- return environment;
72
+ return environment?.toLowerCase();
68
73
  }
69
74
 
70
75
  /**
package/js/main.js CHANGED
@@ -5,18 +5,18 @@ if (isElectron) {
5
5
  require('@plasosdk/screenshot');
6
6
  require('@plasosdk/rtmpplayer');
7
7
 
8
- const { versionComp } = require('./common.js');
9
- const electronVersion = process.versions['electron'];
10
- const { app } = require('electron');
8
+ const { RENDER_TO_MAIN_MESG_TYPE } = require('./code');
9
+
10
+ const { app, ipcMain, crashReporter } = require('electron');
11
11
 
12
- if (electronVersion && versionComp(electronVersion, '14.0.0') >= 0) {
13
- const electronStore = require('@electron/remote/main');
14
- const isInitialized = electronStore.isInitialized();
15
- if (!isInitialized) electronStore.initialize();
16
- }
17
12
  // 首次添加此开关是为了解决一些GPU导致的渲染问题的,比如进课堂白屏,历史课堂播放进度条不动。
18
13
  // 支持虚拟声卡需要添加此开关
19
14
  app.commandLine.appendSwitch('--no-sandbox');
15
+
16
+ ipcMain.on(RENDER_TO_MAIN_MESG_TYPE.PLASO_INIT_LOG_PATH, function(e, logFilePath) {
17
+ app.setPath('crashDumps', logFilePath);
18
+ crashReporter.start({ submitURL: '', uploadToServer: false });
19
+ });
20
20
  } catch (e) {
21
21
  console.error(e);
22
22
  }