iosignal 3.0.0 → 3.1.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.
- package/README.ko.md +566 -0
- package/README.md +561 -2
- package/dist/io.d.ts +481 -0
- package/dist/io.js +3 -3
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +3 -3
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +558 -104
- package/dist/types/client/IOCore.d.ts +408 -0
- package/dist/types/client/browser/IOWebSocket.d.ts +75 -0
- package/dist/types/common/constants.d.ts +169 -0
- package/dist/types/common/payload.d.ts +6 -0
- package/dist/types/common/quotaTable.d.ts +47 -0
- package/examples/react-chat-js/dist/assets/index-Cy4qaVcJ.js +56 -0
- package/examples/react-chat-js/dist/assets/index-NETrjYhz.css +1 -0
- package/examples/react-chat-js/dist/index.html +14 -0
- package/examples/react-chat-js/index.html +13 -0
- package/examples/react-chat-js/package-lock.json +1723 -0
- package/examples/react-chat-js/package.json +20 -0
- package/examples/react-chat-js/src/App.css +61 -0
- package/examples/react-chat-js/src/App.jsx +125 -0
- package/examples/react-chat-js/src/index.css +13 -0
- package/examples/react-chat-js/src/main.jsx +13 -0
- package/examples/react-chat-js/src/shared_io.js +12 -0
- package/examples/react-chat-js/vite.config.js +7 -0
- package/examples/server/index.js +12 -0
- package/examples/server/package-lock.json +47 -0
- package/examples/server/package.json +12 -0
- package/examples/svelte-chat-js/.devtools +3 -0
- package/examples/svelte-chat-js/README.md +38 -0
- package/examples/svelte-chat-js/package-lock.json +1505 -0
- package/examples/svelte-chat-js/package.json +22 -0
- package/examples/svelte-chat-js/src/app.css +105 -0
- package/examples/svelte-chat-js/src/app.d.ts +13 -0
- package/examples/svelte-chat-js/src/app.html +12 -0
- package/examples/svelte-chat-js/src/lib/images/github.svg +1 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-logo.svg +1 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.png +0 -0
- package/examples/svelte-chat-js/src/lib/images/svelte-welcome.webp +0 -0
- package/examples/svelte-chat-js/src/lib/shared_io.js +12 -0
- package/examples/svelte-chat-js/src/routes/+layout.svelte +9 -0
- package/examples/svelte-chat-js/src/routes/+page.js +3 -0
- package/examples/svelte-chat-js/src/routes/+page.svelte +162 -0
- package/examples/svelte-chat-js/static/favicon.svg +1 -0
- package/examples/svelte-chat-js/static/global.css +19 -0
- package/examples/svelte-chat-js/static/robots.txt +3 -0
- package/examples/svelte-chat-js/svelte.config.js +15 -0
- package/examples/svelte-chat-js/vite.config.js +6 -0
- package/package.json +9 -3
- package/rollup.config.js +11 -4
- package/src/client/IOCongSocket.js +20 -9
- package/src/client/IOCore.js +437 -79
- package/src/client/IOWS.js +12 -15
- package/src/client/browser/IOWebSocket.js +101 -17
- package/src/common/constants.js +91 -1
- package/tsconfig.json +24 -0
- package/docs/README.kr.md +0 -230
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-chat-js",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"iosignal": "file:../..",
|
|
13
|
+
"react": "^19.1.1",
|
|
14
|
+
"react-dom": "^19.1.1"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@vitejs/plugin-react": "^5.0.1",
|
|
18
|
+
"vite": "^7.1.3"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
html, body, #root, .App {
|
|
2
|
+
height: 100%;
|
|
3
|
+
margin: 0;
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.App {
|
|
9
|
+
padding: 20px;
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
h1 {
|
|
14
|
+
margin-top: 0;
|
|
15
|
+
color: #333;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.messages {
|
|
19
|
+
flex-grow: 1; /* 남은 공간을 모두 차지하도록 설정 */
|
|
20
|
+
border: 1px solid #ccc;
|
|
21
|
+
padding: 10px;
|
|
22
|
+
overflow-y: auto; /* 내용이 넘치면 스크롤바 표시 */
|
|
23
|
+
margin-bottom: 10px;
|
|
24
|
+
display: flex;
|
|
25
|
+
flex-direction: column; /* 메시지를 아래에서 위로 쌓이도록 */
|
|
26
|
+
justify-content: flex-end; /* 메시지를 아래로 정렬 */
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.messages div {
|
|
30
|
+
background-color: #f0f0f0;
|
|
31
|
+
padding: 8px;
|
|
32
|
+
margin-bottom: 5px;
|
|
33
|
+
border-radius: 5px;
|
|
34
|
+
text-align: left;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.input-area {
|
|
38
|
+
display: flex;
|
|
39
|
+
gap: 10px;
|
|
40
|
+
margin-top: auto; /* 항상 하단에 위치하도록 */
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.input-area input {
|
|
44
|
+
flex-grow: 1;
|
|
45
|
+
padding: 10px;
|
|
46
|
+
border: 1px solid #ccc;
|
|
47
|
+
border-radius: 5px;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.input-area button {
|
|
51
|
+
padding: 10px 15px;
|
|
52
|
+
background-color: #007bff;
|
|
53
|
+
color: white;
|
|
54
|
+
border: none;
|
|
55
|
+
border-radius: 5px;
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.input-area button:hover {
|
|
60
|
+
background-color: #0056b3;
|
|
61
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import './App.css';
|
|
3
|
+
import IO from 'iosignal/io.js';
|
|
4
|
+
|
|
5
|
+
const url = 'ws://localhost:7777';
|
|
6
|
+
const channel_tag = 'channel#topic';
|
|
7
|
+
|
|
8
|
+
function App() {
|
|
9
|
+
const [messages, setMessages] = useState([]);
|
|
10
|
+
const [input, setInput] = useState('Hello, World!');
|
|
11
|
+
const [ioState, setIoState] = useState(null); // ioState is updated by io.on('change')
|
|
12
|
+
const [cid, setCid] = useState(null); // cid is updated by io.on('ready')
|
|
13
|
+
const [counts, setCounts] = useState({ instances: 0, websockets: 0 }); // State for IO counts
|
|
14
|
+
const ioRef = useRef(null); // Manage io instance with useRef
|
|
15
|
+
const messagesEndRef = useRef(null);
|
|
16
|
+
|
|
17
|
+
const scrollToBottom = () => {
|
|
18
|
+
messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
scrollToBottom();
|
|
23
|
+
}, [messages]);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
console.log(IO.version)
|
|
27
|
+
ioRef.current = new IO(url); // Create io instance with URL
|
|
28
|
+
setCounts({ instances: IO.instanceCount, websockets: IO.webSocketCount }); // Set initial counts
|
|
29
|
+
|
|
30
|
+
if (!ioRef.current) {
|
|
31
|
+
console.error('IO instance is not initialized.');
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const handleReady = () => {
|
|
36
|
+
console.log('ready cid:', ioRef.current.cid);
|
|
37
|
+
setCid(ioRef.current.cid); // Update cid state
|
|
38
|
+
ioRef.current.subscribe(channel_tag); // Subscribe to channel
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const handleChange = (state) => {
|
|
42
|
+
setIoState(state);
|
|
43
|
+
setCounts({ instances: IO.instanceCount, websockets: IO.webSocketCount }); // Update counts on state change
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const handleChannelMessage = (msgObj, tag) => {
|
|
47
|
+
console.log('Received message in App:', msgObj, tag);
|
|
48
|
+
if( typeof msgObj === 'string' ) {
|
|
49
|
+
msgObj = { text: msgObj, cid: 'cli unknown' }; // Convert string to object if necessary
|
|
50
|
+
}
|
|
51
|
+
setMessages((prevMessages) => [...prevMessages, `${msgObj.cid} : ${msgObj.text}`]); // Update messages state]);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleError = (error) => {
|
|
55
|
+
console.error('IO Error in App:', error);
|
|
56
|
+
setIoState(`Error: ${error.message}`);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
ioRef.current.on('ready', handleReady);
|
|
60
|
+
ioRef.current.on('change', handleChange);
|
|
61
|
+
ioRef.current.on(channel_tag, handleChannelMessage); // Add channel message listener
|
|
62
|
+
ioRef.current.on('error', handleError);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Cleanup function: remove event listeners when component unmounts
|
|
66
|
+
return () => {
|
|
67
|
+
ioRef.current.off('ready', handleReady);
|
|
68
|
+
ioRef.current.off('change', handleChange);
|
|
69
|
+
ioRef.current.off(channel_tag, handleChannelMessage);
|
|
70
|
+
ioRef.current.off('error', handleError);
|
|
71
|
+
|
|
72
|
+
// destroy() is called to clean up the io instance, all listeners are removed automatically
|
|
73
|
+
ioRef.current.destroy(); // Clean up the io instance
|
|
74
|
+
console.log('IO instance destroyed.');
|
|
75
|
+
ioRef.current = null; // Release the io instance reference
|
|
76
|
+
};
|
|
77
|
+
}, []); // Empty dependency array ensures this runs only once on mount
|
|
78
|
+
|
|
79
|
+
const sendMessage = () => {
|
|
80
|
+
if (input.trim()) {
|
|
81
|
+
console.log('Sending message:', input);
|
|
82
|
+
const msgObj = { text: input, cid: ioRef.current.cid };
|
|
83
|
+
console.log('Sending message object:', msgObj);
|
|
84
|
+
ioRef.current.signal(channel_tag, msgObj); // Send message to channel
|
|
85
|
+
setInput('date' + Date.now());
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const ioStateStyle = {
|
|
90
|
+
color: ioState === 'ready' ? 'green' : 'red',
|
|
91
|
+
fontWeight: 'bold',
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<div className="App">
|
|
96
|
+
<h1>React Chat Example</h1>
|
|
97
|
+
<div>URL: {url}</div>
|
|
98
|
+
<div>Channel: {channel_tag}</div>
|
|
99
|
+
<div>IO State: <span style={ioStateStyle}>{ioState}</span></div>
|
|
100
|
+
<div>Client ID: {cid}</div>
|
|
101
|
+
<div>IO Instances: {counts.instances}</div>
|
|
102
|
+
<div>WebSockets Created: {counts.websockets}</div>
|
|
103
|
+
<div className="messages">
|
|
104
|
+
{messages.map((msg, index) => (
|
|
105
|
+
<div key={index}>{msg}</div>
|
|
106
|
+
))}
|
|
107
|
+
<div ref={messagesEndRef} />
|
|
108
|
+
</div>
|
|
109
|
+
<div className="input-area">
|
|
110
|
+
<input
|
|
111
|
+
type="text"
|
|
112
|
+
value={input}
|
|
113
|
+
onChange={(e) => setInput(e.target.value)}
|
|
114
|
+
onKeyUp={(e) => e.key === 'Enter' && sendMessage()}
|
|
115
|
+
disabled={ioState !== 'ready'}
|
|
116
|
+
/>
|
|
117
|
+
<button onClick={sendMessage} disabled={ioState !== 'ready'}>
|
|
118
|
+
Send
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default App;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
body {
|
|
2
|
+
margin: 0;
|
|
3
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
|
4
|
+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
|
5
|
+
sans-serif;
|
|
6
|
+
-webkit-font-smoothing: antialiased;
|
|
7
|
+
-moz-osx-font-smoothing: grayscale;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
code {
|
|
11
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
|
12
|
+
monospace;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import ReactDOM from 'react-dom/client'
|
|
3
|
+
import App from './App.jsx'
|
|
4
|
+
import './index.css'
|
|
5
|
+
|
|
6
|
+
const strictModeEnabled = true; // true/false 바꾸기만 하면 됨
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
10
|
+
strictModeEnabled
|
|
11
|
+
? <React.StrictMode><App /></React.StrictMode>
|
|
12
|
+
: <App />
|
|
13
|
+
)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Server } from "iosignal"
|
|
2
|
+
|
|
3
|
+
const server = new Server(
|
|
4
|
+
{
|
|
5
|
+
port: 7777,
|
|
6
|
+
congPort: 8888,
|
|
7
|
+
showMetric: 2,
|
|
8
|
+
showMessage: 'message' // show signal message
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
console.log('Signaling server started. Listening on port 7777 and congPort 8888');
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iosignal-example-server",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "iosignal-example-server",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"iosignal": "file:../.."
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"../..": {
|
|
15
|
+
"version": "3.1.0",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"boho": "^1.1.1",
|
|
19
|
+
"eventemitter3": "^5.0.1",
|
|
20
|
+
"meta-buffer-pack": "^2.1.0",
|
|
21
|
+
"ws": "^8.18.3"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@rollup/plugin-commonjs": "^28.0.0",
|
|
25
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
26
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
27
|
+
"@rollup/plugin-replace": "^6.0.1",
|
|
28
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
29
|
+
"@types/node": "^24.1.0",
|
|
30
|
+
"rollup": "^4.36.0",
|
|
31
|
+
"rollup-plugin-dts": "^6.2.1",
|
|
32
|
+
"typescript": "^5.8.3"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18.0.0"
|
|
36
|
+
},
|
|
37
|
+
"optionalDependencies": {
|
|
38
|
+
"bufferutil": "^4.0.9",
|
|
39
|
+
"utf-8-validate": "^6.0.5"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"node_modules/iosignal": {
|
|
43
|
+
"resolved": "../..",
|
|
44
|
+
"link": true
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# sv
|
|
2
|
+
|
|
3
|
+
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).
|
|
4
|
+
|
|
5
|
+
## Creating a project
|
|
6
|
+
|
|
7
|
+
If you're seeing this, you've probably already done this step. Congrats!
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# create a new project in the current directory
|
|
11
|
+
npx sv create
|
|
12
|
+
|
|
13
|
+
# create a new project in my-app
|
|
14
|
+
npx sv create my-app
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Developing
|
|
18
|
+
|
|
19
|
+
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
npm run dev
|
|
23
|
+
|
|
24
|
+
# or start the server and open the app in a new browser tab
|
|
25
|
+
npm run dev -- --open
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Building
|
|
29
|
+
|
|
30
|
+
To create a production version of your app:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm run build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
You can preview the production build with `npm run preview`.
|
|
37
|
+
|
|
38
|
+
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
|