datachannel-wasm: WebSocket error unknown
Code,
#include "rtc/wasm-rtc.hpp"
#include <memory>
#include <iostream>
int main() {
auto ws = std::make_shared<rtc::WebSocket>();
ws->onError([](std::string s) {
std::cout << "WebSocket error"
<< s
<< "\n";
});
ws->open("ws://whatever.com");
return 0;
}
Compile with,
em++ main.cpp ^
C:/testPro/testPro/deps/datachannel-wasm/wasm/src/channel.cpp C:/testPro/testPro/deps/datachannel-wasm/wasm/src/datachannel.cpp ^
C:/testPro/testPro/deps/datachannel-wasm/wasm/src/peerconnection.cpp C:/testPro/testPro/deps/datachannel-wasm/wasm/src/websocket.cpp ^
-o testMe.js --bind -Oz -I C:/testPro/testPro -I C:\testPro\testPro\deps\datachannel-wasm\wasm\include ^
-I C:\testPro\testPro\deps\datachannel-wasm\wasm\include\rtc ^
--js-library C:/testPro/testPro/deps/datachannel-wasm/wasm/js/webrtc.js ^
--js-library C:/testPro/testPro/deps/datachannel-wasm/wasm/js/websocket.js ^
-lpthread ^
-s EXPORT_ALL=1 -std=c++1z -s MODULARIZE=1 -g4 -s "EXPORT_NAME='testMe'" ^
-s DISABLE_EXCEPTION_CATCHING=0 -s ASYNCIFY=1 -s NO_EXIT_RUNTIME=1 -s WASM=1 ^
-s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']" -s ALLOW_MEMORY_GROWTH=1 -DNDEBUG=1
Result,
WebSocket error unknown Uncaught 5279544
Real world app stack-trace,

To debug the error, I’ve modified the ./wasm/websocket.js as follows,
wsCreateWebSocket: function(pUrl) {
var url = UTF8ToString(pUrl);
console.log(pUrl)
if(!window.WebSocket) return 0;
return WEBSOCKET.registerWebSocket(new WebSocket(url));
},
The function console log 5279128 and I have no idea why it console log a numeric type data.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 32 (15 by maintainers)
Thank you for this. Everything works now!
Fine, I will use in single thread for now. I guess all will be okay.