Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit work on explorer not in iOS 8 #46

Open
josefrm opened this issue Feb 13, 2015 · 4 comments
Open

Emit work on explorer not in iOS 8 #46

josefrm opened this issue Feb 13, 2015 · 4 comments

Comments

@josefrm
Copy link

josefrm commented Feb 13, 2015

Hello there, im having some issue there if i open the explorer all of the emit methods works like a charm, but in iOS not.

Any idea why is that happening, some of code here:

Server:

io.on('connection', function(socket)
{
ClientsArray.push(new function () {
this.userid = "";
this.socketid = socket.id;
});

    socket.on('disconnect', function ()
    {
        for (var i = 0; i < ClientsArray.length; i++)
        {
            if (ClientsArray[i].socketid == socket.id)
            {
                ClientsArray.splice(i, 1);
                break;
            }
        }
        console.log(ClientsArray);

    });
    socket.on('chat message', function (msg)
    {
        var Ms = msg;
        console.log(msg);
        try
        {
                var arr = msg.split(";-:-;");
                var toSocketID;
                for (var i = 0; i < ClientsArray.length; i++) {
                    if (ClientsArray[i].userid.toString() == arr[1]) {
                        toSocketID = ClientsArray[i].socketid;
                        break;
                    }
                }
                io.sockets.connected[toSocketID].emit('chat message', msg);
                socket.emit('chat message', msg);
        }
        catch (err)
        {
            socket.emit('chat message', msg);

        }
    });

socket.on('id cliente', function (msg) {
    try {

        for (var i = 0; i < ClientsArray.length; i++) {
            if (ClientsArray[i].socketid.toString() == socket.id.toString()) {
                ClientsArray[i].userid = msg;
                break;
            }
        }
        socket.emit('done');
    }
    catch(err)
    {
        console.log(err);
    }
});

});

Objective C:
+(ConexionSocket_)sharedModel
{
static ConexionSocket_ ConexionCompartida = nil;
if(!ConexionCompartida)
ConexionCompartida = [[ConexionSocket alloc] init];
return ConexionCompartida;
}

-(void)IniciarConexion
{
[SIOSocket socketWithHost: @"http://104.236.96.130:9000/" response: ^(SIOSocket *socket)
{
SocketS = socket;
id _c = cliente;
SocketS.onConnect = ^()
{
[_c OnSocketConnection];
};

         SocketS.onDisconnect= ^()
         {
             [_c OnSocketDisconnect];
         };
         SocketS.onError = ^(NSDictionary* D)
         {
         };
         [SocketS on:@"chat message" callback:^(SIOParameterArray *args)
          {
               NSArray *array = [args.firstObject componentsSeparatedByString:@";-:-;"];
               Mensajes *MSJ = [[Mensajes alloc] init];
               MSJ.IdEmisor = array.firstObject;
               MSJ.IdReceptor = [array objectAtIndex:1];
               MSJ.Mensaje = array.lastObject;
               [cliente OnMensajeRecibido:MSJ];
          }];
         [SocketS on:@"done" callback:^(SIOParameterArray *args)
          {
              NSLog(@"Here");
          }];
     }];

}

-(void)enviarMensaje: (NSString_)mensaje MensajeTraducido: (NSString_)mensajeTraducido To:(id)to From:(id)from
{
[SocketS emit:@"chat message" args:@[[NSString stringWithFormat:@"%@;-:-;%@;-:-;%@;-:-;%@",from, to,mensaje, mensajeTraducido]]];
}

-(void)enviarmensajeConfirmacion: (id)idUsuario
{
@Try
{
NSArray *Arr = [NSArray arrayWithObjects:idUsuario, nil];
[SocketS emit:@"id cliente" args:Arr];
}
@catch (NSException *exception)
{
NSLog(@"Error %@", exception);
}
@finally
{
}
}

@josefrm
Copy link
Author

josefrm commented Feb 13, 2015

Note i've already changed the dispatcher on #16 but cannot emit the message (just 1 emit works) working iOS 8

What i have is 1 emit to assign the user id to socket id (this is working)
and 1 emit to send the message to a specific user (this is not)

And both work perfectly in server.

, thanks

@anuradhavasudeva
Copy link

On iOS8 - My app has become dead after updating to latest SIOSocket!! Neither am I able to send emit nor am I able to receive server call back. Old version had its own issues. Some times the client calls weren't reaching the server and vice versa due to continuous connect and disconnect cycles. Has any one implemented apps successfully on iOS using SIOSocket? Need help...

@waleedmahmood
Copy link

@anuradhavasudeva Have you been able to resolve it? In my case, UI get halted. No further interaction is possible except to kill the app and re-run. :(

@josefrm
Copy link
Author

josefrm commented Mar 30, 2015

I solved it, the problem is we trying to dispatch the events to the main queue the #16 explains how to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants