This commit is contained in:
2020-07-09 08:50:24 +08:00
parent 13d25f4707
commit c523462b82
1818 changed files with 174940 additions and 582 deletions

View File

@@ -0,0 +1,125 @@
var Lib_BEST_HTTP_WebGL_ES_Bridge =
{
$es: {
eventSourceInstances: {},
nextInstanceId : 1,
Set : function(event) {
es.eventSourceInstances[es.nextInstanceId] = event;
return es.nextInstanceId++;
},
Get : function(id) {
return es.eventSourceInstances[id];
},
Remove: function(id) {
delete es.eventSourceInstances[id];
},
_callOnError: function(errCallback, id, reason)
{
if (reason)
{
var length = lengthBytesUTF8(reason) + 1;
var buffer = _malloc(length);
stringToUTF8Array(reason, HEAPU8, buffer, length);
Runtime.dynCall('vii', errCallback, [id, buffer]);
_free(buffer);
}
else
Runtime.dynCall('vii', errCallback, [id, 0]);
}
},
ES_Create: function(urlPtr, withCredentials, onOpen, onMessage, onError)
{
var url = encodeURI(Pointer_stringify(urlPtr))
.replace(/\+/g, '%2B')
.replace(/%252[fF]/ig, '%2F');
var event = {
onError: onError
};
var id = es.nextInstanceId;
console.log(id + ' ES_Create(' + url + ', ' + withCredentials + ')');
event.eventImpl = new EventSource(url, { withCredentials: withCredentials != 0 ? true : false } );
event.eventImpl.onopen = function() {
console.log(id + ' ES_Create - onOpen');
Runtime.dynCall('vi', onOpen, [id]);
};
event.eventImpl.onmessage = function(e) {
function AllocString(str) {
if (str != undefined)
{
var length = lengthBytesUTF8(str) + 1;
var buff = _malloc(length);
stringToUTF8Array(str, HEAPU8, buff, length);
return buff;
}
return 0;
}
var eventBuffer = AllocString(e.event);
var dataBuffer = AllocString(e.data);
var idBuffer = AllocString(e.id);
Runtime.dynCall('viiiii', onMessage, [id, eventBuffer, dataBuffer, idBuffer, e.retry]);
if (eventBuffer != 0)
_free(eventBuffer);
if (dataBuffer != 0)
_free(dataBuffer);
if (idBuffer != 0)
_free(idBuffer);
};
event.eventImpl.onerror = function(e) {
console.log(id + ' ES_Create - onError');
es._callOnError(onError, id, "Unknown Error!");
};
return es.Set(event);
},
ES_Close: function(id)
{
console.log(id + ' ES_Close');
var event = es.Get(id);
try
{
event.close();
}
catch(e) {
es._callOnError(event.onError, id, ' ' + e.name + ': ' + e.message);
}
},
ES_Release: function(id)
{
console.log(id + ' ES_Release');
es.Remove(id);
}
};
autoAddDeps(Lib_BEST_HTTP_WebGL_ES_Bridge, '$es');
mergeInto(LibraryManager.library, Lib_BEST_HTTP_WebGL_ES_Bridge);

View File

