gotty/js/spice-web-client/spiceproxy/socket.js
Soren L. Hansen c66ae7b2e4 First, primitive stab at SPiCE integration
Launch an Xspice and run:
echo -ne "\033]844;127.0.0.1;9876\007"

This will launch a SPiCE client connecting to 127.0.0.1:9876.

Still need to add all the security stuff and generally be
more defensive in the implementation.
2021-04-16 06:50:05 -07:00

56 lines
1.0 KiB
JavaScript

var net = require('net');
wdi.socketStatus = {
'idle':0,
'prepared':1,
'connected':2,
'disconnected':3,
'failed':4
};
//Works only with arrays of bytes (this means each value is a number in 0 to 255)
wdi.Socket = $.spcExtend(wdi.EventObject.prototype, {
netSocket: null,
status: wdi.socketStatus.idle,
binary: false,
connect: function (uri) {
var self = this;
var uriParts = uri.split(':');
var port = uriParts.pop();
var host = uriParts.pop();
this.netSocket = new net.Socket();
this.netSocket.connect(port, host);
this.status = wdi.socketStatus.prepared;
this.netSocket.on('spiceMessage', function (data) {
self.fire('message', new Uint8Array(data));
});
},
send: function (message) {
this.netSocket.write(message);
},
disconnect: function () {
this.netSocket.removeAllListeners();
this.netSocket.end();
},
setStatus: function (status) {
this.status = status;
},
getStatus: function () {
return this.status;
},
getSocket: function () {
return this.netSocket;
}
});