@iotize/device-com-socket.node
Version:
Socket communication protocol to communicate with an iotize
60 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientAdapter = void 0;
const rxjs_1 = require("rxjs");
class ClientAdapter {
constructor(socket) {
this.socket = socket;
this._events = new rxjs_1.Subject();
// Handle incoming messages from clients.
socket.on('data', (data) => {
this._events.next({
type: 'data',
payload: data,
client: this,
});
});
// Remove the client from the list when it leaves
socket.on('error', (err) => {
this._events.next({
type: 'error',
payload: err,
client: this,
});
});
// Remove the client from the list when it leaves
socket.on('end', () => {
this._events.next({
type: 'end',
payload: undefined,
client: this,
});
});
}
ready() {
return Promise.resolve();
}
events() {
return this._events;
}
remoteAddress() {
return this.socket.remoteAddress;
}
remotePort() {
return this.socket.remotePort;
}
getClientName() {
return this.socket.remoteAddress + ':' + this.socket.remotePort;
}
close() {
this.socket.end();
}
write(data) {
this.socket.write(data);
}
isWritable() {
return this.socket.writable;
}
}
exports.ClientAdapter = ClientAdapter;
//# sourceMappingURL=client-adapter.js.map