@symbo.ls/socket 2.10.20 → 2.10.25
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 +98 -0
- package/client.js +14 -17
- package/package.json +2 -2
- package/client.cjs +0 -3806
- package/client.cjs.map +0 -7
package/__client.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
}
|
package/client.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { window } from '@domql/globals'
|
|
4
3
|
import { isFunction, isArray } from '@domql/utils'
|
|
5
|
-
|
|
4
|
+
import io from 'socket.io-client'
|
|
6
5
|
|
|
7
6
|
const ENV = process.env.NODE_ENV
|
|
8
7
|
|
|
9
8
|
const SOCKET_BACKEND_URL = window.location
|
|
10
|
-
|
|
9
|
+
.host.includes('local')
|
|
11
10
|
? 'localhost:13335'
|
|
12
|
-
: 'socket.symbols.app'
|
|
11
|
+
: 'https://socket.symbols.app'
|
|
13
12
|
|
|
14
13
|
let socket
|
|
15
14
|
const defautlOpts = {}
|
|
16
15
|
|
|
17
16
|
export const connect = (key, options = {}) => {
|
|
18
|
-
const socketUrls = isArray(options.socketUrl)
|
|
17
|
+
const socketUrls = isArray(options.socketUrl)
|
|
18
|
+
? options.socketUrl : [options.socketUrl || SOCKET_BACKEND_URL]
|
|
19
19
|
const primaryUrl = socketUrls[0]
|
|
20
20
|
const secondaryUrl = socketUrls[1] || 'socket.symbols.app'
|
|
21
21
|
|
|
@@ -43,25 +43,22 @@ export const connect = (key, options = {}) => {
|
|
|
43
43
|
let tryConnect = 0
|
|
44
44
|
const tryConnectMax = 1
|
|
45
45
|
socket.on('connect_error', (err) => {
|
|
46
|
-
console.log(err)
|
|
47
46
|
console.log(`event: connect_error | reason: ${err.message}`)
|
|
48
47
|
try {
|
|
49
48
|
if (isFunction(options.onError)) options.onError(err, socket)
|
|
50
49
|
if (tryConnect === tryConnectMax) {
|
|
51
50
|
socket.disconnect()
|
|
52
51
|
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
connect(key, { ...options, socketUrl: secondaryUrl })
|
|
52
|
+
if (ENV === 'test' || ENV === 'development') {
|
|
53
|
+
console.log(
|
|
54
|
+
'Could not connect to %c' + primaryUrl + '%c, reconnecting to %c' + secondaryUrl,
|
|
55
|
+
'font-weight: bold; color: red;',
|
|
56
|
+
'',
|
|
57
|
+
'font-weight: bold; color: green;'
|
|
58
|
+
)
|
|
64
59
|
}
|
|
60
|
+
|
|
61
|
+
connect(key, { ...options, socketUrl: secondaryUrl })
|
|
65
62
|
}
|
|
66
63
|
} catch (e) {
|
|
67
64
|
console.error(e)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@symbo.ls/socket",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.25",
|
|
4
4
|
"description": "Connect your app to Symbols editor",
|
|
5
5
|
"main": "server.js",
|
|
6
6
|
"author": "symbo.ls",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"standard": {
|
|
30
30
|
"parser": "babel-eslint"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "891c18159d1045914b41f121474c6b707ac9db83"
|
|
33
33
|
}
|