peers / peerjs-server

Server for PeerJS
https://peerjs.com
MIT License
4.33k stars 1.08k forks source link

Custom message to Client? #28

Closed ken-okabe closed 10 years ago

ken-okabe commented 10 years ago

Hi, basically, I'd like to implement AUTH bootstrap in server.js PeerServer.prototype._initializeWSS such as

  if (true) // true for auth passed
            {
                socket.send(JSON.stringify(
                {
                    type: 'SUCCESS',   //got WARNING You received an unrecognized message: [object Object]
                    payload:
                    {
                        msg: id + ': Authorizaton Success'
                    }
                }));

                f(); // go on the rest
            }
            else
            {
                socket.send(JSON.stringify(
                {
                    type: 'ERROR',   //works fine as it is
                    payload:
                    {
                        msg: id + ': Authorizaton Failed'
                    }
                }));
                socket.close();
                return;
            }

However, in this sample, I tried type: 'SUCCESS' and which is unrecognized message at client side. WARNING You received an unrecognized message: [object Object]

Having googled for a while to find definition of the type, I could not find them. All the type I can find in the server.js code is type: 'ERROR', type: 'ID-TAKEN', and type: 'OPEN' seems to do nothing.

I need to grab a server status for my own implementation in the context of the Connection status: http://cdn.peerjs.com/demo/chat.html

How can we do this?? The types must be defined somewhere in the code, but somehow I can't find it, so please advise.

I've read https://github.com/peers/peerjs-server/pull/10 by the way, but no clue. Thanks.

michelle commented 10 years ago

Hey Ken,

You'll have to edit the server and client side code to recognize those messages. If you'll notice, we switch on the message type to decide how to process the message on both sides. Since SUCCESS is not yet a recognized type, you're getting that message.

Michelle

On Tue, Dec 10, 2013 at 12:16 AM, Ken OKABE notifications@github.comwrote:

Hi, basically, I'd like to implement AUTH bootstrap in server.js PeerServer.prototype._initializeWSS such as

if (true) // true for auth passed { socket.send(JSON.stringify( { type: 'SUCCESS', payload: { msg: id + ': Authorizaton Success' } }));

            f(); // go on the rest
        }
        else
        {
            socket.send(JSON.stringify(
            {
                type: 'ERROR',
                payload:
                {
                    msg: id + ': Authorizaton Failed'
                }
            }));
            socket.close();
            return;
        }

However, in this sample, I tried type: 'SUCCESS' and which is unrecognized message at client side. WARNING You received an unrecognized message: [object Object]

Having googled for a while to find definition of the type, I could not find them. All the type I can find in the server.js code is type: 'ERROR', type: 'ID-TAKEN', and type: 'OPEN' seems to do nothing.

I need to grab a server status for my own implementation in the context of the Connection status: http://cdn.peerjs.com/demo/chat.html

How can we do this??

I've read

10 https://github.com/peers/peerjs-server/pull/10

by the way, but no clue. Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/peers/peerjs-server/issues/28 .

ken-okabe commented 10 years ago

Michelle,

Thanks for reply. I investigated only in server side, but found where to tweak in client side.

https://github.com/peers/peerjs/blob/master/lib/peer.js

Thanks!

michelle commented 10 years ago

https://github.com/peers/peerjs/blob/master/lib/peer.js#L146

That should be what you're looking for! Good luck.

Michelle

On Tue, Dec 10, 2013 at 12:48 PM, Ken OKABE notifications@github.comwrote:

Michelle,

Thanks for reply. I investigated only in server side, but found where to tweak in client side.

https://github.com/peers/peerjs/blob/master/lib/peer.js

Thanks!

— Reply to this email directly or view it on GitHubhttps://github.com/peers/peerjs-server/issues/28#issuecomment-30266348 .

ken-okabe commented 10 years ago

Thanks again, Michelle.

peer.js is one of the best project around. Just in case you haven't noticed, one of the major mobile company in Japan - NTT Communications has employed your project. http://www.us.ntt.com/en/index.html https://github.com/nttcom https://github.com/nttcom/peerjs http://nttcom.github.io/skyway/

Keep up the good work!

michelle commented 10 years ago

Thanks for using us! :)

Michelle

On Tue, Dec 10, 2013 at 2:33 PM, Ken OKABE notifications@github.com wrote:

Thanks again, Michelle.

peer.js is one of the best project around. Just in case you haven't noticed, one of the major mobile company in Japan

Keep up the good work!

— Reply to this email directly or view it on GitHubhttps://github.com/peers/peerjs-server/issues/28#issuecomment-30275281 .