yii-node-socket icon indicating copy to clipboard operation
yii-node-socket copied to clipboard

Command console

Open Sirgalas opened this issue 8 years ago • 9 comments

Help me please! You have specified in the documentation that you want to use the console command ./yiic help node-socket terminal or console shows me an errorbash: ./yiic: No such file or directory. On that I use this command./yii help node-socket is a mistake or not . And how right? Sorry for my English translator google :)

Sirgalas avatar Sep 22 '16 06:09 Sirgalas

Hi, seems like mistake, is it working?

oncesk avatar Sep 22 '16 06:09 oncesk

Hi, thanks for the reply . Socket term. Others are not . To this question I can arrange that on a message in the frontend part and use the information that the message was in the backend . And what kind of data can be transferred ?

Sirgalas avatar Sep 22 '16 13:09 Sirgalas

Finally Sorry for molestation . I correctly understand that I can use your code socket.on () as the soceket.on as in node.js. And where it is used in the controller or in views. Popravte me if I'm wrong . But I can see the use of after if (Yii :: $ app-> request-> post ()) { in any action, controllers.

Sirgalas avatar Sep 22 '16 13:09 Sirgalas

Hi, i am not fully understand your questions, but socket.on used only on client side and by nodejs server,.

oncesk avatar Sep 23 '16 04:09 oncesk

Google translator :) you have written in documentation

Now events can be created only on PHP side. All data transmitted in json format. Into callback function data was pasted as javascript native object (or string, integer, depends of your PHP Frame config)

// Add event listener
socket.on ( 'updateBoard', function (data) {
    // Do any action
});

The question is which is used in the controller or node.js, and that's where these events are used

socket.onConnect (function () {
    // Fire when connection established
});

socket.onDisconnect (function () {
    // Fire when connection close or lost
});

socket.onConnecting (function () {
    // Fire when the socket is attempting to connect with the server
});

socket.onReconnect (function () {
    // Fire when successfully reconnected to the server
});

Sirgalas avatar Sep 23 '16 15:09 Sirgalas

this events should be used on frontend

Predefined events

socket.onConnect (function () {
    // Fire when connection established
});

socket.onDisconnect (function () {
    // Fire when connection close or lost
});

socket.onConnecting (function () {
    // Fire when the socket is attempting to connect with the server
});

socket.onReconnect (function () {
    // Fire when successfully reconnected to the server
});

Custom event which was sent from php or other js client

socket.on('updateBoard', function () {});

oncesk avatar Sep 23 '16 17:09 oncesk

This event

// Add event listener
socket.on ( 'updateBoard', function (data) {
    // Do any action
});

is used in the js or php

Sirgalas avatar Sep 23 '16 17:09 Sirgalas

in js

oncesk avatar Sep 23 '16 18:09 oncesk

And that

Rooms
socket.onConnect(function () {
    socket.room('testRoom').join(function (success, numberOfRoomSubscribers) {
        // success - boolean, numberOfRoomSubscribers - number of room members
        // if error occurred then success = false, and numberOfRoomSubscribers - contains error message
        if (success) {
            console.log(numberOfRoomSubscribers + ' clients in room: ' + roomId);
            // do something

            // bind events
            this.on('join', function (newMembersCount) {
                // fire on client join
            });

            this.on('data', function (data) {
                // fire when server send frame into this room with 'data' event
            });
        } else {
            // numberOfRoomSubscribers - error message
            alert(numberOfRoomSubscribers);
        }
    });
});

Sirgalas avatar Sep 24 '16 04:09 Sirgalas