 
 # Connection and disconnection.
 		
-		@connect = -> socket.socket.connect()
+		service.connect = -> socket.socket.connect()
 		
-		@connected = -> socket.socket.connected
+		service.connected = -> socket.socket.connected
 
-		@disconnect = -> socket.disconnect()
+		service.disconnect = -> socket.disconnect()
 		
 # Proxy for Socket::on, handles invocation of Scope::$apply.
 		
-		@on = (eventName, callback) ->
+		service.on = (eventName, callback) ->
 			
 			debugListeners["on-#{eventName}"] ?= (->
 				socket.on eventName, (data) ->

		
# Proxy for Socket::emit, handles invocation of Scope::$apply.

		@emit = (eventName, data, callback) ->
			return initializedQueue.push arguments unless @connected()
			
			if config.get 'debugging'
				console.debug "sent: #{eventName}, #{JSON.stringify data, null, '  '}"

	'$rootScope', 'config'
	($rootScope, config) ->
		
		service = {}
		
# Be aware: this will throw in unit tests because [global].io won't be
# available. It must be mocked out.
		
		return service if 'unit' is config.get 'testMode'
		socket = io.connect()
		
# We have to queue emits while not initialized to keep things robust.
	
		initializedQueue = []
		socket.on 'initialized', =>
			service.emit.apply this, args for args in initializedQueue
		
# Might as well make sure everything's working fine.
		
