Skip to content

Commit

Permalink
Merge pull request #49 from paullouisageneau/support-sharedarraybuffe…
Browse files Browse the repository at this point in the history
…r-heap

Support SharedArrayBuffer heap
  • Loading branch information
paullouisageneau authored Feb 21, 2024
2 parents da3e8bc + 4da75bb commit a5f0cd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions wasm/include/rtc/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#define RTC_INCLUDE_H

#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <stdexcept>
Expand Down
8 changes: 7 additions & 1 deletion wasm/js/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,13 @@
if(dataChannel.readyState != 'open') return -1;
if(size >= 0) {
var heapBytes = new Uint8Array(Module['HEAPU8'].buffer, pBuffer, size);
dataChannel.send(heapBytes);
if(heapBytes.buffer instanceof ArrayBuffer) {
dataChannel.send(heapBytes);
} else {
var byteArray = new Uint8Array(new ArrayBuffer(size));
byteArray.set(heapBytes);
dataChannel.send(byteArray);
}
return size;
} else {
var str = UTF8ToString(pBuffer);
Expand Down
8 changes: 7 additions & 1 deletion wasm/js/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@
if(webSocket.readyState != 1) return -1;
if(size >= 0) {
var heapBytes = new Uint8Array(Module['HEAPU8'].buffer, pBuffer, size);
webSocket.send(heapBytes);
if(heapBytes.buffer instanceof ArrayBuffer) {
webSocket.send(heapBytes);
} else {
var byteArray = new Uint8Array(new ArrayBuffer(size));
byteArray.set(heapBytes);
webSocket.send(byteArray);
}
return size;
} else {
var str = UTF8ToString(pBuffer);
Expand Down

0 comments on commit a5f0cd2

Please sign in to comment.