@@ -0,0 +1,37 @@
fileFormatVersion: 2
guid: ac23b06f7735b8e478ce14b0d4ac2a68
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Facebook: WebGL
second:
enabled: 1
settings: {}
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,241 @@
var Lib_BEST_HTTP_WebGL_HTTP_Bridge =
{
/*LogLevels: {
All: 0,
Information: 1,
Warning: 2,
Error: 3,
Exception: 4,
None: 5
}*/
$wr: {
requestInstances: {},
nextRequestId: 1,
loglevel: 2
},
XHR_Create: function(method, url, user, passwd)
{
var _url = encodeURI(Pointer_stringify(url))
.replace(/\+/g, '%2B')
.replace(/%252[fF]/ig, '%2F');
var _method = Pointer_stringify(method);
if (wr.loglevel <= 1) /*information*/
console.log(wr.nextRequestId + ' XHR_Create ' + _method + ' ' + _url);
var http = new XMLHttpRequest();
if (user && passwd)
{
var u = Pointer_stringify(user);
var p = Pointer_stringify(passwd);
http.withCredentials = true;
http.open(_method, _url, /*async:*/ true , u, p);
}
else
http.open(_method, _url, /*async:*/ true);
http.responseType = 'arraybuffer';
wr.requestInstances[wr.nextRequestId] = http;
return wr.nextRequestId++;
},
XHR_SetTimeout: function (request, timeout)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetTimeout ' + timeout);
wr.requestInstances[request].timeout = timeout;
},
XHR_SetRequestHeader: function (request, header, value)
{
var _header = Pointer_stringify(header);
var _value = Pointer_stringify(value);
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetRequestHeader ' + _header + ' ' + _value);
wr.requestInstances[request].setRequestHeader(_header, _value);
},
XHR_SetResponseHandler: function (request, onresponse, onerror, ontimeout, onaborted)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetResponseHandler');
var http = wr.requestInstances[request];
// LOAD
http.onload = function http_onload(e) {
if (wr.loglevel <= 1) /*information*/
console.log(request + ' - onload ' + http.status + ' ' + http.statusText);
if (onresponse)
{
var response = 0;
if (!!http.response)
response = http.response;
var byteArray = new Uint8Array(response);
var buffer = _malloc(byteArray.length);
HEAPU8.set(byteArray, buffer);
Runtime.dynCall('viiiii', onresponse, [request, http.status, buffer, byteArray.length, 0]);
_free(buffer);
}
};
if (onerror)
{
http.onerror = function http_onerror(e) {
function HandleError(err)
{
var length = lengthBytesUTF8(err) + 1;
var buffer = _malloc(length);
stringToUTF8Array(err, HEAPU8, buffer, length);
Runtime.dynCall('vii', onerror, [request, buffer]);
_free(buffer);
}
if (e.error)
HandleError(e.error);
else
HandleError("Unknown Error! Maybe a CORS porblem?");
};
}
if (ontimeout)
http.ontimeout = function http_onerror(e) {
Runtime.dynCall('vi', ontimeout, [request]);
};
if (onaborted)
http.onabort = function http_onerror(e) {
Runtime.dynCall('vi', onaborted, [request]);
};
},
XHR_SetProgressHandler: function (request, onprogress, onuploadprogress)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetProgressHandler');
var http = wr.requestInstances[request];
if (http)
{
if (onprogress)
http.onprogress = function http_onprogress(e) {
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetProgressHandler - onProgress ' + e.loaded + ' ' + e.total);
if (e.lengthComputable)
Runtime.dynCall('viii', onprogress, [request, e.loaded, e.total]);
};
if (onuploadprogress)
http.upload.addEventListener("progress", function http_onprogress(e) {
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_SetProgressHandler - onUploadProgress ' + e.loaded + ' ' + e.total);
if (e.lengthComputable)
Runtime.dynCall('viii', onuploadprogress, [request, e.loaded, e.total]);
}, true);
}
},
XHR_Send: function (request, ptr, length)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_Send ' + ptr + ' ' + length);
var http = wr.requestInstances[request];
try {
if (length > 0)
http.send(HEAPU8.subarray(ptr, ptr+length));
else
http.send();
}
catch(e) {
if (wr.loglevel <= 4) /*exception*/
console.error(request + ' ' + e.name + ": " + e.message);
}
},
XHR_GetResponseHeaders: function(request, callback)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_GetResponseHeaders');
var headers = wr.requestInstances[request].getAllResponseHeaders().trim() + "\r\n";
if (wr.loglevel <= 1) /*information*/
console.log(' "' + headers + '"');
var byteArray = new Uint8Array(headers.length);
for(var i=0,j=headers.length;i<j;++i){
byteArray[i]=headers.charCodeAt(i);
}
var buffer = _malloc(byteArray.length);
HEAPU8.set(byteArray, buffer);
Runtime.dynCall('viii', callback, [request, buffer, byteArray.length]);
_free(buffer);
},
XHR_GetStatusLine: function(request, callback)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_GetStatusLine');
var status = "HTTP/1.1 " + wr.requestInstances[request].status + " " + wr.requestInstances[request].statusText;
if (wr.loglevel <= 1) /*information*/
console.log(status);
var byteArray = new Uint8Array(status.length);
for(var i=0,j=status.length;i<j;++i){
byteArray[i]=status.charCodeAt(i);
}
var buffer = _malloc(byteArray.length);
HEAPU8.set(byteArray, buffer);
Runtime.dynCall('viii', callback, [request, buffer, byteArray.length]);
_free(buffer);
},
XHR_Abort: function (request)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_Abort');
wr.requestInstances[request].abort();
},
XHR_Release: function (request)
{
if (wr.loglevel <= 1) /*information*/
console.log(request + ' XHR_Release');
delete wr.requestInstances[request];
},
XHR_SetLoglevel: function (level)
{
wr.loglevel = level;
}
};
autoAddDeps(Lib_BEST_HTTP_WebGL_HTTP_Bridge, '$wr');
mergeInto(LibraryManager.library, Lib_BEST_HTTP_WebGL_HTTP_Bridge);

View File

