@symbo.ls/socket 2.11.131 → 2.11.162
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/LICENSE +21 -0
- package/client.js +26 -19
- package/package.json +3 -2
- package/server.js +24 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 symbo.ls
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/client.js
CHANGED
|
@@ -9,28 +9,28 @@ const { window } = globals.default || globals
|
|
|
9
9
|
|
|
10
10
|
const ENV = process.env.NODE_ENV
|
|
11
11
|
|
|
12
|
-
const SOCKET_BACKEND_URL = window && window.location &&
|
|
13
|
-
window.location.host.includes('local')
|
|
14
|
-
? 'localhost:13335'
|
|
15
|
-
: 'socket.symbols.app' ||
|
|
16
|
-
'https://socket.symbols.app'
|
|
17
|
-
|
|
18
|
-
let socket
|
|
19
|
-
let tryConnect = 0
|
|
20
12
|
const defautlOpts = {}
|
|
21
|
-
const tryConnectMax = 1
|
|
22
13
|
|
|
23
14
|
export const connect = (key, options = {}) => {
|
|
15
|
+
const isDev = options.development ||
|
|
16
|
+
(window && window.location && window.location.host.includes('local')) ||
|
|
17
|
+
(ENV === 'test' || ENV === 'development')
|
|
18
|
+
|
|
19
|
+
const SOCKET_BACKEND_URL = isDev
|
|
20
|
+
? 'http://localhost:13336/'
|
|
21
|
+
: 'https://socket.symbols.app/'
|
|
22
|
+
|
|
24
23
|
const socketUrls = isArray(options.socketUrl)
|
|
25
24
|
? options.socketUrl
|
|
26
25
|
: [options.socketUrl || SOCKET_BACKEND_URL]
|
|
26
|
+
|
|
27
27
|
const primaryUrl = socketUrls[0]
|
|
28
28
|
const secondaryUrl = socketUrls[1] || 'socket.symbols.app'
|
|
29
29
|
|
|
30
|
-
socket = io(primaryUrl || SOCKET_BACKEND_URL)
|
|
30
|
+
const socket = io(primaryUrl || SOCKET_BACKEND_URL)
|
|
31
31
|
|
|
32
32
|
socket.on('connect', () => {
|
|
33
|
-
if (
|
|
33
|
+
if (isDev) {
|
|
34
34
|
console.log(
|
|
35
35
|
`Connected to %c${primaryUrl || SOCKET_BACKEND_URL} %c${key} %c${socket.id}`,
|
|
36
36
|
'font-weight: bold; color: green;',
|
|
@@ -39,7 +39,7 @@ export const connect = (key, options = {}) => {
|
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
socket.emit('initConnect', options)
|
|
42
|
+
socket.emit('initConnect', { key, ...options })
|
|
43
43
|
|
|
44
44
|
try {
|
|
45
45
|
if (isFunction(options.onConnect)) {
|
|
@@ -50,15 +50,18 @@ export const connect = (key, options = {}) => {
|
|
|
50
50
|
}
|
|
51
51
|
})
|
|
52
52
|
|
|
53
|
+
let CONNECT_ATTEPT = 0
|
|
54
|
+
const CONNECT_ATTEPT_MAX_ALLOWED = 1
|
|
55
|
+
|
|
53
56
|
socket.on('connect_error', (err) => {
|
|
54
57
|
console.log(`event: connect_error | reason: ${err.message}`)
|
|
55
58
|
try {
|
|
56
59
|
if (isFunction(options.onError)) options.onError(err, socket)
|
|
57
60
|
|
|
58
|
-
if (
|
|
61
|
+
if (CONNECT_ATTEPT < CONNECT_ATTEPT_MAX_ALLOWED) {
|
|
59
62
|
socket.disconnect()
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
CONNECT_ATTEPT++
|
|
62
65
|
|
|
63
66
|
if (ENV === 'test' || ENV === 'development') {
|
|
64
67
|
console.log(
|
|
@@ -89,17 +92,21 @@ export const connect = (key, options = {}) => {
|
|
|
89
92
|
if (event === 'connect') return
|
|
90
93
|
|
|
91
94
|
try {
|
|
92
|
-
if (isFunction(options.onChange))
|
|
95
|
+
if (isFunction(options.onChange)) {
|
|
96
|
+
options.onChange(event, args[0], socket)
|
|
97
|
+
}
|
|
93
98
|
} catch (e) {
|
|
94
99
|
console.error(e)
|
|
95
100
|
}
|
|
96
101
|
})
|
|
102
|
+
|
|
103
|
+
return socket
|
|
97
104
|
}
|
|
98
105
|
|
|
99
|
-
export
|
|
100
|
-
|
|
106
|
+
export function send (event = 'change', changes, options) {
|
|
107
|
+
this.emit(event, changes, { ...options, ...defautlOpts })
|
|
101
108
|
}
|
|
102
109
|
|
|
103
|
-
export
|
|
104
|
-
|
|
110
|
+
export function disconnect () {
|
|
111
|
+
this.disconnect()
|
|
105
112
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "2.11.
|
|
3
|
+
"version": "2.11.162",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@domql/utils": "latest",
|
|
14
|
+
"chalk": "^5.0.0",
|
|
14
15
|
"express": "^4.18.1",
|
|
15
16
|
"http": "^0.0.1-security",
|
|
16
17
|
"merge-deep": "^3.0.3",
|
|
17
18
|
"socket.io": "^4.5.2",
|
|
18
19
|
"socket.io-client": "^4.5.2"
|
|
19
20
|
},
|
|
20
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "fe3359a1d6c14d38f45f5e5db10ef2056947a228"
|
|
21
22
|
}
|
package/server.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import fs from 'fs'
|
|
4
|
+
import chalk from 'chalk'
|
|
4
5
|
import express from 'express'
|
|
5
6
|
import http from 'http'
|
|
6
7
|
import { Server } from 'socket.io'
|
|
7
8
|
import { createRequire } from 'module'
|
|
8
9
|
import * as utils from '@domql/utils'
|
|
9
|
-
const { overwriteDeep } = utils
|
|
10
|
+
const { overwriteDeep } = utils.default
|
|
10
11
|
|
|
11
12
|
const require = createRequire(import.meta.url) // construct the require method
|
|
12
13
|
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in the ability to create the 'require' method
|
|
@@ -14,20 +15,32 @@ const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in
|
|
|
14
15
|
const app = express()
|
|
15
16
|
let io
|
|
16
17
|
|
|
18
|
+
const debugMsg = chalk.dim('Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls')
|
|
19
|
+
|
|
17
20
|
export const updateDynamycFile = (changes, options = {}) => {
|
|
18
|
-
const {
|
|
21
|
+
const { verbose, prettify, verboseCode } = options
|
|
19
22
|
const file = require('@symbo.ls/init/dynamic.json')
|
|
20
23
|
|
|
21
|
-
const newMerge = overwriteDeep(
|
|
24
|
+
const newMerge = overwriteDeep(file, changes)
|
|
22
25
|
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
23
26
|
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
console.log(chalk.dim('\n----------------\n'))
|
|
29
|
+
|
|
30
|
+
console.log(chalk.dim('Received update:'))
|
|
31
|
+
console.log(Object.keys(changes).join(', '))
|
|
32
|
+
if (verboseCode) console.log(chalk.dim(JSON.stringify(changes, null, prettify ?? 2)))
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
fs.writeFileSync(initPath, mergeStr)
|
|
36
|
+
if (verbose) {
|
|
37
|
+
console.log(chalk.bold.green('\nChanges wrote to the file'))
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.log('')
|
|
41
|
+
console.log(chalk.bold.red('Error writing file'))
|
|
42
|
+
if (verbose) console.error(e)
|
|
43
|
+
else console.log(debugMsg)
|
|
31
44
|
}
|
|
32
45
|
}
|
|
33
46
|
|
|
@@ -75,7 +88,7 @@ export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
|
75
88
|
})
|
|
76
89
|
})
|
|
77
90
|
|
|
78
|
-
server.listen(
|
|
79
|
-
console.log('listening on *:
|
|
91
|
+
server.listen(13336, () => {
|
|
92
|
+
console.log('listening on *:13336')
|
|
80
93
|
})
|
|
81
94
|
}
|