Ejemplo n.º 1
0
def run(addr, schema, secret):
    channel = grpc.insecure_channel(addr)
    stub = pbx.NodeStub(channel)
    # Call the server
    stream = stub.MessageLoop(gen_message(schema, secret))
    try:
        # Read server responses
        for msg in stream:
            if msg.HasField("ctrl"):
                # Run code on command completion
                func = onCompletion.get(msg.ctrl.id)
                if func != None:
                    del onCompletion[msg.ctrl.id]
                    if msg.ctrl.code >= 200 and msg.ctrl.code < 400:
                        func(msg.ctrl.params)
                print(str(msg.ctrl.code) + " " + msg.ctrl.text)
            elif msg.HasField("data"):
                print("\nFrom: " + msg.data.from_user_id + ":\n")
                print(json.loads(msg.data.content) + "\n")
            elif msg.HasField("pres"):
                pass
            else:
                print("Message type not handled", msg)

    except grpc._channel._Rendezvous as err:
        print(err)
def init_client(addr, schema, secret, cookie_file_name, secure, ssl_host):
    print("Connecting to", "secure" if secure else "", "server at", addr,
        "SNI="+ssl_host if ssl_host else "")

    channel = None
    if secure:
        opts = (('grpc.ssl_target_name_override', ssl_host),) if ssl_host else None
        channel = grpc.secure_channel(addr, grpc.ssl_channel_credentials(), opts)
    else:
        channel = grpc.insecure_channel(addr)

    # Call the server
    stream = pbx.NodeStub(channel).MessageLoop(client_generate())
    print(" Session initialization sequence: {hi}, {login}, {sub topic='me'} ")
    # Session initialization sequence: {hi}, {login}, {sub topic='me'}
    client_post(hello())
    client_post(login(cookie_file_name, schema, secret))
    ids = next_id()

    client_post(subscribe_v2('usrBaeu194wTfU', ids))
    
    msg = "Please write it you msg"
    path = "prompts.json"
    user_destination = 'usrBaeu194wTfU'
    head_info = "\"text/x-drafty\""

    client_post(publish_v2(user_destination, msg, ids, path, head_info))
    
    
    
    for msg in stream:
        print(msg)
    return stream
Ejemplo n.º 3
0
def init_client(addr, schema, secret, cookie_file_name):
    channel = grpc.insecure_channel(addr)
    stub = pbx.NodeStub(channel)
    # Call the server
    stream = stub.MessageLoop(client_generate())
    # Session initialization sequence: {hi}, {login}, {sub topic='me'}
    client_post(hello())
    client_post(login(cookie_file_name, schema, secret))
    client_post(subscribe('me'))

    return stream