88
99import Foundation
1010
11- let SPDefaultClientName : String = " jenny " ;
11+ let SPDefaultClientName : String = " jenny "
1212let SPBaseCapabilityTokenUrl : String = " http://example.com/generateToken?%@ "
13- let SPTwiMLAppSid : String = " APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx " ;
13+ let SPTwiMLAppSid : String = " APxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "
1414
1515public class Phone : NSObject , TCDeviceDelegate {
1616 var device : TCDevice !
@@ -19,57 +19,53 @@ public class Phone : NSObject, TCDeviceDelegate {
1919
2020 func login( ) {
2121
22- TwilioClient . sharedInstance ( ) . setLogLevel ( TCLogLevel . _LOG_VERBOSE) ;
22+ TwilioClient . sharedInstance ( ) . setLogLevel ( TCLogLevel . _LOG_VERBOSE)
2323
24- var url : String = self . getCapabilityTokenUrl ( ) ;
24+ var url : String = self . getCapabilityTokenUrl ( )
2525
26- var swiftRequest = SwiftRequest ( ) ;
26+ var swiftRequest = SwiftRequest ( )
2727 swiftRequest. get ( url, callback: { ( err, response, body) -> ( ) in
28- if ( err != nil ) {
29- return ;
28+ if err != nil {
29+ return
3030 }
3131
3232 var token = body as! String
33- println ( token) ;
33+ println ( token)
3434
35- if ( err == nil && token != " " )
36- {
37- if ( self . device == nil )
38- {
39- self . device = TCDevice ( capabilityToken: token as String , delegate: nil ) ;
35+ if err == nil && token != " " {
36+ if self . device == nil {
37+ self . device = TCDevice ( capabilityToken: token as String , delegate: nil )
4038 }
41- else
42- {
43- self . device!. updateCapabilityToken ( token) ;
39+ else {
40+ self . device!. updateCapabilityToken ( token)
4441 }
4542 }
46- else if ( err != nil && response != nil ) {
43+ else if err != nil && response != nil {
4744 // We received and error with a response
4845 }
49- else if ( err != nil ) {
46+ else if err != nil {
5047 // We received an error without a response
5148 }
52- } ) ;
49+ } )
5350 }
5451
5552 func getCapabilityTokenUrl( ) -> String {
5653
57- var querystring : String = String ( ) ;
54+ var querystring : String = String ( )
5855
59- querystring += String ( format: " &sid=%@ " , SPTwiMLAppSid) ;
60- querystring += String ( format: " &name=%@ " , SPDefaultClientName) ;
56+ querystring += String ( format: " &sid=%@ " , SPTwiMLAppSid)
57+ querystring += String ( format: " &name=%@ " , SPDefaultClientName)
6158
62- return String ( format: SPBaseCapabilityTokenUrl, querystring) ;
59+ return String ( format: SPBaseCapabilityTokenUrl, querystring)
6360 }
6461
6562 func connectWithParams( params dictParams: Dictionary < String , String > = Dictionary < String , String > ( ) ) {
6663
67- if ( !self . capabilityTokenValid ( ) )
68- {
69- self . login ( ) ;
64+ if !self . capabilityTokenValid ( ) {
65+ self . login ( )
7066 }
7167
72- self . connection = self . device? . connect ( dictParams, delegate: nil ) ;
68+ self . connection = self . device? . connect ( dictParams, delegate: nil )
7369 }
7470
7571 func acceptConnection( ) {
@@ -90,21 +86,21 @@ public class Phone : NSObject, TCDeviceDelegate {
9086 }
9187
9288 func capabilityTokenValid( ) -> ( Bool ) {
93- var isValid : Bool = false ;
89+ var isValid : Bool = false
9490
95- if ( self . device != nil ) {
91+ if self . device != nil {
9692 var capabilities = self . device!. capabilities as NSDictionary ;
9793
9894 var expirationTimeObject : NSNumber = capabilities. objectForKey ( " expiration " ) as! NSNumber ;
9995 var expirationTimeValue : Int64 = expirationTimeObject. longLongValue;
10096 var currentTimeValue : NSTimeInterval = NSDate ( ) . timeIntervalSince1970;
10197
102- if ( ( expirationTimeValue- Int64( currentTimeValue) ) > 0 ) {
98+ if ( expirationTimeValue- Int64( currentTimeValue) ) > 0 {
10399 isValid = true ;
104100 }
105101 }
106102
107- return isValid;
103+ return isValid
108104 }
109105
110106 public func deviceDidStartListeningForIncomingConnections( device: TCDevice ) -> ( ) {
0 commit comments