Showing
2 changed files
with
10 additions
and
4 deletions
@@ -200,6 +200,10 @@ function pageInit() { | @@ -200,6 +200,10 @@ function pageInit() { | ||
200 | 200 | ||
201 | connectFailCb: function () { | 201 | connectFailCb: function () { |
202 | $('.connect-fail').fadeIn(); | 202 | $('.connect-fail').fadeIn(); |
203 | + }, | ||
204 | + | ||
205 | + socketClosedCb: function () { | ||
206 | + alert('链接已经断开了,请刷新后重试!'); | ||
203 | } | 207 | } |
204 | })); | 208 | })); |
205 | } | 209 | } |
@@ -7,9 +7,10 @@ | @@ -7,9 +7,10 @@ | ||
7 | 7 | ||
8 | var times, | 8 | var times, |
9 | param, | 9 | param, |
10 | - servers, | ||
11 | socket, | 10 | socket, |
12 | server, | 11 | server, |
12 | + servers, | ||
13 | + options, | ||
13 | connectId, | 14 | connectId, |
14 | conversationMessage; | 15 | conversationMessage; |
15 | 16 | ||
@@ -19,9 +20,10 @@ function _randomServer() { | @@ -19,9 +20,10 @@ function _randomServer() { | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * socket初始化 | 22 | * socket初始化 |
22 | - * @param options | 23 | + * @param opts |
23 | */ | 24 | */ |
24 | -function socketInit(options) { | 25 | +function socketInit(opts) { |
26 | + options = opts; | ||
25 | servers = options.servers; | 27 | servers = options.servers; |
26 | server = _randomServer(); | 28 | server = _randomServer(); |
27 | conversationMessage = options.conversationMessage; | 29 | conversationMessage = options.conversationMessage; |
@@ -84,7 +86,7 @@ function sendMsg(msg) { | @@ -84,7 +86,7 @@ function sendMsg(msg) { | ||
84 | if (socket.readyState === WebSocket.OPEN) { | 86 | if (socket.readyState === WebSocket.OPEN) { |
85 | socket.send(JSON.stringify(msg)); | 87 | socket.send(JSON.stringify(msg)); |
86 | } else { | 88 | } else { |
87 | - console.log('The socket is not open.'); | 89 | + options.socketClosedCb(); |
88 | } | 90 | } |
89 | } | 91 | } |
90 | 92 |
-
Please register or login to post a comment