| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; | 5 const String _webSocketGUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; |
| 6 | 6 |
| 7 class _WebSocketMessageType { | 7 class _WebSocketMessageType { |
| 8 static const int NONE = 0; | 8 static const int NONE = 0; |
| 9 static const int BINARY = 1; | 9 static const int BINARY = 1; |
| 10 static const int TEXT = 2; | 10 static const int TEXT = 2; |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 String reason = ""; | 286 String reason = ""; |
| 287 if (_controlPayload.length > 0) { | 287 if (_controlPayload.length > 0) { |
| 288 if (_controlPayload.length == 1) { | 288 if (_controlPayload.length == 1) { |
| 289 throw new WebSocketException("Protocol error"); | 289 throw new WebSocketException("Protocol error"); |
| 290 } | 290 } |
| 291 status = _controlPayload[0] << 8 | _controlPayload[1]; | 291 status = _controlPayload[0] << 8 | _controlPayload[1]; |
| 292 if (_controlPayload.length > 2) { | 292 if (_controlPayload.length > 2) { |
| 293 var decoder = _StringDecoders.decoder(Encoding.UTF_8); | 293 var decoder = _StringDecoders.decoder(Encoding.UTF_8); |
| 294 decoder.write( | 294 decoder.write( |
| 295 _controlPayload.getRange(2, _controlPayload.length - 2)); | 295 _controlPayload.getRange(2, _controlPayload.length - 2)); |
| 296 reason = decoder.decoded; | 296 reason = decoder.decoded(); |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 if (onClosed !== null) onClosed(status, reason); | 299 if (onClosed !== null) onClosed(status, reason); |
| 300 _state = CLOSED; | 300 _state = CLOSED; |
| 301 break; | 301 break; |
| 302 | 302 |
| 303 case _WebSocketOpcode.PING: | 303 case _WebSocketOpcode.PING: |
| 304 if (onPing !== null) onPing(_controlPayload); | 304 if (onPing !== null) onPing(_controlPayload); |
| 305 break; | 305 break; |
| 306 | 306 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 if (_currentMessageType == _WebSocketMessageType.TEXT) { | 474 if (_currentMessageType == _WebSocketMessageType.TEXT) { |
| 475 _decoder.write(buffer.getRange(offset, count)); | 475 _decoder.write(buffer.getRange(offset, count)); |
| 476 } else { | 476 } else { |
| 477 _outputStream.write(buffer.getRange(offset, count)); | 477 _outputStream.write(buffer.getRange(offset, count)); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 | 480 |
| 481 _onWebSocketMessageEnd() { | 481 _onWebSocketMessageEnd() { |
| 482 if (_onMessage !== null) { | 482 if (_onMessage !== null) { |
| 483 if (_currentMessageType == _WebSocketMessageType.TEXT) { | 483 if (_currentMessageType == _WebSocketMessageType.TEXT) { |
| 484 _onMessage(_decoder.decoded); | 484 _onMessage(_decoder.decoded()); |
| 485 } else { | 485 } else { |
| 486 _onMessage(_outputStream.read()); | 486 _onMessage(_outputStream.read()); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 _decoder = null; | 489 _decoder = null; |
| 490 _outputStream = null; | 490 _outputStream = null; |
| 491 } | 491 } |
| 492 | 492 |
| 493 _onWebSocketPing(List<int> payload) { | 493 _onWebSocketPing(List<int> payload) { |
| 494 _sendFrame(_WebSocketOpcode.PONG, payload); | 494 _sendFrame(_WebSocketOpcode.PONG, payload); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 851 |
| 852 class _WebSocketCloseEvent implements CloseEvent { | 852 class _WebSocketCloseEvent implements CloseEvent { |
| 853 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); | 853 _WebSocketCloseEvent(this._wasClean, this._code, this._reason); |
| 854 bool get wasClean => _wasClean; | 854 bool get wasClean => _wasClean; |
| 855 int get code => _code; | 855 int get code => _code; |
| 856 String get reason => _reason; | 856 String get reason => _reason; |
| 857 bool _wasClean; | 857 bool _wasClean; |
| 858 int _code; | 858 int _code; |
| 859 String _reason; | 859 String _reason; |
| 860 } | 860 } |
| OLD | NEW |