prep for addon - find loop

This commit is contained in:
Felipe Gasper
2017-10-16 15:12:07 +01:00
parent a6efda6120
commit 151eac6f4f
4 changed files with 1052 additions and 100 deletions
+76
View File
@@ -0,0 +1,76 @@
//Eventually?
//import { Zmodem } from './zmodemjs/dist/zmodem';
(function (addon) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = addon(require('../../Terminal').Terminal);
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../xterm'], addon);
} else {
/*
* Plain browser environment
*/
addon(window.Terminal);
}
})(function _zmodemAddon(Terminal) {
if (Terminal.prototype.attach) {
throw "The “zmodem” and “attach” addons are mutually incompatible.";
}
function _makeSendWsWrapper(socket) {
return
}
Object.assign(
Terminal.prototype,
{
zmodemAttach: function zmodemAttach(ws) {
var term = this;
var senderFunc = function _ws_sender_func(octets) {
ws.send( new Uint8Array(octets) );
};
var zsentry = new Zmodem.Sentry( {
to_terminal: function _to_terminal(octets) {
term.write(
String.fromCharCode.apply(String, octets)
);
},
sender: senderFunc,
on_retract: function _on_retract() {
term.emit("zmodemRetract");
},
on_detect: function _on_detect(detection) {
term.emit("zmodemDetect", detection);
},
} );
function handleWSMessage(evt) {
//For some reason the first message from the server is text.
if (typeof evt.data === "string") {
term.write(evt.data);
}
else {
zsentry.consume(evt.data);
}
}
ws.binaryType = "arraybuffer";
ws.addEventListener("message", handleWSMessage);
},
zmodemBrowser: Zmodem.Browser,
}
);
});