func newGCMClient(xmppc xmppC, httpc httpC, config *Config, h MessageHandler) (*gcmClient, error) {
	c := &gcmClient{
		httpClient:   httpc,
		xmppClient:   xmppc,
		xmppChan:     make(chan xmppPacket),
		cerr:         make(chan error, 1),
		senderID:     config.SenderID,
		apiKey:       config.APIKey,
		mh:           h,
		debug:        config.Debug,
		omitRetry:    config.OmitInternalRetry,
		sandbox:      config.Sandbox,
		pingInterval: time.Duration(config.PingInterval) * time.Second,
		pingTimeout:  time.Duration(config.PingTimeout) * time.Second,
		killMonitor:  make(chan bool, 1),
	}
	if c.pingInterval <= 0 {
		c.pingInterval = DefaultPingInterval
	}
	if c.pingTimeout <= 0 {
		c.pingTimeout = DefaultPingTimeout
	}

	clientIsConnected := make(chan bool, 1)
	if xmppc != nil {
		// Create and monitor XMPP client.
		go c.monitorXMPP(config.MonitorConnection, clientIsConnected)

		select {
		case err := <-c.cerr:
			c.killMonitor <- true
			return nil, err
		case <-clientIsConnected:
			return c, nil
		case <-time.After(10 * time.Second):
			c.killMonitor <- true
			return nil, errors.New("Timed out attempting to connect client")
		}
	} else {
		return c, nil
	}
}
// newGCMClient creates an instance of gcmClient.
newGCMClient creates an instance of gcmClient.
// newGCMClient creates an instance of gcmClient .
func newGCMClient(xmppc xmppC, httpc httpC, config *Config, h MessageHandler) (*gcmClient, error) {
	c := &gcmClient{
		httpClient:   httpc,
		xmppClient:   xmppc,
		xmppChan:     make(chan xmppPacket),
		cerr:         make(chan error, 1),
		senderID:     config.SenderID,
		apiKey:       config.APIKey,
		mh:           h,
		debug:        config.Debug,
		omitRetry:    config.OmitInternalRetry,
		sandbox:      config.Sandbox,
		pingInterval: time.Duration(config.PingInterval) * time.Second,
		pingTimeout:  time.Duration(config.PingTimeout) * time.Second,
		killMonitor:  make(chan bool, 1),
	}
	if c.pingInterval <= 0 {
		c.pingInterval = DefaultPingInterval
	}
	if c.pingTimeout <= 0 {
		c.pingTimeout = DefaultPingTimeout
	}
	clientIsConnected := make(chan bool, 1)
	if xmppc != nil {
		go c.monitorXMPP(config.MonitorConnection, clientIsConnected)
		select {
		case err := <-c.cerr:
			c.killMonitor <- true
			return nil, err
		case <-clientIsConnected:
			return c, nil
		case <-time.After(10 * time.Second):
			c.killMonitor <- true
			return nil, errors.New("Timed out attempting to connect client")
		}
	} else {
		return c, nil
	}
}
func newGCMClient ( xmppc xmppC , httpc httpC , config * Config , h MessageHandler ) ( * gcmClient , error ) { c := & gcmClient { httpClient : httpc , xmppClient : xmppc , xmppChan : make ( chan xmppPacket ) , cerr : make ( chan error , 1 ) , senderID : config . SenderID , apiKey : config . APIKey , mh : h , debug : config . Debug , omitRetry : config . OmitInternalRetry , sandbox : config . Sandbox , pingInterval : time . Duration ( config . PingInterval ) * time . Second , pingTimeout : time . Duration ( config . PingTimeout ) * time . Second , killMonitor : make ( chan bool , 1 ) , } if c . pingInterval <= 0 { c . pingInterval = DefaultPingInterval } if c . pingTimeout <= 0 { c . pingTimeout = DefaultPingTimeout } clientIsConnected := make ( chan bool , 1 ) if xmppc != nil { go c . monitorXMPP ( config . MonitorConnection , clientIsConnected ) select { case err := <- c . cerr : c . killMonitor <- true return nil , err case <- clientIsConnected : return c , nil case <- time . After ( 10 * time . Second ) : c . killMonitor <- true return nil , errors . New ( " " ) } } else { return c , nil } }
newGCMClient creates an instance of gcmClient.
newGCMClient creates an instance of gcmClient .
// Create and monitor XMPP client.