yiicod / yii2-socketio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to connect to server from browser?

shoxabbos opened this issue · comments

How to connect to server from browser?
here is my code

// Connect to socket.io
            var socket = io.connect('http://d.xcd.uz:1367/notifications');

            socket.on('connect', () => {
			  	console.log('hi');
			});

            socket.on('update_notification_count', function(data){
		        console.log(data)
		    });
            
            $("p").click(function () {
            	socket.emit('mark_as_read_notification', {id: 10});
            	console.log('clicked');
            });

But I'm getting errors on the console

polling-xhr.js:264 GET http://d.xcd.uz:1367/socket.io/?EIO=3&transport=polling&t=ME8OMmo 0 ()

Check Asset, configuration, npm packages. I can not understand anything by your error.

Client says that namespace invalid

http://prntscr.com/jlfyeo

this is my client code

http://prntscr.com/jlfytq

Here is my console conf

  'components' => [
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'log' => [
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db, 	    
       
    ],
    'params' => $params,
    'controllerMap' => [
    	'socketio' => [
            'class' => \yiicod\socketio\commands\WorkerCommand::class,
            'server' => 'd.xcd.uz:1367'
        ],
    ],

web config file

'components' => [
        'broadcastEvents' => [
            'class' => \yiicod\socketio\EventManager::class,
            'nsp' => 'some_unique_key',
            // Namespaces with events folders
            'namespaces' => [
                'app\events',
            ]
        ],
        
        'broadcastDriver' => [
            'class' => \yiicod\socketio\drivers\RedisDriver::class,
            'hostname' => 'localhost',
            'port' => 6379,
        ],
]

And I run this command from controller

\yiicod\socketio\Broadcast::emit(\app\events\CountEvent::name(), ['count' => 10]);

I copied all files from the example. What is the problem I do not understand? (((
Please help me 😢😢😢😢

All daemons && workers are works! You can see it here
http://prntscr.com/jlg24e

Check this runtime/logs/exceptions.log. I think the problem on the server side. Right now i don't have any other suggestions

one more, if you run daemon and after add event class, then you have to remove all daemons and stop all process and rerun pm2. You should do it every time when you add/update you event classes

I solve it ))

What was the problem?