Esempio n. 1
0
from BridgePython.bridge import Bridge 
bridge = Bridge(api_key='myapikey')


#
# Joining a Bridge channel
#
# In order to join a Bridge channel, clients must provide the name 
# of the channel to join and a handler object on which RPC calls 
# in the channel will act on. Note that the client that is joined 
# to the channel is whoever created the handler, not necessarily the 
# client executing the join command. This means clients can join other
# clients to channels by having a reference to an object of theirs.
#
# Only Bridge clients using the private API key may call the join command. 
# However, those clients may join other clients using the public API key on their behalf.
#
def start():
    class TestHandler(object):
        def log(self, msg):
            print('Got message: %s' % (msg));

    bridge.join_channel('testChannel', TestHandler(), callback=ready)


#
# Getting and calling a Bridge channel
#
# This can be done from any Bridge client connected to the same 
# Bridge server, regardless of language.
# When a function call is made to a channel object, the requested
Esempio n. 2
0
from BridgePython.bridge import Bridge 
bridge = Bridge(api_key='myapikey')


#
# Publishing a Bridge service
#
# Any Python object can be published. A published service 
# can be retrieved by any Bridge client with the same API key pair.
#
# Only Bridge clients using the prviate API key may publish services.
#
class TestService(object):
    def ping(self, cb):
        print 'Received ping request!'
        cb('Pong')
        
bridge.publish_service('testService', TestService())


#
# Retrieving a Bridge service 
#
# This can be done from any Bridge client connected to the same 
# Bridge server, regardless of language.
# If multiple clients publish a Bridge service, getService will 
# retrieve from the publisher with the least load.
#
def message_cb(msg):
    print msg
    
Esempio n. 3
0
from BridgePython.bridge import Bridge 
bridge = Bridge(api_key='f99ede2465de4114')


def message_cb(msg):
  print msg

forjs = """
handler.run  =  function(message_cb, start, end) {
        var temp = start + end;
        console.log(temp);
        message_cb(temp);
}
"""

channel = bridge.get_channel('function-channel')
channel.message(forjs)

cluster = bridge.get_service('cluster')

cluster.run(message_cb, 1, 3)
cluster.run(message_cb, 5, 3)

bridge.connect()
Esempio n. 4
0
#!/usr/bin/python

import logging
from BridgePython.bridge import Bridge

bridge = Bridge(host='localhost', port=8090, log_level=logging.DEBUG,
        api_key='abcdefgh', reconnect=True)


class Handler(object):
    def someFn(self, name, message):
        print(name + ': ' + message)


def callback(message):
    self.lobby.msg(self.name, message)


def start_client():
    handler = Handler()

    someService = bridge.get_service('someService')
    someService.someFn(1, 1.0, 'foo', True, None, ['foo', 'bar'], {'foo': 'bar'})
    someService.someFn(handler, callback);

    someChannel = bridge.get_channel('someChannel')
    someChannel.someFn(1, 1.0, 'foo', True, None, ['foo', 'bar'], {'foo': 'bar'})

    bridge.join_channel('myChannel', handler, callback)
    bridge.join_channel('myChannel', handler)