iOS Client with Node Server

31 views
Skip to first unread message

sbarow

unread,
Jul 19, 2012, 12:01:17 PM7/19/12
to bridge...@googlegroups.com
Hey,

Busy playing around with the Bridge examples. I am using a local Bridge server, with node and the callbacks_server javascript example. I then have an iOS Client running in my simulator.

Javascript -- 

var Bridge = require('/usr/local/lib/node_modules/bridge-js');
var bridge = new Bridge({host: 'localhost', port: 8090, apiKey: 'myprivateapikey' });

var authObj = {
login: function(username, password, callback) {
if (password == 'secret123') {
console.log('Welcome');
callback(true);
}
else {
console.log('Sorry!');
callback(false);
}
}
}

bridge.publishService('auth', authObj);
bridge.connect();

Objective-C Code:

-(void)combinedChatClient:(Bridge *)bridge

{    

    BridgeCallback* callback = [BridgeCallback callbackWithBlock:^(NSArray* args){

        // First argument is the name of the sender

        NSString* roomName = [args objectAtIndex:0];

        // Second argument is the message

        BridgeRemoteObject<RemoteChat>* channel = [args objectAtIndex:1];

        

        NSLog(@"Joined channel: %@", roomName);

        [channel message:@"\n\nsteve" :@"Bridge is pretty nifty!"];

    }];

    [bridge joinChannel:@"bridge-lovers \n\n" withHandler:[ChatObj new] andCallback:callback];

    [bridge connect];

}


The error on the server side is TypeError: object is not a function


if I console log the callback object it looks like this


{ _address: [ 'client', 'lkadgdndgbclhcel', 'fzxc0WG0lV' ],

  notify: [Function],

  _operations: [ 'notify' ],

  _bridge: 

   { _context: { _bridge: [Circular], clientId: 'lkadgdndgbclhcel' },

     _options: 

      { redirector: 'http://redirector.getbridge.com',

        secure_redirector: 'https://redirector.getbridge.com',

        secure: false,

        reconnect: true,

        log: 2,

        tcp: true,

        prototype: [Object],

        __super__: undefined,

        host: 'localhost',

        port: 8090,

        apiKey: 'myprivateapikey' },

     _store: { system: [Object], auth: [Object] },

     _ready: true,

     _connection: 

      { bridge: [Circular],

        options: [Object],

        sockBuffer: [Object],

        sock: [Object],

        interval: 400,

        clientId: 'bjbfdcfiicegefif',

        secret: 'ibibamiecneihigc' },

     _events: {} } }

TypeError: object is not a function

    at Object.authObj.login (/Users/CameronMcGorian/Sites/node-examples/bridge-test/callbacks_server.js:9:4)

    at Bridge._execute (/usr/local/lib/node_modules/bridge-js/lib/bridge.js:103:12)

    at Socket.Connection.processMessage [as onmessage] (/usr/local/lib/node_modules/bridge-js/lib/connection.js:180:15)

    at sock.start (/usr/local/lib/node_modules/bridge-js/lib/tcp.js:61:14)

    at Socket.sock.onchunk (/usr/local/lib/node_modules/bridge-js/lib/tcp.js:41:7)

    at Socket.sock.onchunk (/usr/local/lib/node_modules/bridge-js/lib/tcp.js:42:12)

    at Socket.EventEmitter.emit (events.js:88:17)

    at TCP.onread (net.js:397:14)


If I then try it with the Javascript call back Client all works fine and the logged callback object looks like this 


{ [Function]

  _reference: 

   { _address: [ 'client', 'ecnagldjgekemall', 'rfumnicjwpdv' ],

     callback: [Function],

     _operations: [ 'callback' ],

     _bridge: 

      { _context: [Object],

        _options: [Object],

        _store: [Object],

        _ready: true,

        _connection: [Object],

        _events: {} } },

  _toDict: [Function],

  callback: [Circular] }


Is there any special formatting that needs to happen on the Javascript of Objective C side?

Sridatta Thatipamala

unread,
Jul 19, 2012, 2:43:56 PM7/19/12
to bridge...@googlegroups.com
The Objective-C code you posted wouldn't be contacting the node.js server at all. Are you actually using this one?:
    
    BridgeCallback* callback = [BridgeCallback callbackWithBlock:^(NSArray* args){
      // First argument is the name of the sender
      NSString* roomName = [args objectAtIndex:0];
      // Second argument is the message
      BridgeRemoteObject<RemoteChat>* channel = [args objectAtIndex:1];
      
      NSLog(@"Joined channel: %@", roomName);
      [channel message:@"steve" :@"Bridge is pretty nifty!"]; 
    }];
    
    [remoteAuth login:@"steve" :@"bridge-lovers" :@"secret123" :[ChatObj new] :callback];
    [bridge connect];
--Sridatta

--
You received this message because you are subscribed to the Google Groups "Bridge" group.
To post to this group, send email to bridge...@googlegroups.com.
To unsubscribe from this group, send email to bridge-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/bridge-users/-/YBDdZvUNO6QJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

sbarow

unread,
Jul 19, 2012, 2:59:46 PM7/19/12
to bridge...@googlegroups.com
Nope definitely using the code I posted, it does contact the server but throw the error also posted above.

If I use the code you have posted it works fine, that is in a bock though, would like to know why the other code doesn't work?
To unsubscribe from this group, send email to bridge-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages