def remote_connect(request, message): import sputnik ret = {} # does this work ? try: clientID = sputnik.incr("sputnik:client_id") except: sputnik.rcon.connect() clientID = sputnik.incr("sputnik:client_id") ret["clientID"] = clientID request.sputnikID = "%s:%s" % (request.session.session_key, clientID) if not clientID: return # subscribe to this channels for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID) # set our username if request.user and request.user.username.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:username" % request.sputnikID, request.user.username) # set our last access if request.sputnikID and request.sputnikID.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:last_access" % request.sputnikID, time.time()) return ret
def remote_subscribe(request, message): import sputnik for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID)
def remote_connect(request, message): """ Initializes sputnik connection for this client. Creates clientID for this connection. Input: - chanels @type request: C{django.http.HttpRequest} @param request: Client Request object @type message: C{dict} @param message: Message object @rtype: C{string} @return: Returns unique Client ID for this connection """ import sputnik ret = {} # does this work ? try: clientID = sputnik.incr("sputnik:client_id") except: sputnik.rcon.connect() clientID = sputnik.incr("sputnik:client_id") ret["clientID"] = clientID request.sputnikID = "%s:%s" % (request.session.session_key, clientID) if not clientID: return # subscribe to this channels for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID) # set our username if request.user and request.user.username.strip( ) != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:username" % request.sputnikID, request.user.username) # set our last access if request.sputnikID and request.sputnikID.strip( ) != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:last_access" % request.sputnikID, time.time()) return ret
def remote_connect(request, message): """ Initializes sputnik connection for this client. Creates clientID for this connection. Input: - chanels :Args: - request (:class:`django.http.HttpRequest`): Client Request object - message (dict): Message object :Returns: Returns unique Client ID for this connection """ import sputnik ret = {} # does this work ? try: clientID = sputnik.incr("sputnik:client_id") except Exception as err: logger.warn("Not able to get cliend_id from sputnik. Msg: %s" % err) sputnik.rcon.connect() clientID = sputnik.incr("sputnik:client_id") ret["clientID"] = clientID request.sputnikID = "%s:%s" % (request.session.session_key, clientID) if not clientID: return # subscribe to this channels for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID) # set our username if request.user and request.user.username.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:username" % request.sputnikID, request.user.username) # set our last access if request.sputnikID and request.sputnikID.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:last_access" % request.sputnikID, time.time()) return ret
def remote_connect(request, message): """ Initializes sputnik connection for this client. Creates clientID for this connection. Input: - chanels @type request: C{django.http.HttpRequest} @param request: Client Request object @type message: C{dict} @param message: Message object @rtype: C{string} @return: Returns unique Client ID for this connection """ import sputnik ret = {} # does this work ? try: clientID = sputnik.incr("sputnik:client_id") except: sputnik.rcon.connect() clientID = sputnik.incr("sputnik:client_id") ret["clientID"] = clientID request.sputnikID = "%s:%s" % (request.session.session_key, clientID) if not clientID: return # subscribe to this channels for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID) # set our username if request.user and request.user.username.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:username" % request.sputnikID, request.user.username) # set our last access if request.sputnikID and request.sputnikID.strip() != '' and request.sputnikID and request.sputnikID.find(' ') == -1: sputnik.set("ses:%s:last_access" % request.sputnikID, time.time()) return ret
def remote_subscribe(request, message): """ Subscribes client to specific channels. Input: - chanels :Args: - request (:class:`django.http.HttpRequest`): Client Request object - message (dict): Message object """ import sputnik for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID)
def remote_subscribe(request, message): """ Subscribes client to specific channels. Input: - chanels @type request: C{django.http.HttpRequest} @param request: Client Request object @type message: C{dict} @param message: Message object """ import sputnik for chnl in message["channels"]: if not sputnik.hasChannel(chnl): sputnik.createChannel(chnl) sputnik.addClientToChannel(chnl, request.sputnikID)