@symbo.ls/socket 2.10.114 → 2.10.123
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 +12 -6
- package/package.json +2 -2
- package/server.js +19 -17
- package/README.md +0 -11
- package/__client.js +0 -98
package/client.js
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import * as utils from '@domql/utils'
|
|
4
|
+
import * as globals from '@domql/globals'
|
|
4
5
|
import io from 'socket.io-client'
|
|
5
6
|
|
|
7
|
+
const { isFunction, isArray } = utils
|
|
8
|
+
const { window } = globals
|
|
9
|
+
|
|
6
10
|
const ENV = process.env.NODE_ENV
|
|
7
11
|
|
|
8
|
-
const SOCKET_BACKEND_URL = window.location
|
|
9
|
-
.host.includes('local')
|
|
12
|
+
const SOCKET_BACKEND_URL = window.location &&
|
|
13
|
+
window.location.host.includes('local')
|
|
10
14
|
? 'localhost:13335'
|
|
11
|
-
: 'https://socket.symbols.app'
|
|
15
|
+
: 'https://socket.symbols.app' ||
|
|
16
|
+
'https://socket.symbols.app'
|
|
12
17
|
|
|
13
18
|
let socket
|
|
14
19
|
const defautlOpts = {}
|
|
15
20
|
|
|
16
21
|
export const connect = (key, options = {}) => {
|
|
17
|
-
const socketUrls = isArray(options.socketUrl)
|
|
18
|
-
? options.socketUrl
|
|
22
|
+
const socketUrls = isArray(options.socketUrl)
|
|
23
|
+
? options.socketUrl
|
|
24
|
+
: [options.socketUrl || SOCKET_BACKEND_URL]
|
|
19
25
|
const primaryUrl = socketUrls[0]
|
|
20
26
|
const secondaryUrl = socketUrls[1] || 'socket.symbols.app'
|
|
21
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.123",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"socket.io": "^4.5.2",
|
|
18
18
|
"socket.io-client": "^4.5.2"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "8e7c8dada6686b012c70e414cada2dd249790ab2"
|
|
21
21
|
}
|
package/server.js
CHANGED
|
@@ -4,16 +4,31 @@ import fs from 'fs'
|
|
|
4
4
|
import express from 'express'
|
|
5
5
|
import http from 'http'
|
|
6
6
|
import { Server } from 'socket.io'
|
|
7
|
-
import { dirname } from 'path' // eslint-disable-line
|
|
8
|
-
import mergeDeep from 'merge-deep' // use the require method
|
|
9
|
-
|
|
10
7
|
import { createRequire } from 'module'
|
|
8
|
+
import { deepMerge, overwriteDeep } from '@domql/utils'
|
|
11
9
|
|
|
12
10
|
const require = createRequire(import.meta.url) // construct the require method
|
|
13
11
|
const DES_SYS_DEFAULT_FILE = require('@symbo.ls/init/dynamic.json') // Bring in the ability to create the 'require' method
|
|
14
12
|
|
|
15
13
|
const app = express()
|
|
16
14
|
|
|
15
|
+
export const updateDynamycFile = (changes, options = {}) => {
|
|
16
|
+
const { key, live } = options
|
|
17
|
+
const file = require('@symbo.ls/init/dynamic.json')
|
|
18
|
+
|
|
19
|
+
const newMerge = overwriteDeep(changes, file)
|
|
20
|
+
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
21
|
+
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/dynamic.json'
|
|
22
|
+
|
|
23
|
+
if (live) {
|
|
24
|
+
io.to(key).emit('liveChange', mergeStr)
|
|
25
|
+
} else {
|
|
26
|
+
fs.writeFile(initPath, mergeStr, function (err) {
|
|
27
|
+
if (err) { return console.log(err) }
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
17
32
|
export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
18
33
|
const server = http.createServer(app)
|
|
19
34
|
const { key, live } = options
|
|
@@ -49,20 +64,7 @@ export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
|
|
|
49
64
|
io.to(key).emit('route', data, options)
|
|
50
65
|
})
|
|
51
66
|
|
|
52
|
-
socket.on('change',
|
|
53
|
-
const file = require('@symbo.ls/init/src/dynamic.json')
|
|
54
|
-
const newMerge = mergeDeep(file, changes)
|
|
55
|
-
const mergeStr = JSON.stringify(newMerge, null, 2)
|
|
56
|
-
const initPath = process.cwd() + '/node_modules/@symbo.ls/init/src/dynamic.json'
|
|
57
|
-
|
|
58
|
-
if (live) {
|
|
59
|
-
io.to(key).emit('liveChange', mergeStr)
|
|
60
|
-
} else {
|
|
61
|
-
fs.writeFile(initPath, mergeStr, function (err) {
|
|
62
|
-
if (err) { return console.log(err) }
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
})
|
|
67
|
+
socket.on('change', updateDynamycFile)
|
|
66
68
|
|
|
67
69
|
socket.on('disconnect', (changes, options) => {
|
|
68
70
|
const { clientsCount } = io.engine
|
package/README.md
DELETED
package/__client.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
import { window } from '@domql/globals'
|
|
4
|
-
import { isFunction, isArray } from '@domql/utils'
|
|
5
|
-
// import { } from 'socket.io-client/build/esm/index.js'
|
|
6
|
-
|
|
7
|
-
const ENV = process.env.NODE_ENV
|
|
8
|
-
|
|
9
|
-
const SOCKET_BACKEND_URL = window.location
|
|
10
|
-
?.host.includes('local')
|
|
11
|
-
? 'localhost:13335'
|
|
12
|
-
: 'socket.symbols.app'
|
|
13
|
-
|
|
14
|
-
let socket
|
|
15
|
-
const defautlOpts = {}
|
|
16
|
-
|
|
17
|
-
export const connect = (key, options = {}) => {
|
|
18
|
-
const socketUrls = isArray(options.socketUrl) ? options.socketUrl : [options.socketUrl || SOCKET_BACKEND_URL]
|
|
19
|
-
const primaryUrl = socketUrls[0]
|
|
20
|
-
const secondaryUrl = socketUrls[1] || 'socket.symbols.app'
|
|
21
|
-
|
|
22
|
-
socket = io(primaryUrl || SOCKET_BACKEND_URL)
|
|
23
|
-
|
|
24
|
-
socket.on('connect', () => {
|
|
25
|
-
if (ENV === 'test' || ENV === 'development') {
|
|
26
|
-
console.log(
|
|
27
|
-
`Connected to %c${primaryUrl || SOCKET_BACKEND_URL} %c${key} %c${socket.id}`,
|
|
28
|
-
'font-weight: bold; color: green;',
|
|
29
|
-
'font-weight: bold;',
|
|
30
|
-
''
|
|
31
|
-
)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
socket.emit('initConnect', options)
|
|
35
|
-
|
|
36
|
-
try {
|
|
37
|
-
if (isFunction(options.onConnect)) options.onConnect(socket.id, socket)
|
|
38
|
-
} catch (e) {
|
|
39
|
-
console.error(e)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
let tryConnect = 0
|
|
44
|
-
const tryConnectMax = 1
|
|
45
|
-
socket.on('connect_error', (err) => {
|
|
46
|
-
console.log(err)
|
|
47
|
-
console.log(`event: connect_error | reason: ${err.message}`)
|
|
48
|
-
try {
|
|
49
|
-
if (isFunction(options.onError)) options.onError(err, socket)
|
|
50
|
-
if (tryConnect === tryConnectMax) {
|
|
51
|
-
socket.disconnect()
|
|
52
|
-
|
|
53
|
-
if (primaryUrl !== secondaryUrl) {
|
|
54
|
-
if (ENV === 'test' || ENV === 'development') {
|
|
55
|
-
console.log(
|
|
56
|
-
'Could not connect to %c' + primaryUrl + '%c, reconnecting to %c' + secondaryUrl,
|
|
57
|
-
'font-weight: bold; color: red;',
|
|
58
|
-
'',
|
|
59
|
-
'font-weight: bold; color: green;'
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
connect(key, { ...options, socketUrl: secondaryUrl })
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {
|
|
67
|
-
console.error(e)
|
|
68
|
-
}
|
|
69
|
-
tryConnect++
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
socket.on('disconnect', (reason) => {
|
|
73
|
-
console.log(`event: disconnect | reason: ${reason}`)
|
|
74
|
-
try {
|
|
75
|
-
if (isFunction(options.onDisconnect)) options.onDisconnect(reason, socket)
|
|
76
|
-
} catch (e) {
|
|
77
|
-
console.error(e)
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
socket.onAny((event, ...args) => {
|
|
82
|
-
if (event === 'connect') return
|
|
83
|
-
|
|
84
|
-
try {
|
|
85
|
-
if (isFunction(options.onChange)) options.onChange(event, args[0], socket)
|
|
86
|
-
} catch (e) {
|
|
87
|
-
console.error(e)
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export const send = (event = 'change', changes, options) => {
|
|
93
|
-
socket.emit(event, changes, { ...options, ...defautlOpts })
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const disconnect = () => {
|
|
97
|
-
socket.disconnect()
|
|
98
|
-
}
|