김대연

Connect with Papago API and make testView

1 +const config = require('../config/config')
2 +const request = require('request');
3 +
4 +const PAPAGO_URL = 'https://openapi.naver.com/v1/papago/n2mt'
5 +const dPAPAGO_URL = 'https://openapi.naver.com/v1/papago/detectLangs'
6 +const PAPAGO_ID = process.env.PAPAGO_ID
7 +const PAPAGO_SECRET = process.env.PAPAGO_SECRET
8 +
9 +exports.trans = (message, lang, io, room) => {
10 + request.post(
11 + {
12 + url: PAPAGO_URL,
13 + headers: {
14 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
15 + 'X-Naver-Client-Id': `${PAPAGO_ID}`,
16 + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
17 + },
18 + body: `source=${lang}&target=ko&text=` + message,
19 + json:true
20 + },(error, response, body) => {
21 + if(!error && response.statusCode == 200) {
22 + var Translated = body.message.result.translatedText;
23 + io.to(room).emit('chat message', "trans", Translated);
24 + }
25 + });
26 +}
27 +
28 +
29 +exports.detect = (message,io,room) => {
30 + request.post(
31 + {
32 + url: dPAPAGO_URL,
33 + headers: {
34 + 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
35 + 'X-Naver-Client-Id': `${PAPAGO_ID}`,
36 + 'X-Naver-Client-Secret': `${PAPAGO_SECRET}`
37 + },
38 + body: `query=` + message,
39 + json:true
40 + },(error, response, body) => {
41 + if(!error && response.statusCode == 200) {
42 + var lang = body.langCode;
43 + if(lang != 'ko'){
44 + this.trans(message,lang,io,room)
45 + }
46 + }
47 + });
48 +}
...@@ -98,16 +98,81 @@ ...@@ -98,16 +98,81 @@
98 "negotiator": "0.6.2" 98 "negotiator": "0.6.2"
99 } 99 }
100 }, 100 },
101 + "ajv": {
102 + "version": "6.12.6",
103 + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
104 + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
105 + "requires": {
106 + "fast-deep-equal": "^3.1.1",
107 + "fast-json-stable-stringify": "^2.0.0",
108 + "json-schema-traverse": "^0.4.1",
109 + "uri-js": "^4.2.2"
110 + }
111 + },
112 + "ansi-styles": {
113 + "version": "3.2.1",
114 + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
115 + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
116 + "requires": {
117 + "color-convert": "^1.9.0"
118 + }
119 + },
101 "array-flatten": { 120 "array-flatten": {
102 "version": "1.1.1", 121 "version": "1.1.1",
103 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", 122 "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
104 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" 123 "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
105 }, 124 },
125 + "asn1": {
126 + "version": "0.2.4",
127 + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
128 + "integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
129 + "requires": {
130 + "safer-buffer": "~2.1.0"
131 + }
132 + },
133 + "assert-plus": {
134 + "version": "1.0.0",
135 + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
136 + "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
137 + },
138 + "async": {
139 + "version": "0.9.2",
140 + "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
141 + "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
142 + },
143 + "asynckit": {
144 + "version": "0.4.0",
145 + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
146 + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
147 + },
148 + "aws-sign2": {
149 + "version": "0.7.0",
150 + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
151 + "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg="
152 + },
153 + "aws4": {
154 + "version": "1.11.0",
155 + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz",
156 + "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA=="
157 + },
158 + "balanced-match": {
159 + "version": "1.0.0",
160 + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
161 + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
162 + },
106 "base64id": { 163 "base64id": {
107 "version": "2.0.0", 164 "version": "2.0.0",
108 "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", 165 "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
109 "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==" 166 "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog=="
110 }, 167 },
168 + "bcrypt-pbkdf": {
169 + "version": "1.0.2",
170 + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
171 + "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
172 + "requires": {
173 + "tweetnacl": "^0.14.3"
174 + }
175 + },
111 "body-parser": { 176 "body-parser": {
112 "version": "1.19.0", 177 "version": "1.19.0",
113 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", 178 "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
...@@ -125,16 +190,66 @@ ...@@ -125,16 +190,66 @@
125 "type-is": "~1.6.17" 190 "type-is": "~1.6.17"
126 } 191 }
127 }, 192 },
193 + "brace-expansion": {
194 + "version": "1.1.11",
195 + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
196 + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
197 + "requires": {
198 + "balanced-match": "^1.0.0",
199 + "concat-map": "0.0.1"
200 + }
201 + },
128 "bytes": { 202 "bytes": {
129 "version": "3.1.0", 203 "version": "3.1.0",
130 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", 204 "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
131 "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" 205 "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
132 }, 206 },
207 + "caseless": {
208 + "version": "0.12.0",
209 + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
210 + "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
211 + },
212 + "chalk": {
213 + "version": "2.4.2",
214 + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
215 + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
216 + "requires": {
217 + "ansi-styles": "^3.2.1",
218 + "escape-string-regexp": "^1.0.5",
219 + "supports-color": "^5.3.0"
220 + }
221 + },
222 + "color-convert": {
223 + "version": "1.9.3",
224 + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
225 + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
226 + "requires": {
227 + "color-name": "1.1.3"
228 + }
229 + },
230 + "color-name": {
231 + "version": "1.1.3",
232 + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
233 + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
234 + },
235 + "combined-stream": {
236 + "version": "1.0.8",
237 + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
238 + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
239 + "requires": {
240 + "delayed-stream": "~1.0.0"
241 + }
242 + },
133 "component-emitter": { 243 "component-emitter": {
134 "version": "1.3.0", 244 "version": "1.3.0",
135 "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", 245 "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz",
136 "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" 246 "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg=="
137 }, 247 },
248 + "concat-map": {
249 + "version": "0.0.1",
250 + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
251 + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
252 + },
138 "content-disposition": { 253 "content-disposition": {
139 "version": "0.5.3", 254 "version": "0.5.3",
140 "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz", 255 "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
...@@ -158,6 +273,11 @@ ...@@ -158,6 +273,11 @@
158 "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", 273 "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
159 "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" 274 "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
160 }, 275 },
276 + "core-util-is": {
277 + "version": "1.0.2",
278 + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
279 + "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
280 + },
161 "cors": { 281 "cors": {
162 "version": "2.8.5", 282 "version": "2.8.5",
163 "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", 283 "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
...@@ -167,6 +287,14 @@ ...@@ -167,6 +287,14 @@
167 "vary": "^1" 287 "vary": "^1"
168 } 288 }
169 }, 289 },
290 + "dashdash": {
291 + "version": "1.14.1",
292 + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
293 + "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=",
294 + "requires": {
295 + "assert-plus": "^1.0.0"
296 + }
297 + },
170 "debug": { 298 "debug": {
171 "version": "2.6.9", 299 "version": "2.6.9",
172 "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", 300 "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
...@@ -175,6 +303,11 @@ ...@@ -175,6 +303,11 @@
175 "ms": "2.0.0" 303 "ms": "2.0.0"
176 } 304 }
177 }, 305 },
306 + "delayed-stream": {
307 + "version": "1.0.0",
308 + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
309 + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
310 + },
178 "depd": { 311 "depd": {
179 "version": "1.1.2", 312 "version": "1.1.2",
180 "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", 313 "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
...@@ -190,11 +323,28 @@ ...@@ -190,11 +323,28 @@
190 "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz", 323 "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz",
191 "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==" 324 "integrity": "sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw=="
192 }, 325 },
326 + "ecc-jsbn": {
327 + "version": "0.1.2",
328 + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
329 + "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=",
330 + "requires": {
331 + "jsbn": "~0.1.0",
332 + "safer-buffer": "^2.1.0"
333 + }
334 + },
193 "ee-first": { 335 "ee-first": {
194 "version": "1.1.1", 336 "version": "1.1.1",
195 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", 337 "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
196 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" 338 "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
197 }, 339 },
340 + "ejs": {
341 + "version": "3.1.5",
342 + "resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.5.tgz",
343 + "integrity": "sha512-dldq3ZfFtgVTJMLjOe+/3sROTzALlL9E34V4/sDtUd/KlBSS0s6U1/+WPE1B4sj9CXHJpL1M6rhNJnc9Wbal9w==",
344 + "requires": {
345 + "jake": "^10.6.1"
346 + }
347 + },
198 "encodeurl": { 348 "encodeurl": {
199 "version": "1.0.2", 349 "version": "1.0.2",
200 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", 350 "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
...@@ -244,6 +394,11 @@ ...@@ -244,6 +394,11 @@
244 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", 394 "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
245 "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" 395 "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
246 }, 396 },
397 + "escape-string-regexp": {
398 + "version": "1.0.5",
399 + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
400 + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
401 + },
247 "etag": { 402 "etag": {
248 "version": "1.8.1", 403 "version": "1.8.1",
249 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", 404 "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
...@@ -286,6 +441,34 @@ ...@@ -286,6 +441,34 @@
286 "vary": "~1.1.2" 441 "vary": "~1.1.2"
287 } 442 }
288 }, 443 },
444 + "extend": {
445 + "version": "3.0.2",
446 + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
447 + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
448 + },
449 + "extsprintf": {
450 + "version": "1.3.0",
451 + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
452 + "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU="
453 + },
454 + "fast-deep-equal": {
455 + "version": "3.1.3",
456 + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
457 + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
458 + },
459 + "fast-json-stable-stringify": {
460 + "version": "2.1.0",
461 + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
462 + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
463 + },
464 + "filelist": {
465 + "version": "1.0.1",
466 + "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz",
467 + "integrity": "sha512-8zSK6Nu0DQIC08mUC46sWGXi+q3GGpKydAG36k+JDba6VRpkevvOWUW5a/PhShij4+vHT9M+ghgG7eM+a9JDUQ==",
468 + "requires": {
469 + "minimatch": "^3.0.4"
470 + }
471 + },
289 "finalhandler": { 472 "finalhandler": {
290 "version": "1.1.2", 473 "version": "1.1.2",
291 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", 474 "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
...@@ -300,6 +483,21 @@ ...@@ -300,6 +483,21 @@
300 "unpipe": "~1.0.0" 483 "unpipe": "~1.0.0"
301 } 484 }
302 }, 485 },
486 + "forever-agent": {
487 + "version": "0.6.1",
488 + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
489 + "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
490 + },
491 + "form-data": {
492 + "version": "2.3.3",
493 + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
494 + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
495 + "requires": {
496 + "asynckit": "^0.4.0",
497 + "combined-stream": "^1.0.6",
498 + "mime-types": "^2.1.12"
499 + }
500 + },
303 "forwarded": { 501 "forwarded": {
304 "version": "0.1.2", 502 "version": "0.1.2",
305 "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 503 "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
...@@ -310,6 +508,33 @@ ...@@ -310,6 +508,33 @@
310 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", 508 "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
311 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" 509 "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
312 }, 510 },
511 + "getpass": {
512 + "version": "0.1.7",
513 + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
514 + "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=",
515 + "requires": {
516 + "assert-plus": "^1.0.0"
517 + }
518 + },
519 + "har-schema": {
520 + "version": "2.0.0",
521 + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
522 + "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI="
523 + },
524 + "har-validator": {
525 + "version": "5.1.5",
526 + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz",
527 + "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==",
528 + "requires": {
529 + "ajv": "^6.12.3",
530 + "har-schema": "^2.0.0"
531 + }
532 + },
533 + "has-flag": {
534 + "version": "3.0.0",
535 + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
536 + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
537 + },
313 "http-errors": { 538 "http-errors": {
314 "version": "1.7.2", 539 "version": "1.7.2",
315 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz", 540 "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
...@@ -322,6 +547,16 @@ ...@@ -322,6 +547,16 @@
322 "toidentifier": "1.0.0" 547 "toidentifier": "1.0.0"
323 } 548 }
324 }, 549 },
550 + "http-signature": {
551 + "version": "1.2.0",
552 + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
553 + "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=",
554 + "requires": {
555 + "assert-plus": "^1.0.0",
556 + "jsprim": "^1.2.2",
557 + "sshpk": "^1.7.0"
558 + }
559 + },
325 "iconv-lite": { 560 "iconv-lite": {
326 "version": "0.4.24", 561 "version": "0.4.24",
327 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", 562 "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
...@@ -340,6 +575,58 @@ ...@@ -340,6 +575,58 @@
340 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 575 "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz",
341 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" 576 "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="
342 }, 577 },
578 + "is-typedarray": {
579 + "version": "1.0.0",
580 + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
581 + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
582 + },
583 + "isstream": {
584 + "version": "0.1.2",
585 + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
586 + "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
587 + },
588 + "jake": {
589 + "version": "10.8.2",
590 + "resolved": "https://registry.npmjs.org/jake/-/jake-10.8.2.tgz",
591 + "integrity": "sha512-eLpKyrfG3mzvGE2Du8VoPbeSkRry093+tyNjdYaBbJS9v17knImYGNXQCUV0gLxQtF82m3E8iRb/wdSQZLoq7A==",
592 + "requires": {
593 + "async": "0.9.x",
594 + "chalk": "^2.4.2",
595 + "filelist": "^1.0.1",
596 + "minimatch": "^3.0.4"
597 + }
598 + },
599 + "jsbn": {
600 + "version": "0.1.1",
601 + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
602 + "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM="
603 + },
604 + "json-schema": {
605 + "version": "0.2.3",
606 + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
607 + "integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM="
608 + },
609 + "json-schema-traverse": {
610 + "version": "0.4.1",
611 + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
612 + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
613 + },
614 + "json-stringify-safe": {
615 + "version": "5.0.1",
616 + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
617 + "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
618 + },
619 + "jsprim": {
620 + "version": "1.4.1",
621 + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
622 + "integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",
623 + "requires": {
624 + "assert-plus": "1.0.0",
625 + "extsprintf": "1.3.0",
626 + "json-schema": "0.2.3",
627 + "verror": "1.10.0"
628 + }
629 + },
343 "media-typer": { 630 "media-typer": {
344 "version": "0.3.0", 631 "version": "0.3.0",
345 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 632 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
...@@ -373,6 +660,14 @@ ...@@ -373,6 +660,14 @@
373 "mime-db": "1.44.0" 660 "mime-db": "1.44.0"
374 } 661 }
375 }, 662 },
663 + "minimatch": {
664 + "version": "3.0.4",
665 + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
666 + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
667 + "requires": {
668 + "brace-expansion": "^1.1.7"
669 + }
670 + },
376 "ms": { 671 "ms": {
377 "version": "2.0.0", 672 "version": "2.0.0",
378 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 673 "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
...@@ -383,6 +678,11 @@ ...@@ -383,6 +678,11 @@
383 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz", 678 "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
384 "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==" 679 "integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
385 }, 680 },
681 + "oauth-sign": {
682 + "version": "0.9.0",
683 + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
684 + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
685 + },
386 "object-assign": { 686 "object-assign": {
387 "version": "4.1.1", 687 "version": "4.1.1",
388 "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 688 "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
...@@ -406,6 +706,11 @@ ...@@ -406,6 +706,11 @@
406 "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", 706 "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
407 "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" 707 "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
408 }, 708 },
709 + "performance-now": {
710 + "version": "2.1.0",
711 + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
712 + "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
713 + },
409 "proxy-addr": { 714 "proxy-addr": {
410 "version": "2.0.6", 715 "version": "2.0.6",
411 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", 716 "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz",
...@@ -415,6 +720,16 @@ ...@@ -415,6 +720,16 @@
415 "ipaddr.js": "1.9.1" 720 "ipaddr.js": "1.9.1"
416 } 721 }
417 }, 722 },
723 + "psl": {
724 + "version": "1.8.0",
725 + "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
726 + "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
727 + },
728 + "punycode": {
729 + "version": "2.1.1",
730 + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
731 + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
732 + },
418 "qs": { 733 "qs": {
419 "version": "6.7.0", 734 "version": "6.7.0",
420 "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz", 735 "resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
...@@ -436,6 +751,40 @@ ...@@ -436,6 +751,40 @@
436 "unpipe": "1.0.0" 751 "unpipe": "1.0.0"
437 } 752 }
438 }, 753 },
754 + "request": {
755 + "version": "2.88.2",
756 + "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
757 + "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==",
758 + "requires": {
759 + "aws-sign2": "~0.7.0",
760 + "aws4": "^1.8.0",
761 + "caseless": "~0.12.0",
762 + "combined-stream": "~1.0.6",
763 + "extend": "~3.0.2",
764 + "forever-agent": "~0.6.1",
765 + "form-data": "~2.3.2",
766 + "har-validator": "~5.1.3",
767 + "http-signature": "~1.2.0",
768 + "is-typedarray": "~1.0.0",
769 + "isstream": "~0.1.2",
770 + "json-stringify-safe": "~5.0.1",
771 + "mime-types": "~2.1.19",
772 + "oauth-sign": "~0.9.0",
773 + "performance-now": "^2.1.0",
774 + "qs": "~6.5.2",
775 + "safe-buffer": "^5.1.2",
776 + "tough-cookie": "~2.5.0",
777 + "tunnel-agent": "^0.6.0",
778 + "uuid": "^3.3.2"
779 + },
780 + "dependencies": {
781 + "qs": {
782 + "version": "6.5.2",
783 + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
784 + "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
785 + }
786 + }
787 + },
439 "safe-buffer": { 788 "safe-buffer": {
440 "version": "5.1.2", 789 "version": "5.1.2",
441 "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 790 "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
...@@ -550,16 +899,62 @@ ...@@ -550,16 +899,62 @@
550 } 899 }
551 } 900 }
552 }, 901 },
902 + "sshpk": {
903 + "version": "1.16.1",
904 + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
905 + "integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==",
906 + "requires": {
907 + "asn1": "~0.2.3",
908 + "assert-plus": "^1.0.0",
909 + "bcrypt-pbkdf": "^1.0.0",
910 + "dashdash": "^1.12.0",
911 + "ecc-jsbn": "~0.1.1",
912 + "getpass": "^0.1.1",
913 + "jsbn": "~0.1.0",
914 + "safer-buffer": "^2.0.2",
915 + "tweetnacl": "~0.14.0"
916 + }
917 + },
553 "statuses": { 918 "statuses": {
554 "version": "1.5.0", 919 "version": "1.5.0",
555 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", 920 "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
556 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" 921 "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
557 }, 922 },
923 + "supports-color": {
924 + "version": "5.5.0",
925 + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
926 + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
927 + "requires": {
928 + "has-flag": "^3.0.0"
929 + }
930 + },
558 "toidentifier": { 931 "toidentifier": {
559 "version": "1.0.0", 932 "version": "1.0.0",
560 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz", 933 "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
561 "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==" 934 "integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
562 }, 935 },
936 + "tough-cookie": {
937 + "version": "2.5.0",
938 + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
939 + "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
940 + "requires": {
941 + "psl": "^1.1.28",
942 + "punycode": "^2.1.1"
943 + }
944 + },
945 + "tunnel-agent": {
946 + "version": "0.6.0",
947 + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
948 + "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=",
949 + "requires": {
950 + "safe-buffer": "^5.0.1"
951 + }
952 + },
953 + "tweetnacl": {
954 + "version": "0.14.5",
955 + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
956 + "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
957 + },
563 "type-is": { 958 "type-is": {
564 "version": "1.6.18", 959 "version": "1.6.18",
565 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", 960 "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
...@@ -574,16 +969,39 @@ ...@@ -574,16 +969,39 @@
574 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", 969 "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
575 "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" 970 "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
576 }, 971 },
972 + "uri-js": {
973 + "version": "4.4.0",
974 + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
975 + "integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
976 + "requires": {
977 + "punycode": "^2.1.0"
978 + }
979 + },
577 "utils-merge": { 980 "utils-merge": {
578 "version": "1.0.1", 981 "version": "1.0.1",
579 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", 982 "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
580 "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" 983 "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
581 }, 984 },
985 + "uuid": {
986 + "version": "3.4.0",
987 + "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",
988 + "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A=="
989 + },
582 "vary": { 990 "vary": {
583 "version": "1.1.2", 991 "version": "1.1.2",
584 "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", 992 "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
585 "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" 993 "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
586 }, 994 },
995 + "verror": {
996 + "version": "1.10.0",
997 + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
998 + "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=",
999 + "requires": {
1000 + "assert-plus": "^1.0.0",
1001 + "core-util-is": "1.0.2",
1002 + "extsprintf": "^1.2.0"
1003 + }
1004 + },
587 "ws": { 1005 "ws": {
588 "version": "7.4.0", 1006 "version": "7.4.0",
589 "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz", 1007 "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.0.tgz",
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
10 "license": "ISC", 10 "license": "ISC",
11 "dependencies": { 11 "dependencies": {
12 "dotenv": "^8.2.0", 12 "dotenv": "^8.2.0",
13 + "ejs": "^3.1.5",
13 "express": "^4.17.1", 14 "express": "^4.17.1",
15 + "request": "^2.88.2",
14 "socket.io": "^3.0.3" 16 "socket.io": "^3.0.3"
15 } 17 }
16 } 18 }
......
1 -const config = require(__dirname + '/config/config')
2 -
3 -const express = require('express');
4 -const app = express();
5 -const server = require('http').Server(app);
6 -const io = require('socket.io')(server);
7 -const port = process.env.SOCKET_PORT;
8 -
9 -server.listen(port, () => { console.log(`Listening on port ${port}`) });
10 -
11 -io.on('connection', socket => {
12 - console.log("connected socketID : ", socket.id);
13 - io.to(socket.id).emit('my socket id',{socketId: socket.id});
14 -
15 - socket.on('enter chatroom', () => {
16 - console.log("channel에 입장");
17 - socket.broadcast.emit('receive chat', {type: "alert", chat: "누군가가 입장하였습니다.", regDate: Date.now()});
18 - })
19 -
20 - socket.on('send voice', data => {
21 - console.log(`${socket.id} : ${data.chat}`);
22 - io.emit('send voice', data);
23 - })
24 -
25 - socket.on('leave chatroom', data => {
26 - console.log('leave chatroom ', data);
27 - socket.broadcast.emit('receive chat', {type: "alert", chat: "누군가가 퇴장하였습니다.", regDate: Date.now()});
28 - })
29 -
30 -})
...\ No newline at end of file ...\ No newline at end of file
1 +const config = require('./config/config')
2 +
3 +const app = require('express')();
4 +const http = require('http').Server(app);
5 +const io = require('socket.io')(http);
6 +const papago = require('./openAPIs/papago_api')
7 +
8 +app.set('view engine', 'ejs');
9 +app.set('views', './views');
10 +
11 +let room = ['streamer1', 'streamer2'];
12 +let a = 0;
13 +
14 +app.get('/', (req, res) => {
15 + res.render('chat');
16 +});
17 +
18 +app.get('/list',(req,res) => {
19 + res.send(room);
20 +})
21 +
22 +app.post('/add',(req,res)=>{
23 + room.append(req.body.streamer);
24 + res.send(req.body.streamer);
25 +})
26 +
27 +
28 +io.on('connection', (socket) => {
29 + socket.on('disconnect', () => {
30 + console.log('user disconnected');
31 + });
32 +
33 + socket.on('leaveRoom', (num,name) => {
34 + socket.leave(room[num], () => {
35 + console.log('Someone leave a ' + room[num]);
36 + io.to(room[num]).emit('leaveRoom', num ,name);
37 + });
38 + });
39 +
40 + socket.on('joinRoom', (num,name) => {
41 + socket.join(room[num], () => {
42 + console.log('Someone join a ' + room[num]);
43 + io.to(room[num]).emit('joinRoom', num ,name);
44 + });
45 + });
46 +
47 + socket.on('chat message', (num,name, msg) => {
48 + papago.detect(msg,io,room[num]);
49 + io.to(room[a]).emit('chat message', name, msg);
50 + });
51 +});
52 +
53 +
54 +http.listen(process.env.SOCKET_PORT, () => {
55 + console.log(`Connect at ${process.env.SOCKET_PORT}`);
56 +});
...\ No newline at end of file ...\ No newline at end of file
......
1 -<script src="/socket.io/socket.io.js"></script>
2 -<script>
3 - var socket = io();
4 -</script>
5 -<h1>Socket Chat</h1>
...\ No newline at end of file ...\ No newline at end of file
1 +<html>
2 +<head>
3 + <style>
4 + * {
5 + margin: 0;
6 + padding: 0;
7 + box-sizing: border-box;
8 + }
9 +
10 + body {
11 + font: 13px Helvetica, Arial;
12 + }
13 +
14 + form {
15 + background: #000;
16 + padding: 3px;
17 + position: fixed;
18 + bottom: 0;
19 + width: 100%;
20 + }
21 +
22 + form input {
23 + border: 0;
24 + padding: 10px;
25 + width: 90%;
26 + margin-right: .5%;
27 + }
28 +
29 + form button {
30 + width: 9%;
31 + background: rgb(130, 224, 255);
32 + border: none;
33 + padding: 10px;
34 + }
35 +
36 + #messages {
37 + list-style-type: none;
38 + margin: 0;
39 + padding: 0;
40 + }
41 +
42 + #messages li {
43 + padding: 5px 10px;
44 + }
45 +
46 + #messages li:nth-child(odd) {
47 + background: #eee;
48 + }
49 + </style>
50 +</head>
51 +<body>
52 +<select>
53 + <option value="streamer1">streamer1</option>
54 + <option value="streamer2">streamer2</option>
55 +</select>
56 +<ul id="messages"></ul>
57 +<form action="">
58 + <input id="m" autocomplete="off"/>
59 + <button>Send</button>
60 +</form>
61 +<script src="/socket.io/socket.io.js"></script>
62 +<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
63 +<script>
64 + $(() => {
65 + const name = prompt('What your name');
66 + const socket = io();
67 + let room = ['streamer1', 'streamer2'];
68 + let num = 0;
69 +
70 + socket.emit('joinRoom', num, name);
71 +
72 + $('select').change(() => {
73 + socket.emit('leaveRoom', num, name);
74 + num++;
75 + num = num % 2;
76 + socket.emit('joinRoom', num, name);
77 + });
78 +
79 +
80 + $('form').submit(() => {
81 + socket.emit('chat message', num, name, $('#m').val());
82 + $('#m').val('');
83 + return false;
84 + });
85 +
86 + socket.on('chat message', (name, msg) => {
87 + $('#messages').append($('<li>').text(name + ' : ' +
88 + msg));
89 + });
90 +
91 + socket.on('leaveRoom', (num, name) => {
92 + $('#messages').append($('<li>').text(name + ' leaved '
93 + + room[num] + ' :('));
94 + });
95 +
96 + socket.on('joinRoom', (num, name) => {
97 + $('#messages').append($('<li>').text(name + ' joined '
98 + + room[num] + ':)'));
99 + });
100 + });
101 +</script>
102 +</body>
103 +</html>
...\ No newline at end of file ...\ No newline at end of file