<commit_before>CCPomeloWrapper
===============

A simple libpomelo wrapper for cocos2d-x

Great thanks to https://github.com/xdxttt/CCPomelo

<commit_msg>add sample<commit_after>CCPomeloWrapper
===============

A simple libpomelo wrapper for cocos2d-x

Great thanks to https://github.com/xdxttt/CCPomelo


How to use

0. setup your cocos2d-x project with libpomelo supported first
1. add CCPomeloWrapper.cpp/h to your project
2. sample code for connecting with chatofpomelo-websocket:

connect to gate:
```
void SampleScene::testMenuClicked(cocos2d::CCObject* pSender)
{
    if(CCPomeloWrapper::getInstance()->connect("dev1.laoyur.ml", 3014)) //you can use my sample dev server to test
    {
        CCLOG("connect failed ");
    }
    else
    {
        const char *route = "gate.gateHandler.queryEntry";
        Json::Value msg;  //you need to include "jsoncpp.h"
        Json::FastWriter writer;
        
        msg["uid"] = "1"; //your uid
        
        CCPomeloWrapper::getInstance()->request(route, writer.write(msg), this,  pomelo_req_result_cb_selector(SampleScene::queryEntryCB));
    }
}

void SampleScene::queryEntryCB(const CCPomeloRequestResult& result)
{
    CCLOG("queryEntry %s", result.jsonMsg.c_str());
    
    Json::Value root;
    Json::Reader reader;
    if(reader.parse(result.jsonMsg, root))
    {
        if(root["code"].asInt() == 200)
        {
            string host = root["host"].asString();
            int port = root["port"].asInt();
            
            //stop gate connection
            CCPomeloWrapper::getInstance()->stop();
            
            //connect to connector
            //we use async connect version here
            CCPomeloWrapper::getInstance()->connectAsnyc(host.c_str(), port, this, pomelo_async_conn_cb_selector(SampleScene::connectCB));
            
            //sync connect version
            /*
            if(CCPomeloWrapper::getInstance()->connect(host.c_str(), port) == 0)
            {
                Json::Value msg;
                Json::FastWriter writer;
                
                msg["rid"] = "1";
                msg["username"] = "user1";
                
                CCPomeloWrapper::getInstance()->request("connector.entryHandler.enter", writer.write(msg), this, pomelo_req_result_cb_selector(SampleScene::entryCB));
            }
            else
            {
                //error
            }
             */
        }
    }
}

void SampleScene::connectCB(int result)
{
    //now we need to listen to 'disconnect' event
    CCPomeloWrapper::getInstance()->setDisconnectedCallback(this, callfunc_selector(SampleScene::onConnLost));
    
    Json::Value msg;
    Json::FastWriter writer;
    
    msg["rid"] = "1"; //room id
    msg["username"] = "user1";
    
    CCPomeloWrapper::getInstance()->request("connector.entryHandler.enter", writer.write(msg), this, pomelo_req_result_cb_selector(SampleScene::entryCB));
}

void SampleScene::entryCB(const CCPomeloRequestResult& result)
{
    CCLOG("entryCB %s", result.jsonMsg.c_str());
    
    //listen to chat event
    CCPomeloWrapper::getInstance()->addListener("onChat",this,  pomelo_listener_cb_selector(SampleScene::onChat));
    
    //we simply send message to all to test
    Json::Value msg;
    Json::FastWriter writer;
    
    msg["content"] = "hello CCPomelo";
    msg["target"] = "*";  //send to all
    
    const char *route = "chat.chatHandler.send";

    CCPomeloWrapper::getInstance()->request(route, writer.write(msg), this,  pomelo_req_result_cb_selector(SampleScene::sendCB));
}

void SampleScene::sendCB(const CCPomeloRequestResult& result)
{
    CCLOG("%s: %s", result.requestRoute.c_str(), result.jsonMsg.c_str());
}

void SampleScene::onChat(const CCPomeloEvent& event)
{
    CCLOG("%s: %s", event.event.c_str(), event.jsonMsg.c_str());
}

void SampleScene::onConnLost()
{
    CCLOG("connection lost");
}
{'fraction_non_alphanumeric': 0.138259526261586, 'fraction_numerical': 0.005406797116374871, 'mean_word_length': 2.838932806324111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7160252', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1172, 'n_words': 234}