Commit c8147595 authored by Yoann Pigné's avatar Yoann Pigné

extracted transport layer from receiver

parent fe89f3b0
...@@ -12,6 +12,27 @@ ...@@ -12,6 +12,27 @@
global.netstream = {}; global.netstream = {};
} }
global.netstream.utf16to8 = function (str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
};
// Copyright (c) 2008 notmasteryet // Copyright (c) 2008 notmasteryet
global.netstream.TypedArrayReader = function(t_array) { global.netstream.TypedArrayReader = function(t_array) {
...@@ -227,7 +248,12 @@ ...@@ -227,7 +248,12 @@
}, },
encode: function(arrayBuffer) { encode: function(arrayBuffer) {
var base64 = ''; var base64 = '';
if('slice' in arrayBuffer){
var bytes = new Uint8Array(arrayBuffer); var bytes = new Uint8Array(arrayBuffer);
} else {
var bytes = arrayBuffer;
}
var byteLength = bytes.byteLength; var byteLength = bytes.byteLength;
var byteRemainder = byteLength % 3; var byteRemainder = byteLength % 3;
var mainLength = byteLength - byteRemainder; var mainLength = byteLength - byteRemainder;
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment