Skip to content

Commit b7b6cd2

Browse files
committed
Add in some additional integration code to help with demos not working properly.
1 parent 6537dea commit b7b6cd2

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

examples/pxScene2d/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ if (APPLE)
103103
set(PXSCENE_LINK_LIBRARIES)
104104
set(PXSCENE_LINK_DIRECTORIES ${PXSCENE_LINK_DIRECTORIES} ${NODE_LIBRARY_DIRS} ${V8_LIBRARY_DIRS} ${DUKE_LIBRARY_DIRS} ${COMM_DEPS_LIBRARY_DIRS})
105105
set(PLATFORM_LIBRARIES pxCore rtCore_s pthread ${NODE_LIBRARIES} ${V8_LIBRARIES} ${DUKE_LIBRARIES} ${COMM_DEPS_LIBRARIES})
106+
if (SUPPORT_V8)
107+
set(PXSCENE_LINK_DIRECTORIES ${PXSCENE_LINK_DIRECTORIES} ${UWS})
108+
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} uWS)
109+
endif ()
106110
include_directories(AFTER ${NODE_INCLUDE_DIRS} ${DUKE_INCLUDE_DIRS} ${COMM_DEPS_INCLUDE_DIRS})
107111
if (DEFINED ENV{CODE_COVERAGE})
108112
message("enabling code coverage support")

examples/pxScene2d/src/node_modules/htmlparser/index.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pxScene2d/src/v8_modules/native_http_wrap.js

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,29 @@ NativeHttpManager.request = function(...args) {
5353
*/
5454
function NativeHttp(url, cb) {
5555
this._httpInstance = httpGet(url, res => {
56-
cb(res);
56+
if (this.timeoutHandler) {
57+
clearTimeout(this.timeoutHandler);
58+
}
59+
if (!this.isTimeout) {
60+
cb(res);
61+
} else {
62+
console.log('request timeout and reponse reached, ignore this response.');
63+
}
5764
NativeHttpManager.remove(this);
5865
});
5966
NativeHttpManager.add(this);
67+
this.timeoutHandler = null;
68+
this.errorHander = null;
69+
this.isTimeout = false;
6070
}
6171

62-
NativeHttp.prototype.on = function(...args) {
63-
this._httpInstance.on(...args);
72+
NativeHttp.prototype.on = function(eventName, handler) {
73+
this._httpInstance.on(eventName, handler);
74+
75+
if(eventName === 'error') {
76+
this.errorHander = handler;
77+
}
78+
6479
return this;
6580
};
6681

@@ -74,8 +89,16 @@ NativeHttp.prototype.end = function() {
7489
NativeHttp.prototype.write = function(...args) {
7590
this._httpInstance.write(...args);
7691
}
77-
NativeHttp.prototype.setTimeout = function(...args) {
78-
this._httpInstance.setTimeout.apply(...args);
92+
NativeHttp.prototype.setTimeout = function(ms, timeoutCB) {
93+
// c++ native didn't implement the setTimeout
94+
// so i implement this in js side
95+
this.timeoutHandler = setTimeout(()=>{
96+
this.isTimeout = true;
97+
timeoutCB();
98+
if (this.errorHander) {
99+
this.errorHander({message:'request timeout'});
100+
}
101+
}, ms);
79102
}
80103
NativeHttp.prototype.setHeader = function(...args) {
81104
this._httpInstance.setHeader(...args);

examples/pxScene2d/src/v8_modules/path.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ win32 = {
275275
}
276276
}
277277
},
278+
extname: function extname(path) {
279+
return path.split('.').pop();
280+
},
278281
}
279282

280283
posix = {
@@ -299,6 +302,9 @@ posix = {
299302
return '/' + path;
300303
return path;
301304
},
305+
extname: function extname(path) {
306+
return path.split('.').pop();
307+
},
302308
}
303309

304310
if (uv_platform() === 'win32')

0 commit comments

Comments
 (0)