Skip to content

Commit 2dca493

Browse files
committed
2.5.14-alpha
1 parent e0b04ea commit 2dca493

File tree

8 files changed

+227
-6
lines changed

8 files changed

+227
-6
lines changed

backend/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remoteit-headless",
3-
"version": "2.5.13-alpha",
3+
"version": "2.5.14-alpha",
44
"private": true,
55
"main": "build/index.js",
66
"scripts": {

backend/src/CLIWebSocket.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import WebSocket from 'ws'
2+
3+
type ICallback = (payload: IPayload) => void
4+
5+
export default class CLIWebSocket {
6+
onConnect?: ICallback
7+
onClose?: ICallback
8+
onError?: ICallback
9+
onDataReceived?: ICallback
10+
private _ws: any
11+
private _url: string
12+
private _reconnect: boolean = true
13+
private _delayInMsBeforeReconnect: number = 1000
14+
private _onMessageReceived: { [key: string]: ICallback } = {}
15+
16+
constructor(url: string) {
17+
this._url = url
18+
this.setUpConnection()
19+
}
20+
21+
public send(type: string, data: any) {
22+
console.log('--------------')
23+
console.trace()
24+
console.log('--------------')
25+
console.log('type', type)
26+
console.log('--------------')
27+
console.log('data', data)
28+
console.log('--------------')
29+
const dataAsString = JSON.stringify({
30+
Type: type,
31+
Data: data,
32+
})
33+
34+
this._ws.send(dataAsString)
35+
}
36+
37+
public on(type: string, callback: ICallback) {
38+
this._onMessageReceived[type] = callback
39+
}
40+
41+
private setUpConnection() {
42+
this._ws = new WebSocket(this._url)
43+
44+
this._ws.onclose = (event: any) => {
45+
const response = JSON.parse(event.data)
46+
47+
if (typeof this.onClose === 'function') {
48+
this.onClose(response)
49+
}
50+
51+
if (this._reconnect) {
52+
setTimeout(() => this.setUpConnection, this._delayInMsBeforeReconnect)
53+
}
54+
}
55+
56+
this._ws.onopen = (response: any) => {
57+
if (typeof this.onConnect === 'function') {
58+
this.onConnect(response)
59+
}
60+
}
61+
62+
// WHEN data received, then de-serialize and pass up the chain
63+
this._ws.onmessage = (event: any) => {
64+
const response = JSON.parse(event.data)
65+
66+
if (typeof this.onDataReceived === 'function') {
67+
this.onDataReceived(response)
68+
}
69+
70+
if (typeof this._onMessageReceived[response.type] === 'function') {
71+
this._onMessageReceived[response.type](response)
72+
}
73+
}
74+
75+
// IF errors just notify
76+
this._ws.onerror = (event: any) => {
77+
const response = JSON.parse(event.data)
78+
79+
if (typeof this.onError === 'function') {
80+
this.onError(response)
81+
}
82+
}
83+
}
84+
}

backend/src/cliController.ts

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import server from './server'
2+
import Logger from './Logger'
3+
import EventBus from './EventBus'
4+
import CLIWebSocket from './CLIWebSocket'
5+
import { WEBSOCKET_URL } from './constants'
6+
7+
class CLIController {
8+
private socket: CLIWebSocket
9+
10+
constructor() {
11+
Logger.info('START CLI CONTROLLER')
12+
this.socket = new CLIWebSocket(WEBSOCKET_URL)
13+
this.addHandlers()
14+
EventBus.on(server.EVENTS.authenticated, this.ready)
15+
}
16+
17+
ready = () => {
18+
// this.socket.send('GetConnections', [])
19+
}
20+
21+
send = (channel: string, data: object) => {
22+
this.socket.send(channel, data)
23+
}
24+
25+
addHandlers = () => {
26+
this.socket.onConnect = () => console.log('onConnect')
27+
this.socket.onClose = () => console.log('onClose')
28+
this.socket.onError = () => console.warn('onError')
29+
30+
this.socket.on('GetConnections', (response: IPayload) => {
31+
console.log('socket.on-GetConnections')
32+
if (response.hasError) {
33+
console.log(' error: ', response.errorMessage)
34+
} else {
35+
console.log(' data:', response.data)
36+
}
37+
})
38+
39+
this.socket.on('SetConnections', (response: IPayload) => {
40+
console.log('socket.on-SetConnections')
41+
if (response.hasError) {
42+
console.log(' error: ', response.errorMessage)
43+
}
44+
})
45+
46+
this.socket.on('GetAuth', (response: IPayload) => {
47+
console.log('socket.on-GetAuth')
48+
if (response.hasError) {
49+
console.log(' error: ', response.errorMessage)
50+
} else {
51+
console.log(' data:', response.data)
52+
}
53+
})
54+
55+
this.socket.on('SetAuth', (response: IPayload) => {
56+
console.log('socket.on-SetAuth')
57+
if (response.hasError) {
58+
console.log(' error: ', response.errorMessage)
59+
}
60+
})
61+
62+
this.socket.on('Forget', (response: IPayload) => {
63+
console.log('socket.on-Forget')
64+
if (response.hasError) {
65+
console.log(' error: ', response.errorMessage)
66+
} else {
67+
console.log(' data:', response.data)
68+
}
69+
})
70+
}
71+
}
72+
73+
export default new CLIController()
74+
75+
/*
76+
77+
ACTION EXAMPLES
78+
79+
function GetConnections() {
80+
var object = {}
81+
82+
socket.Send('GetConnections', object)
83+
}
84+
function SetConnections() {
85+
var object = {
86+
connections: [
87+
{
88+
uid: '80:00:00:00:01:01:8E:EE',
89+
name: '',
90+
port: 25185,
91+
hostname: 'localhost',
92+
disabled: false,
93+
retry: true,
94+
failover: true,
95+
restart: false,
96+
createdTime: 0,
97+
owner: '',
98+
restriction: '',
99+
connected: false,
100+
connecting: false,
101+
error: {
102+
code: 0,
103+
errorMessage: '',
104+
},
105+
startTime: 0,
106+
stopTime: 0,
107+
metadata: null,
108+
},
109+
],
110+
}
111+
112+
socket.Send('SetConnections', object)
113+
}
114+
115+
function GetAuth() {
116+
var object = {}
117+
118+
socket.Send('GetAuth', object)
119+
}
120+
function SetAuth() {
121+
var object = {
122+
authHash:
123+
'hVYwtk/RhKZMDDFVf9SfIjNHCp9e/J+VHGHsXRP5Xeohd+5BHnEjI+MwBDEles+EUi/FF6ZNDki98eJu2D5ew1EtJ7pQc0hKNBqgJcqwEb4=',
124+
userName: 'nicolae@remote.it',
125+
}
126+
127+
socket.Send('SetAuth', object)
128+
}
129+
130+
function Forget() {
131+
var object = {
132+
uid: '80:00:00:00:01:01:8E:EE',
133+
}
134+
135+
socket.Send('Forget', object)
136+
}
137+
*/

frontend/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remoteit-desktop-frontend",
3-
"version": "2.5.13-alpha",
3+
"version": "2.5.14-alpha",
44
"private": true,
55
"main": "src/server/initialize.js",
66
"scripts": {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "remoteit-desktop",
3-
"version": "2.5.13-alpha",
3+
"version": "2.5.14-alpha",
44
"private": true,
55
"main": "build/index.js",
66
"description": "remote.it cross platform desktop application for creating and hosting connections",

0 commit comments

Comments
 (0)