@cocreate/socket-server 1.10.4 → 1.11.0

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.
@@ -53,3 +53,7 @@ jobs:
53
53
  node-version: 16
54
54
  - name: update documentation
55
55
  uses: CoCreate-app/CoCreate-docs@master
56
+ env:
57
+ organization_id: ${{ secrets.COCREATE_ORGANIZATION_ID }}
58
+ key: ${{ secrets.COCREATE_KEY }}
59
+ host: ${{ secrets.COCREATE_HOST }}
package/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ # [1.11.0](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.10.4...v1.11.0) (2023-06-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Refactor CoCreate.config.js to remove hard-coded credentials ([4c1033a](https://github.com/CoCreate-app/CoCreate-socket-server/commit/4c1033ae66aa16993f3821ee7248394e8aecab1c))
7
+ * workflow ([9594513](https://github.com/CoCreate-app/CoCreate-socket-server/commit/95945133a54d71ee0eb17ffa27ac938795fecc69))
8
+
9
+
10
+ ### Features
11
+
12
+ * Refactor WebSocket server constructor and handleUpgrade method ([0caa836](https://github.com/CoCreate-app/CoCreate-socket-server/commit/0caa83606fcb1482b9fd14c5677e32edfc54f4e0))
13
+
1
14
  ## [1.10.4](https://github.com/CoCreate-app/CoCreate-socket-server/compare/v1.10.3...v1.10.4) (2023-06-04)
2
15
 
3
16
 
@@ -1,8 +1,8 @@
1
1
  module.exports = {
2
2
  "config": {
3
- "organization_id": "5ff747727005da1c272740ab",
4
- "key": "2061acef-0451-4545-f754-60cf8160",
5
- "host": "general.cocreate.app"
3
+ "organization_id": "",
4
+ "key": "",
5
+ "host": ""
6
6
  },
7
7
  "sources": [
8
8
  {
package/demo/server.js CHANGED
@@ -1,19 +1,24 @@
1
+ 'use strict';
1
2
  const express = require('express');
2
- const { createServer } = require('http');
3
-
4
- const SocketServer = require("../src/index")
5
-
6
- const ws_socket = new SocketServer("ws");
7
- const port = process.env.PORT || 3000;
3
+ const cors = require('cors')
4
+ const urlencoded = require('body-parser').urlencoded;
8
5
 
9
6
  const app = express();
7
+ app.use(cors())
8
+ app.use(urlencoded({ extended: false }));
10
9
 
11
- const server = createServer(app);
10
+ const socketServer = require("@cocreate/socket-server")
11
+ const wsManager = new socketServer("ws");
12
12
 
13
+ const { createServer } = require('http');
14
+ const server = createServer(app);
13
15
  server.on('upgrade', function upgrade(request, socket, head) {
14
- if (!ws_socket.handleUpgrade(request, socket, head)) {
16
+ if (!wsManager.handleUpgrade(request, socket, head)) {
15
17
  socket.destroy();
16
18
  }
17
19
  });
18
20
 
19
- server.listen(port);
21
+ const components = require("./components")
22
+ components.init(app, wsManager)
23
+
24
+ server.listen(process.env.PORT || 3000);
package/docs/index.html CHANGED
@@ -1,224 +1,224 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1" />
7
- <title>CoCreate-socket-server Documentation | CoCreateJS</title>
8
- <link
9
- rel="icon"
10
- type="image/png"
11
- sizes="32x32"
12
- href="https://cocreate.app/images/favicon.ico" />
13
- <meta
14
- name="description"
15
- content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
- <meta
17
- name="keywords"
18
- content="helper classes, utility classes, css framework, css library, inline style classes" />
19
- <meta name="robots" content="index,follow" />
20
-
21
- <!-- CoCreate CSS -->
22
- <link
23
- rel="stylesheet"
24
- href="https://cdn.cocreate.app/latest/CoCreate.min.css"
25
- type="text/css" />
26
-
27
- <link rel="manifest" href="/manifest.json" />
28
- </head>
29
-
30
- <body>
31
- <div collection="" document_id="" name="" id="cocreate-socket-server">
32
- <div
33
- class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
34
- <div class="display:flex align-items:center">
35
- <h2>CoCreate-socket-server</h2>
36
- </div>
37
- <div
38
- class="display:flex align-items:center font-size:20px"
39
- share-height="600"
40
- share-width="500"
41
- share-media="https://via.placeholder.com/300/09f/fff.png">
42
- <a
43
- href="https://github.com/CoCreate-app/CoCreate-socket-server"
44
- target="_blank"
45
- class="margin-right:15px"
46
- ><i class="fab fa-github"></i
47
- ></a>
48
- <a
49
- class="margin-right:15px share"
50
- share-network="twitter"
51
- title="Share on twitter"
52
- ><i class="fab fa-twitter"></i
53
- ></a>
54
- <a
55
- class="margin-right:15px share"
56
- share-network="facebook"
57
- title="Share on Facebook"
58
- ><i class="fab fa-facebook"></i
59
- ></a>
60
- <a
61
- class="margin-right:15px share"
62
- share-network="instagram"
63
- title="Share on instagram"
64
- ><i class="fab fa-instagram"></i
65
- ></a>
66
- <a
67
- class="margin-right:15px share"
68
- share-network="share"
69
- title="Share on share"
70
- ><i class="fas fa-share-alt"></i
71
- ></a>
72
- </div>
73
- </div>
74
- <p class="max-width:500px margin:20px_10px">
75
- A simple HTML5, CSS and pure javascript component. Easy
76
- configuration using data-attributes and highly styleable.
77
- </p>
78
- <div id="socket-server-section" class="display:flex flex-wrap:wrap">
79
- <div
80
- class="flex-grow:1 min-width:300px width:50% padding:20px_10px">
81
- <h2
82
- class="border-bottom:1px_solid_lightgrey padding:5px_0px">
83
- Install
84
- </h2>
85
- <pre
86
- class="margin-top:15px"><code class="language-javascript">npm install cocreate-socket-server</code></pre>
87
- <p class="padding:10px_0px">Or you can use cdn link:</p>
88
- <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-socket-server.min.js</code></pre>
89
-
90
- <h2
91
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
92
- Usage
93
- </h2>
94
- <p class="padding:10px_0px">socket-server usage content</p>
95
- <pre><code class="language-html">&lt;div&gt;&lt;/div&gt;</code></pre>
96
-
97
- <h2
98
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
99
- Reference
100
- </h2>
101
- <p class="padding:10px_0px">
102
- This is socket-server reference content
103
- </p>
104
- <pre><code class="language-javascript">&lt;div&gt;&lt;/div&gt;</code></pre>
105
- <p class="padding:10px_0px">
106
- This is socket-server reference content
107
- </p>
108
-
109
- <h2
110
- class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
111
- Attributes
112
- </h2>
113
- <ul class="list-style-type:none">
114
- <li
115
- class="padding:15px_0px border-bottom:1px_solid_lightgrey">
116
- <h4>
117
- <span>socket-server</span>
118
- <span class="cocreate-badge success"
119
- >string</span
120
- >
121
- <span class="cocreate-badge warning"
122
- >optional</span
123
- >
124
- </h4>
125
- <p>socket-server-attribute</p>
126
- </li>
127
- <li
128
- class="padding:15px_0px border-bottom:1px_solid_lightgrey">
129
- <h4>
130
- <span>socket-server</span>
131
- <span class="cocreate-badge success"
132
- >string</span
133
- >
134
- <span class="cocreate-badge warning"
135
- >optional</span
136
- >
137
- </h4>
138
- <p>socket-server-attribute</p>
139
- </li>
140
- </ul>
141
- </div>
142
-
143
- <div
144
- class="flex-grow:1 min-width:300px width:50% padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
145
- <!-- SandBox -->
146
- <div
147
- class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
148
- id="playground">
149
- <div
150
- id="demo-code"
151
- resizable
152
- class="position:relative height:50%">
153
- <textarea
154
- type="code"
155
- lang="html"
156
- collection="demos"
157
- document_id=""
158
- name="demo"
159
- save="false"
160
- id="demo"
161
- class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
162
- <div
163
- resize="bottom"
164
- class="background:lightgrey"></div>
165
- </div>
166
-
167
- <div
168
- id="demo-preview"
169
- class="position:relative overflow:auto background-color:white">
170
- <div get-value="#demo" class="padding:20px"></div>
171
- </div>
172
-
173
- <div
174
- class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
175
- <a
176
- class="margin-right:10px"
177
- id="eye"
178
- show="#eye-slash"
179
- hide="#eye, #demo-preview"
180
- toggle="code-height"
181
- toggle-target="#demo-code"
182
- ><i class="far fa-eye"></i
183
- ></a>
184
- <a
185
- class="margin-right:10px"
186
- hidden
187
- id="eye-slash"
188
- show="#eye, #demo-preview"
189
- hide="#eye-slash"
190
- toggle="code-height"
191
- toggle-target="#demo-code"
192
- ><i class="fas fa-eye-slash"></i
193
- ></a>
194
- <a
195
- class="margin-right:10px"
196
- id="code"
197
- show="#code-slash"
198
- hide="#code, #demo-code"
199
- ><i class="fa fa-code"></i
200
- ></a>
201
- <a
202
- class="margin-right:10px"
203
- hidden
204
- id="code-slash"
205
- show="#code, #demo-code"
206
- hide="#code-slash"
207
- ><i class="fas fa-code"></i
208
- ></a>
209
- <a
210
- class="margin-right:5px"
211
- fullscreen
212
- target="#playground"
213
- ><i class="fas fa-expand"></i
214
- ></a>
215
- </div>
216
- </div>
217
- <!-- End SandBox -->
218
- </div>
219
- </div>
220
- </div>
221
- <script src="/apikey.js"></script>
222
- <script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>
223
- </body>
224
- </html>
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <title>CoCreate-socket-server Documentation | CoCreateJS</title>
8
+ <link
9
+ rel="icon"
10
+ type="image/png"
11
+ sizes="32x32"
12
+ href="https://cocreate.app/images/favicon.ico" />
13
+ <meta
14
+ name="description"
15
+ content="A simple HTML5 and pure javascript component. Easy configuration using data-attributes and highly styleable." />
16
+ <meta
17
+ name="keywords"
18
+ content="helper classes, utility classes, css framework, css library, inline style classes" />
19
+ <meta name="robots" content="index,follow" />
20
+
21
+ <!-- CoCreate CSS -->
22
+ <link
23
+ rel="stylesheet"
24
+ href="https://cdn.cocreate.app/latest/CoCreate.min.css"
25
+ type="text/css" />
26
+
27
+ <link rel="manifest" href="/manifest.json" />
28
+ </head>
29
+
30
+ <body>
31
+ <div collection="" document_id="" name="" id="cocreate-socket-server">
32
+ <div
33
+ class="display:flex flex-wrap:wrap justify-content:space-between margin:10px">
34
+ <div class="display:flex align-items:center">
35
+ <h2>CoCreate-socket-server</h2>
36
+ </div>
37
+ <div
38
+ class="display:flex align-items:center font-size:20px"
39
+ share-height="600"
40
+ share-width="500"
41
+ share-media="https://via.placeholder.com/300/09f/fff.png">
42
+ <a
43
+ href="https://github.com/CoCreate-app/CoCreate-socket-server"
44
+ target="_blank"
45
+ class="margin-right:15px"
46
+ ><i class="fab fa-github"></i
47
+ ></a>
48
+ <a
49
+ class="margin-right:15px share"
50
+ share-network="twitter"
51
+ title="Share on twitter"
52
+ ><i class="fab fa-twitter"></i
53
+ ></a>
54
+ <a
55
+ class="margin-right:15px share"
56
+ share-network="facebook"
57
+ title="Share on Facebook"
58
+ ><i class="fab fa-facebook"></i
59
+ ></a>
60
+ <a
61
+ class="margin-right:15px share"
62
+ share-network="instagram"
63
+ title="Share on instagram"
64
+ ><i class="fab fa-instagram"></i
65
+ ></a>
66
+ <a
67
+ class="margin-right:15px share"
68
+ share-network="share"
69
+ title="Share on share"
70
+ ><i class="fas fa-share-alt"></i
71
+ ></a>
72
+ </div>
73
+ </div>
74
+ <p class="max-width:500px margin:20px_10px">
75
+ A simple HTML5, CSS and pure javascript component. Easy
76
+ configuration using data-attributes and highly styleable.
77
+ </p>
78
+ <div id="socket-server-section" class="display:flex flex-wrap:wrap">
79
+ <div
80
+ class="flex-grow:1 min-width:300px width:50% padding:20px_10px">
81
+ <h2
82
+ class="border-bottom:1px_solid_lightgrey padding:5px_0px">
83
+ Install
84
+ </h2>
85
+ <pre
86
+ class="margin-top:15px"><code class="language-javascript">npm install cocreate-socket-server</code></pre>
87
+ <p class="padding:10px_0px">Or you can use cdn link:</p>
88
+ <pre><code class="language-javascript">https://cdn.cocreate.app/js/CoCreate-socket-server.min.js</code></pre>
89
+
90
+ <h2
91
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
92
+ Usage
93
+ </h2>
94
+ <p class="padding:10px_0px">socket-server usage content</p>
95
+ <pre><code class="language-html">&lt;div&gt;&lt;/div&gt;</code></pre>
96
+
97
+ <h2
98
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
99
+ Reference
100
+ </h2>
101
+ <p class="padding:10px_0px">
102
+ This is socket-server reference content
103
+ </p>
104
+ <pre><code class="language-javascript">&lt;div&gt;&lt;/div&gt;</code></pre>
105
+ <p class="padding:10px_0px">
106
+ This is socket-server reference content
107
+ </p>
108
+
109
+ <h2
110
+ class="border-bottom:1px_solid_lightgrey margin-top:20px padding:5px_0px">
111
+ Attributes
112
+ </h2>
113
+ <ul class="list-style-type:none">
114
+ <li
115
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
116
+ <h4>
117
+ <span>socket-server</span>
118
+ <span class="cocreate-badge success"
119
+ >string</span
120
+ >
121
+ <span class="cocreate-badge warning"
122
+ >optional</span
123
+ >
124
+ </h4>
125
+ <p>socket-server-attribute</p>
126
+ </li>
127
+ <li
128
+ class="padding:15px_0px border-bottom:1px_solid_lightgrey">
129
+ <h4>
130
+ <span>socket-server</span>
131
+ <span class="cocreate-badge success"
132
+ >string</span
133
+ >
134
+ <span class="cocreate-badge warning"
135
+ >optional</span
136
+ >
137
+ </h4>
138
+ <p>socket-server-attribute</p>
139
+ </li>
140
+ </ul>
141
+ </div>
142
+
143
+ <div
144
+ class="flex-grow:1 min-width:300px width:50% padding:0px_10px margin:20px_0px border-bottom:1px_solid_lightgrey">
145
+ <!-- SandBox -->
146
+ <div
147
+ class="display:flex flex-direction:column position:relative overflow:hidden card border-radius:2px width:auto height:600px margin-top:20px"
148
+ id="playground">
149
+ <div
150
+ id="demo-code"
151
+ resizable
152
+ class="position:relative height:50%">
153
+ <textarea
154
+ type="code"
155
+ lang="html"
156
+ collection="demos"
157
+ document_id=""
158
+ name="demo"
159
+ save="false"
160
+ id="demo"
161
+ class="height:100% width:100% outline:none border:none resize:none padding:5px"></textarea>
162
+ <div
163
+ resize="bottom"
164
+ class="background:lightgrey"></div>
165
+ </div>
166
+
167
+ <div
168
+ id="demo-preview"
169
+ class="position:relative overflow:auto background-color:white">
170
+ <div get-value="#demo" class="padding:20px"></div>
171
+ </div>
172
+
173
+ <div
174
+ class="font-size:20px position:absolute top:10px right:10px opacity:0.6">
175
+ <a
176
+ class="margin-right:10px"
177
+ id="eye"
178
+ show="#eye-slash"
179
+ hide="#eye, #demo-preview"
180
+ toggle="code-height"
181
+ toggle-target="#demo-code"
182
+ ><i class="far fa-eye"></i
183
+ ></a>
184
+ <a
185
+ class="margin-right:10px"
186
+ hidden
187
+ id="eye-slash"
188
+ show="#eye, #demo-preview"
189
+ hide="#eye-slash"
190
+ toggle="code-height"
191
+ toggle-target="#demo-code"
192
+ ><i class="fas fa-eye-slash"></i
193
+ ></a>
194
+ <a
195
+ class="margin-right:10px"
196
+ id="code"
197
+ show="#code-slash"
198
+ hide="#code, #demo-code"
199
+ ><i class="fa fa-code"></i
200
+ ></a>
201
+ <a
202
+ class="margin-right:10px"
203
+ hidden
204
+ id="code-slash"
205
+ show="#code, #demo-code"
206
+ hide="#code-slash"
207
+ ><i class="fas fa-code"></i
208
+ ></a>
209
+ <a
210
+ class="margin-right:5px"
211
+ fullscreen
212
+ target="#playground"
213
+ ><i class="fas fa-expand"></i
214
+ ></a>
215
+ </div>
216
+ </div>
217
+ <!-- End SandBox -->
218
+ </div>
219
+ </div>
220
+ </div>
221
+ <script src="/apikey.js"></script>
222
+ <script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>
223
+ </body>
224
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/socket-server",
3
- "version": "1.10.4",
3
+ "version": "1.11.0",
4
4
  "description": "CoCreate-socket-server",
5
5
  "keywords": [
6
6
  "cocreate-socket",
@@ -27,7 +27,8 @@
27
27
  "scripts": {
28
28
  "demo": "PORT=5000 node demo/server.js",
29
29
  "test": "echo \"Error: no test specified\" && exit 1",
30
- "docs": "node ./node_modules/@cocreate/docs/src/index.js"
30
+ "docs": "node ./node_modules/@cocreate/docs/src/index.js",
31
+ "postinstall": "node ./node_modules/@cocreate/cli/check-coc.js"
31
32
  },
32
33
  "repository": {
33
34
  "type": "git",
@@ -39,12 +40,12 @@
39
40
  "url": "https://github.com/CoCreate-app/CoCreate-socket-server/issues"
40
41
  },
41
42
  "homepage": "https://cocreate.app/docs/CoCreate-socket-server",
42
- "dependencies": {
43
- "@cocreate/docs": "^1.7.15",
44
- "@cocreate/uuid": "^1.4.13"
45
- },
46
43
  "devDependencies": {
47
- "express": "^4.17.1",
44
+ "@cocreate/cli": "^1.29.3"
45
+ },
46
+ "dependencies": {
47
+ "@cocreate/docs": "^1.8.2",
48
+ "@cocreate/uuid": "^1.4.15",
48
49
  "ws": "7.5.9"
49
50
  }
50
51
  }
package/src/index.js CHANGED
@@ -4,11 +4,16 @@ const EventEmitter = require("events").EventEmitter;
4
4
  const uid = require('@cocreate/uuid')
5
5
 
6
6
  class SocketServer extends EventEmitter {
7
- constructor(prefix) {
7
+ constructor(server, prefix) {
8
8
  super();
9
9
  this.clients = new Map();
10
10
  this.prefix = prefix || "crud";
11
11
  this.wss = new WebSocket.Server({ noServer: true });
12
+ server.on('upgrade', (request, socket, head) => {
13
+ if (!this.handleUpgrade(request, socket, head)) {
14
+ socket.destroy();
15
+ }
16
+ });
12
17
  }
13
18
 
14
19
  handleUpgrade(req, socket, head) {