@symbo.ls/socket 2.29.57 → 2.29.59
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 +20 -20
- package/package.json +4 -4
- package/server.js +17 -8
package/client.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
import * as utils from '@domql/utils'
|
|
4
2
|
import io from 'socket.io-client'
|
|
5
3
|
|
|
@@ -10,13 +8,10 @@ const defautlOpts = {}
|
|
|
10
8
|
let CONNECT_ATTEPT = 0
|
|
11
9
|
const CONNECT_ATTEPT_MAX_ALLOWED = 1
|
|
12
10
|
|
|
13
|
-
const getIsDev = options =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
utils.isNotProduction()
|
|
18
|
-
)
|
|
19
|
-
}
|
|
11
|
+
const getIsDev = (options) =>
|
|
12
|
+
options.development ||
|
|
13
|
+
(window && window.location && window.location.host.includes('local')) ||
|
|
14
|
+
utils.isNotProduction()
|
|
20
15
|
|
|
21
16
|
const getSocketUrl = (options, isDev) => {
|
|
22
17
|
const SOCKET_BACKEND_URL = isDev
|
|
@@ -65,10 +60,12 @@ export const connect = (key, options = {}) => {
|
|
|
65
60
|
}
|
|
66
61
|
})
|
|
67
62
|
|
|
68
|
-
socket.on('connect_error', err => {
|
|
63
|
+
socket.on('connect_error', (err) => {
|
|
69
64
|
console.log(`event: connect_error | reason: ${err.message}`)
|
|
70
65
|
try {
|
|
71
|
-
if (isFunction(options.onError))
|
|
66
|
+
if (isFunction(options.onError)) {
|
|
67
|
+
options.onError(err, socket)
|
|
68
|
+
}
|
|
72
69
|
|
|
73
70
|
if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
|
|
74
71
|
CONNECT_ATTEPT++
|
|
@@ -77,10 +74,9 @@ export const connect = (key, options = {}) => {
|
|
|
77
74
|
|
|
78
75
|
if (utils.isNotProduction()) {
|
|
79
76
|
console.log(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
secondaryUrl,
|
|
77
|
+
`Could not connect to %c${primaryUrl}%c, reconnecting to %c${
|
|
78
|
+
secondaryUrl
|
|
79
|
+
}`,
|
|
84
80
|
'font-weight: bold; color: red;',
|
|
85
81
|
'',
|
|
86
82
|
'font-weight: bold; color: green;'
|
|
@@ -94,17 +90,21 @@ export const connect = (key, options = {}) => {
|
|
|
94
90
|
}
|
|
95
91
|
})
|
|
96
92
|
|
|
97
|
-
socket.on('disconnect', reason => {
|
|
93
|
+
socket.on('disconnect', (reason) => {
|
|
98
94
|
console.log(`event: disconnect | reason: ${reason}`)
|
|
99
95
|
try {
|
|
100
|
-
if (isFunction(options.onDisconnect))
|
|
96
|
+
if (isFunction(options.onDisconnect)) {
|
|
97
|
+
options.onDisconnect(reason, socket)
|
|
98
|
+
}
|
|
101
99
|
} catch (e) {
|
|
102
100
|
console.error(e)
|
|
103
101
|
}
|
|
104
102
|
})
|
|
105
103
|
|
|
106
104
|
socket.onAny((event, ...args) => {
|
|
107
|
-
if (event === 'connect')
|
|
105
|
+
if (event === 'connect') {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
108
|
|
|
109
109
|
try {
|
|
110
110
|
if (isFunction(options.onChange)) {
|
|
@@ -118,10 +118,10 @@ export const connect = (key, options = {}) => {
|
|
|
118
118
|
return socket
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
export function send
|
|
121
|
+
export function send(event = 'change', changes, options) {
|
|
122
122
|
this.emit(event, changes, { ...options, ...defautlOpts })
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export function disconnect
|
|
125
|
+
export function disconnect() {
|
|
126
126
|
this.disconnect()
|
|
127
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "2.29.
|
|
3
|
+
"version": "2.29.59",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
"start": "nodemon server.js"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@domql/utils": "^2.29.
|
|
14
|
-
"@symbo.ls/init": "^2.29.
|
|
13
|
+
"@domql/utils": "^2.29.59",
|
|
14
|
+
"@symbo.ls/init": "^2.29.59",
|
|
15
15
|
"chalk": "^5.4.1",
|
|
16
16
|
"express": "^4.21.2",
|
|
17
17
|
"http": "^0.0.1-security",
|
|
18
18
|
"socket.io": "^4.8.1",
|
|
19
19
|
"socket.io-client": "^4.8.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "1e603f4009489df16a52ebe50a8c91c32d855ba4"
|
|
22
22
|
}
|
package/server.js
CHANGED
|
@@ -7,7 +7,7 @@ import http from 'http'
|
|
|
7
7
|
import { Server } from 'socket.io'
|
|
8
8
|
import { createRequire } from 'module'
|
|
9
9
|
import * as utils from '@domql/utils'
|
|
10
|
-
const { overwriteDeep } =
|
|
10
|
+
const { overwriteDeep } = utils.default || utils
|
|
11
11
|
|
|
12
12
|
const require = createRequire(import.meta.url) // construct the require method
|
|
13
13
|
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in the ability to create the 'require' method
|
|
@@ -15,7 +15,9 @@ const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in
|
|
|
15
15
|
const app = express()
|
|
16
16
|
let io
|
|
17
17
|
|
|
18
|
-
const debugMsg = chalk.dim(
|
|
18
|
+
const debugMsg = chalk.dim(
|
|
19
|
+
'Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls'
|
|
20
|
+
)
|
|
19
21
|
|
|
20
22
|
export const updateDynamycFile = (changes, options = {}) => {
|
|
21
23
|
const { verbose, prettify, verboseCode } = options
|
|
@@ -23,13 +25,15 @@ export const updateDynamycFile = (changes, options = {}) => {
|
|
|
23
25
|
|
|
24
26
|
const newMerge = overwriteDeep(file, changes)
|
|
25
27
|
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
26
|
-
const initPath = process.cwd()
|
|
28
|
+
const initPath = `${process.cwd()}/node_modules/@symbo.ls/init/dynamic.json`
|
|
27
29
|
|
|
28
30
|
console.log(chalk.dim('\n----------------\n'))
|
|
29
31
|
|
|
30
32
|
console.log(chalk.dim('Received update:'))
|
|
31
33
|
console.log(Object.keys(changes).join(', '))
|
|
32
|
-
if (verboseCode)
|
|
34
|
+
if (verboseCode) {
|
|
35
|
+
console.log(chalk.dim(JSON.stringify(changes, null, prettify ?? 2)))
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
try {
|
|
35
39
|
fs.writeFileSync(initPath, mergeStr)
|
|
@@ -39,14 +43,18 @@ export const updateDynamycFile = (changes, options = {}) => {
|
|
|
39
43
|
} catch (e) {
|
|
40
44
|
console.log('')
|
|
41
45
|
console.log(chalk.bold.red('Error writing file'))
|
|
42
|
-
if (verbose)
|
|
43
|
-
|
|
46
|
+
if (verbose) {
|
|
47
|
+
console.error(e)
|
|
48
|
+
} else {
|
|
49
|
+
console.log(debugMsg)
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
}
|
|
46
53
|
|
|
47
|
-
|
|
54
|
+
// eslint-disable-next-line no-unused-vars
|
|
55
|
+
export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, opts = {}) => {
|
|
48
56
|
const server = http.createServer(app)
|
|
49
|
-
const { key } =
|
|
57
|
+
const { key } = opts
|
|
50
58
|
|
|
51
59
|
io = new Server(server, {
|
|
52
60
|
transports: ['websocket', 'polling', 'flashsocket'],
|
|
@@ -81,6 +89,7 @@ export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
|
81
89
|
|
|
82
90
|
socket.on('change', updateDynamycFile)
|
|
83
91
|
|
|
92
|
+
// eslint-disable-next-line no-unused-vars
|
|
84
93
|
socket.on('disconnect', (changes, options) => {
|
|
85
94
|
const { clientsCount } = io.engine
|
|
86
95
|
socket.to(key).emit('clientsCount', clientsCount)
|