@symbo.ls/socket 0.0.22 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.js +37 -13
- package/package.json +4 -3
- package/server.js +1 -1
package/client.js
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isFunction } from '@domql/utils'
|
|
3
|
+
import { isFunction, isArray } from '@domql/utils'
|
|
4
4
|
import io from 'socket.io-client'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
// const SOCKET_BACKEND_URL = 'ws://52.14.150.69:8080'
|
|
8
|
-
// const SOCKET_BACKEND_URL = 'ws://ec2-52-14-150-69.us-east-2.compute.amazonaws.com:8080'
|
|
9
|
-
// const SOCKET_BACKEND_URL = 'ws://ec2-52-14-150-69.us-east-2.compute.amazonaws.com:8080'
|
|
10
|
-
// const SOCKET_BACKEND_URL = 'ws://52.14.150.69:8080'
|
|
6
|
+
const ENV = process.env.NODE_ENV
|
|
11
7
|
|
|
12
8
|
const SOCKET_BACKEND_URL = window.location
|
|
13
|
-
.host.includes('
|
|
14
|
-
? '
|
|
15
|
-
: '
|
|
9
|
+
.host.includes('local')
|
|
10
|
+
? 'localhost:13335'
|
|
11
|
+
: 'socket.symbols.app'
|
|
16
12
|
|
|
17
13
|
let socket
|
|
18
14
|
const defautlOpts = {}
|
|
19
15
|
|
|
20
16
|
export const connect = (key, options = {}) => {
|
|
21
|
-
|
|
17
|
+
const socketUrls = isArray(options.socketUrl) ? options.socketUrl : [options.socketUrl || SOCKET_BACKEND_URL]
|
|
18
|
+
const primaryUrl = socketUrls[0]
|
|
19
|
+
const secondaryUrl = socketUrls[1] || 'socket.symbols.app'
|
|
20
|
+
|
|
21
|
+
socket = io(primaryUrl || SOCKET_BACKEND_URL)
|
|
22
22
|
|
|
23
23
|
socket.on('connect', () => {
|
|
24
|
-
|
|
24
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
25
|
+
console.log(
|
|
26
|
+
`Connected to %c${primaryUrl || SOCKET_BACKEND_URL} %c${key} %c${socket.id}`,
|
|
27
|
+
'font-weight: bold; color: green;',
|
|
28
|
+
'font-weight: bold;',
|
|
29
|
+
''
|
|
30
|
+
)
|
|
31
|
+
}
|
|
25
32
|
|
|
26
33
|
socket.emit('initConnect', options)
|
|
27
34
|
|
|
@@ -32,13 +39,30 @@ export const connect = (key, options = {}) => {
|
|
|
32
39
|
}
|
|
33
40
|
})
|
|
34
41
|
|
|
42
|
+
let tryConnect = 0
|
|
43
|
+
const tryConnectMax = 1
|
|
35
44
|
socket.on('connect_error', (err) => {
|
|
36
45
|
console.log(`event: connect_error | reason: ${err.message}`)
|
|
37
46
|
try {
|
|
38
47
|
if (isFunction(options.onError)) options.onError(err, socket)
|
|
48
|
+
if (tryConnect === tryConnectMax) {
|
|
49
|
+
socket.disconnect()
|
|
50
|
+
|
|
51
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
52
|
+
console.log(
|
|
53
|
+
'Could not connect to %c' + primaryUrl + '%c, reconnecting to %c' + secondaryUrl,
|
|
54
|
+
'font-weight: bold; color: red;',
|
|
55
|
+
'',
|
|
56
|
+
'font-weight: bold; color: green;'
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
connect(key, { ...options, socketUrl: secondaryUrl })
|
|
61
|
+
}
|
|
39
62
|
} catch (e) {
|
|
40
63
|
console.error(e)
|
|
41
64
|
}
|
|
65
|
+
tryConnect++
|
|
42
66
|
})
|
|
43
67
|
|
|
44
68
|
socket.on('disconnect', (reason) => {
|
|
@@ -65,6 +89,6 @@ export const send = (event = 'change', changes, options) => {
|
|
|
65
89
|
socket.emit(event, changes, { ...options, ...defautlOpts })
|
|
66
90
|
}
|
|
67
91
|
|
|
68
|
-
export const disconnect =
|
|
69
|
-
socket.
|
|
92
|
+
export const disconnect = () => {
|
|
93
|
+
socket.disconnect()
|
|
70
94
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"start": "nodemon server.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@domql/utils": "latest",
|
|
14
15
|
"express": "^4.18.1",
|
|
15
16
|
"http": "^0.0.1-security",
|
|
16
17
|
"merge-deep": "^3.0.3",
|
|
17
|
-
"@domql/utils": "latest",
|
|
18
18
|
"socket.io": "^4.5.2",
|
|
19
19
|
"socket.io-client": "^4.5.2"
|
|
20
20
|
},
|
|
@@ -29,5 +29,6 @@
|
|
|
29
29
|
},
|
|
30
30
|
"standard": {
|
|
31
31
|
"parser": "babel-eslint"
|
|
32
|
-
}
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "ce1ceb5545eb5189a49484ba1c57261f3429b577"
|
|
33
34
|
}
|
package/server.js
CHANGED
|
@@ -10,7 +10,7 @@ import mergeDeep from 'merge-deep' // use the require method
|
|
|
10
10
|
import { createRequire } from 'module'
|
|
11
11
|
|
|
12
12
|
const require = createRequire(import.meta.url) // construct the require method
|
|
13
|
-
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/
|
|
13
|
+
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in the ability to create the 'require' method
|
|
14
14
|
|
|
15
15
|
const app = express()
|
|
16
16
|
|