| 1678 | self.setHeartbeatTimeout(); |
| 1679 | |
| 1680 | function connect (transports){ |
| 1681 | if (self.transport) self.transport.clearTimeouts(); |
| 1682 | |
| 1683 | self.transport = self.getTransport(transports); |
| 1684 | if (!self.transport) return self.publish('connect_failed'); |
| 1685 | |
| 1686 | // once the transport is ready |
| 1687 | self.transport.ready(self, function () { |
| 1688 | self.connecting = true; |
| 1689 | self.publish('connecting', self.transport.name); |
| 1690 | self.transport.open(); |
| 1691 | |
| 1692 | if (self.options['connect timeout']) { |
| 1693 | self.connectTimeoutTimer = setTimeout(function () { |
| 1694 | if (!self.connected) { |
| 1695 | self.connecting = false; |
| 1696 | |
| 1697 | if (self.options['try multiple transports']) { |
| 1698 | if (!self.remainingTransports) { |
| 1699 | self.remainingTransports = self.transports.slice(0); |
| 1700 | } |
| 1701 | |
| 1702 | var remaining = self.remainingTransports; |
| 1703 | |
| 1704 | while (remaining.length > 0 && remaining.splice(0,1)[0] != |
| 1705 | self.transport.name) {} |
| 1706 | |
| 1707 | if (remaining.length){ |
| 1708 | connect(remaining); |
| 1709 | } else { |
| 1710 | self.publish('connect_failed'); |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | }, self.options['connect timeout']); |
| 1715 | } |
| 1716 | }); |
| 1717 | } |
| 1718 | |
| 1719 | connect(self.options.transports); |
| 1720 | |