質問編集履歴
1
App.jsの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -133,3 +133,77 @@
|
|
133
133
|
|
134
134
|
|
135
135
|
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
```AppJS
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
var io = require('socket.io')(3000);
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
/**
|
148
|
+
|
149
|
+
* connection
|
150
|
+
|
151
|
+
*/
|
152
|
+
|
153
|
+
io.sockets.on('connection', function (socket) {
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
/**
|
158
|
+
|
159
|
+
* disconnect
|
160
|
+
|
161
|
+
*/
|
162
|
+
|
163
|
+
socket.on('disconnect', function () {
|
164
|
+
|
165
|
+
socket.leave(socket.data.room);
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
/**
|
172
|
+
|
173
|
+
* メンバーを追加
|
174
|
+
|
175
|
+
*/
|
176
|
+
|
177
|
+
socket.on('add:member', function(data) {
|
178
|
+
|
179
|
+
socket.data = data;
|
180
|
+
|
181
|
+
socket.join(data.room);
|
182
|
+
|
183
|
+
io.sockets.to(socket.data.room).emit('insert:message', socket.data.message);
|
184
|
+
|
185
|
+
});
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
/**
|
190
|
+
|
191
|
+
* メッセージを挿入
|
192
|
+
|
193
|
+
*/
|
194
|
+
|
195
|
+
socket.on('insert:message', function (data) {
|
196
|
+
|
197
|
+
io.sockets.to(socket.data.room).emit('insert:message', data.message);
|
198
|
+
|
199
|
+
});
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
});
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
```
|