OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * WebRTC session to the DevTools Bridge Server. Handles a peer connection. |
| 7 * Client sends an offer to the server, waits for an answer and then |
| 8 * handles ICE candidates exhange process. |
| 9 * |
| 10 * @Constructor |
| 11 */ |
| 12 function ClientSession(deviceId, gcdClient) { |
| 13 this.deviceId_ = deviceId; |
| 14 this.connection_ = new webkitRTCPeerConnection(null, null); |
| 15 this.gcdClient_ = gcdClient; |
| 16 this.id_ = ""; // TODO(serya): generate or pass ID. |
| 17 } |
| 18 |
| 19 ClientSession.prototype.start = function() { |
| 20 this.connection_.createOffer(this.onOfferCreated_.bind(this), |
| 21 this.onOfferFailed_.bind(this), |
| 22 {}); |
| 23 }; |
| 24 |
| 25 ClientSession.prototype.stop = function() { |
| 26 this.connection_.close(); |
| 27 }; |
| 28 |
| 29 ClientSession.prototype.onOfferCreated_ = function(offer) { |
| 30 this.gcdClient_.sendCommand({ |
| 31 'deviceId': this.deviceId_, |
| 32 'name': 'base._startSession', |
| 33 'parameters': { |
| 34 '_sessionId': this.id_, |
| 35 '_config': '{}', |
| 36 '_offer': offer.sdp |
| 37 } |
| 38 }); |
| 39 }; |
| 40 |
| 41 ClientSession.prototype.onOfferFailed_ = function(error) { |
| 42 console.log('Offer failed: ' + error); |
| 43 }; |
OLD | NEW |