@symbo.ls/socket 3.0.1 → 3.1.1

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.
Files changed (3) hide show
  1. package/client.js +14 -10
  2. package/package.json +6 -7
  3. package/server.js +8 -5
package/client.js CHANGED
@@ -1,11 +1,9 @@
1
1
  'use strict'
2
2
 
3
3
  import * as utils from '@domql/utils'
4
- import * as globals from '@domql/globals'
5
4
  import io from 'socket.io-client'
6
5
 
7
- const { isFunction, isArray } = utils.default || utils
8
- const { window } = globals.default || globals
6
+ const { window, isFunction, isArray } = utils.default || utils
9
7
  const ENV = process.env.NODE_ENV
10
8
 
11
9
  const defautlOpts = {}
@@ -13,10 +11,13 @@ const defautlOpts = {}
13
11
  let CONNECT_ATTEPT = 0
14
12
  const CONNECT_ATTEPT_MAX_ALLOWED = 1
15
13
 
16
- const getIsDev = (options) => {
17
- return options.development ||
14
+ const getIsDev = options => {
15
+ return (
16
+ options.development ||
18
17
  (window && window.location && window.location.host.includes('local')) ||
19
- (ENV === 'test' || ENV === 'development')
18
+ ENV === 'testing' ||
19
+ ENV === 'development'
20
+ )
20
21
  }
21
22
 
22
23
  const getSocketUrl = (options, isDev) => {
@@ -66,7 +67,7 @@ export const connect = (key, options = {}) => {
66
67
  }
67
68
  })
68
69
 
69
- socket.on('connect_error', (err) => {
70
+ socket.on('connect_error', err => {
70
71
  console.log(`event: connect_error | reason: ${err.message}`)
71
72
  try {
72
73
  if (isFunction(options.onError)) options.onError(err, socket)
@@ -76,9 +77,12 @@ export const connect = (key, options = {}) => {
76
77
 
77
78
  socket.disconnect()
78
79
 
79
- if (ENV === 'test' || ENV === 'development') {
80
+ if (ENV === 'testing' || ENV === 'development') {
80
81
  console.log(
81
- 'Could not connect to %c' + primaryUrl + '%c, reconnecting to %c' + secondaryUrl,
82
+ 'Could not connect to %c' +
83
+ primaryUrl +
84
+ '%c, reconnecting to %c' +
85
+ secondaryUrl,
82
86
  'font-weight: bold; color: red;',
83
87
  '',
84
88
  'font-weight: bold; color: green;'
@@ -92,7 +96,7 @@ export const connect = (key, options = {}) => {
92
96
  }
93
97
  })
94
98
 
95
- socket.on('disconnect', (reason) => {
99
+ socket.on('disconnect', reason => {
96
100
  console.log(`event: disconnect | reason: ${reason}`)
97
101
  try {
98
102
  if (isFunction(options.onDisconnect)) options.onDisconnect(reason, socket)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symbo.ls/socket",
3
- "version": "3.0.1",
3
+ "version": "3.1.1",
4
4
  "description": "Connect your app to Symbols editor",
5
5
  "main": "server.js",
6
6
  "author": "symbo.ls",
@@ -10,15 +10,14 @@
10
10
  "start": "nodemon server.js"
11
11
  },
12
12
  "dependencies": {
13
- "@domql/globals": "latest",
14
- "@domql/utils": "^2.5.0",
15
- "@symbo.ls/init": "^3.0.1",
16
- "chalk": "^5.0.0",
17
- "express": "^4.18.1",
13
+ "@domql/utils": "^3.1.1",
14
+ "@symbo.ls/init": "^3.1.1",
15
+ "chalk": "^5.4.1",
16
+ "express": "^4.21.2",
18
17
  "http": "^0.0.1-security",
19
18
  "merge-deep": "^3.0.3",
20
19
  "socket.io": "^4.5.2",
21
20
  "socket.io-client": "^4.5.2"
22
21
  },
23
- "gitHead": "a4e7f586f7e4f60bd7b6a8388bdacc3ae1879433"
22
+ "gitHead": "39fb7a8c07355468ccce79e2f787ca3fa0715692"
24
23
  }
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 } = (utils.default || utils)
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('Use --verbose to debug the error or open the issue at https://github.com/symbo-ls/smbls')
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
@@ -29,7 +31,8 @@ export const updateDynamycFile = (changes, options = {}) => {
29
31
 
30
32
  console.log(chalk.dim('Received update:'))
31
33
  console.log(Object.keys(changes).join(', '))
32
- if (verboseCode) console.log(chalk.dim(JSON.stringify(changes, null, prettify ?? 2)))
34
+ if (verboseCode)
35
+ console.log(chalk.dim(JSON.stringify(changes, null, prettify ?? 2)))
33
36
 
34
37
  try {
35
38
  fs.writeFileSync(initPath, mergeStr)
@@ -59,11 +62,11 @@ export const sync = (desSysFile = DES_SYS_DEFAULT_FILE, options = {}) => {
59
62
  res.end('open')
60
63
  })
61
64
 
62
- io.on('connection', (socket) => {
65
+ io.on('connection', socket => {
63
66
  socket.join(key)
64
67
  let source
65
68
 
66
- socket.on('initConnect', (options) => {
69
+ socket.on('initConnect', options => {
67
70
  const { clientsCount } = io.engine
68
71
  socket.to(key).emit('clientsCount', clientsCount)
69
72
  source = options.source