@@ -0,0 +1,37 @@
fileFormatVersion: 2
guid: 3a8cd111a04391742a3eaa9a96f9a0ac
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Facebook: WebGL
second:
enabled: 1
settings: {}
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,205 @@
var Lib_BEST_HTTP_WebGL_WS_Bridge =
{
$ws: {
webSocketInstances: {},
nextInstanceId : 1,
Set : function(socket) {
ws.webSocketInstances[ws.nextInstanceId] = socket;
return ws.nextInstanceId++;
},
Get : function(id) {
return ws.webSocketInstances[id];
},
Remove: function(id) {
delete ws.webSocketInstances[id];
},
_callOnClose: function(onClose, id, code, reason)
{
var length = lengthBytesUTF8(reason) + 1;
var buffer = _malloc(length);
stringToUTF8Array(reason, HEAPU8, buffer, length);
Runtime.dynCall('viii', onClose, [id, code, buffer]);
_free(buffer);
},
_callOnError: function(errCallback, id, reason)
{
var length = lengthBytesUTF8(reason) + 1;
var buffer = _malloc(length);
stringToUTF8Array(reason, HEAPU8, buffer, length);
Runtime.dynCall('vii', errCallback, [id, buffer]);
_free(buffer);
}
},
WS_Create: function(url, protocol, onOpen, onText, onBinary, onError, onClose)
{
var urlStr = encodeURI(Pointer_stringify(url))
.replace(/\+/g, '%2B')
.replace(/%252[fF]/ig, '%2F');
var proto = Pointer_stringify(protocol);
console.log('WS_Create(' + urlStr + ', "' + proto + '")');
var socket = {
onError: onError,
onClose: onClose
};
if (proto == '')
socket.socketImpl = new WebSocket(urlStr);
else
socket.socketImpl = new WebSocket(urlStr, [proto]);
var id = ws.nextInstanceId;
socket.socketImpl.binaryType = "arraybuffer";
socket.socketImpl.onopen = function(e) {
console.log(id + ' WS_Create - onOpen');
Runtime.dynCall('vi', onOpen, [id]);
};
socket.socketImpl.onmessage = function (e)
{
// Binary?
if (e.data instanceof ArrayBuffer)
{
var byteArray = new Uint8Array(e.data);
var buffer = _malloc(byteArray.length);
HEAPU8.set(byteArray, buffer);
Runtime.dynCall('viii', onBinary, [id, buffer, byteArray.length]);
_free(buffer);
}
else // Text
{
var length = lengthBytesUTF8(e.data) + 1;
var buffer = _malloc(length);
stringToUTF8Array(e.data, HEAPU8, buffer, length);
Runtime.dynCall('vii', onText, [id, buffer]);
_free(buffer);
}
};
socket.socketImpl.onerror = function (e)
{
console.log(id + ' WS_Create - onError');
// Do not call this, onClose will be called with an apropriate error code and reason
//ws._callOnError(onError, id, "Unknown error.");
};
socket.socketImpl.onclose = function (e) {
console.log(id + ' WS_Create - onClose ' + e.code + ' ' + e.reason);
if (e.code != 1000)
{
if (e.reason != null && e.reason.length > 0)
ws._callOnError(onError, id, e.reason);
else
{
switch (e.code)
{
case 1001: ws._callOnError(onError, id, "Endpoint going away.");
break;
case 1002: ws._callOnError(onError, id, "Protocol error.");
break;
case 1003: ws._callOnError(onError, id, "Unsupported message.");
break;
case 1005: ws._callOnError(onError, id, "No status.");
break;
case 1006: ws._callOnError(onError, id, "Abnormal disconnection.");
break;
case 1009: ws._callOnError(onError, id, "Data frame too large.");
break;
default: ws._callOnError(onError, id, "Error " + e.code);
}
}
}
else
ws._callOnClose(onClose, id, e.code, e.reason);
};
return ws.Set(socket);
},
WS_GetState: function (id)
{
var socket = ws.Get(id);
if (typeof socket === 'undefined' ||
socket == null ||
typeof socket.socketImpl === 'undefined' ||
socket.socketImpl == null)
return 3; // closed
return socket.socketImpl.readyState;
},
WS_Send_String: function (id, str)
{
var socket = ws.Get(id);
var str = Pointer_stringify(str);
try
{
socket.socketImpl.send(str);
}
catch(e) {
ws._callOnError(socket.onError, id, ' ' + e.name + ': ' + e.message);
}
return socket.socketImpl.bufferedAmount;
},
WS_Send_Binary: function(id, ptr, pos, length)
{
var socket = ws.Get(id);
try
{
var buff = HEAPU8.subarray(ptr + pos, ptr + pos + length);
socket.socketImpl.send(buff /*HEAPU8.buffer.slice(ptr + pos, ptr + pos + length)*/);
}
catch(e) {
ws._callOnError(socket.onError, id, ' ' + e.name + ': ' + e.message);
}
return socket.socketImpl.bufferedAmount;
},
WS_Close: function (id, code, reason)
{
var socket = ws.Get(id);
var reasonStr = Pointer_stringify(reason);
console.log(id + ' WS_Close(' + code + ', ' + reasonStr + ')');
socket.socketImpl.close(/*ulong*/code, reasonStr);
},
WS_Release: function(id)
{
console.log(id + ' WS_Release');
ws.Remove(id);
}
};
autoAddDeps(Lib_BEST_HTTP_WebGL_WS_Bridge, '$ws');
mergeInto(LibraryManager.library, Lib_BEST_HTTP_WebGL_WS_Bridge);

View File

@@ -0,0 +1,37 @@
fileFormatVersion: 2
guid: 8efe6cedf2832a647a33465b85e4f311
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Facebook: WebGL
second:
enabled: 1
settings: {}
- first:
WebGL: WebGL
second:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant: