Closed 724789975 closed 6 years ago
附 WebSocket.jslib var LibraryWebSockets = { $webSocketInstances: [],
SocketCreate: function(url) { var str = Pointer_stringify(url); var socket = { socket: new WebSocket(str), buffer: new Uint8Array(0), error: null, messages: [] }
socket.socket.binaryType = 'arraybuffer';
socket.socket.onmessage = function (e) {
// Todo: handle other data types?
if (e.data instanceof Blob)
{
var reader = new FileReader();
reader.addEventListener("loadend", function() {
var array = new Uint8Array(reader.result);
socket.messages.push(array);
});
reader.readAsArrayBuffer(e.data);
}
else if (e.data instanceof ArrayBuffer)
{
var array = new Uint8Array(e.data);
socket.messages.push(array);
}
else if (typeof e.data === "string")
{
var reader = new FileReader();
reader.addEventListener("loadend", function(){
var array = new Uint8Array(reader.result);
socket.messages.push(array);
});
var blob = new Blob([e.data]);
reader.readAsArrayBuffer(blob);
}
};
socket.socket.onclose = function (e) {
if (e.code != 1000)
{
if (e.reason != null && e.reason.length > 0)
socket.error = e.reason;
else
{
switch (e.code)
{
case 1001:
socket.error = "Endpoint going away.";
break;
case 1002:
socket.error = "Protocol error.";
break;
case 1003:
socket.error = "Unsupported message.";
break;
case 1005:
socket.error = "No status.";
break;
case 1006:
socket.error = "Abnormal disconnection.";
break;
case 1009:
socket.error = "Data frame too large.";
break;
default:
socket.error = "Error "+e.code;
}
}
}
}
var instance = webSocketInstances.push(socket) - 1;
return instance;
},
SocketState: function (socketInstance) { var socket = webSocketInstances[socketInstance]; return socket.socket.readyState; },
SocketError: function (socketInstance, ptr, bufsize) { var socket = webSocketInstances[socketInstance]; if (socket.error == null) return 0; var str = socket.error.slice(0, Math.max(0, bufsize - 1)); stringToUTF8(str, ptr, Math.max(0, bufsize - 1)); // writeStringToMemory(str, ptr, false); return 1; },
SocketSend: function (socketInstance, ptr, length) { var socket = webSocketInstances[socketInstance]; socket.socket.send (HEAPU8.buffer.slice(ptr, ptr+length)); },
SocketRecvLength: function(socketInstance) { var socket = webSocketInstances[socketInstance]; if (socket.messages.length == 0) return 0; return socket.messages[0].length; },
SocketRecv: function (socketInstance, ptr, length) { var socket = webSocketInstances[socketInstance]; if (socket.messages.length == 0) return 0; if (socket.messages[0].length > length) return 0; HEAPU8.set(socket.messages[0], ptr); socket.messages = socket.messages.slice(1); },
SocketClose: function (socketInstance) { var socket = webSocketInstances[socketInstance]; socket.socket.close(); } };
autoAddDeps(LibraryWebSockets, '$webSocketInstances'); mergeInto(LibraryManager.library, LibraryWebSockets);
H5.jslib mergeInto(LibraryManager.library, { GetUrl: function () { var url = window.document.location.href; var bufferSize = lengthBytesUTF8(url) + 1; var buffer = _malloc(bufferSize); stringToUTF8(url, buffer, bufferSize); return buffer; }, LogStr: function(str) { console.log(Pointer_stringify(str)); }, AlertString: function(str) { window.alert(Pointer_stringify(str)); }, });
没有每个版本都试,但至少这个版本当时是发布过webgl应用的:https://github.com/Tencent/xLua/releases/tag/v2.1.10
我试了一下 在development build模式下 生成失败 关闭development build生成成功 我使用的版本是2.1.11 另 之前有个警告 WebGLPlugins/perflib.c:172:57: warning: comparison of array 'ar.short_src' not equal to a null pointer is always true [-Wtautological-pointer-compare] snprintf(used_in, sizeof(used_in) - 1, "%s:%d~%d", ar.short_src != NULL ? ar.short_src : "", ar.linedefined, ar.lastlinedefined);
我也遇到了在development build模式下 生成失败,需要用development来使用Profiler
xlua支持webgl吗 我发布webgl生成时报错
Failed running "C:\Program Files\Unity2017.3.f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten_Win\python\2.7.5.3_64bit\python.exe" "C:\Program Files\Unity2017.3.f1\Editor\Data\PlaybackEngines\WebGLSupport\BuildTools\Emscripten\emcc" @"F:\FxLib\Client_Unity\Test\Assets..\Temp\emcc_arguments.resp"
stdout: stderr:WARNING:root:--separate-asm works best when compiling to HTML. otherwise, you must yourself load the '.asm.js' file that is emitted separately, and must do so before loading the main '.js` file In file included from F:\FxLib\Client_Unity\Test\Assets\Plugins\WebGL\xlua_webgl.cpp:36: F:\FxLib\Client_Unity\Test\Assets\Plugins\WebGL/../../../WebGLPlugins/perflib.c:172:57: warning: comparison of array 'ar.short_src' not equal to a null pointer is always true [-Wtautological-pointer-compare] snprintf(used_in, sizeof(used_in) - 1, "%s:%d~%d", ar.short_src != NULL ? ar.short_src : "", ar.linedefined, ar.lastlinedefined);