Skip to content
New issue

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

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

Already on GitHub? # to your account

need function emitBinary in nsConn.Room #13

Open
cainiaoDJ opened this issue Jan 12, 2021 · 0 comments
Open

need function emitBinary in nsConn.Room #13

cainiaoDJ opened this issue Jan 12, 2021 · 0 comments

Comments

@cainiaoDJ
Copy link

I found nsConn has a function named emitBinary which can tarnsform data by binary. And I saw it in _examples\protobuf\browser\app.js. So I did a practice. But It doesn't work in nsConn.Room. My code like this

var room = "default_room"
sendBtn.onclick = function () {
    const input = inputTxt.value;
    inputTxt.value = "";
    var pbMsg = new proto.protobuf.ChatMsg();
    pbMsg.setMsgtype(10000).setMsgbody(input);
    addMessage("Me: " + input + " --room " + room);

    // work correct
    nsConn.emitBinary("OnChat", pbMsg.serializeBinary());
   
    //error becasue emitBinary undefined
    nsConn.room(room).emitBinary("OnChat",pbMsg.serializeBinary())
};

I read the examples again, and found this way to send a binary data in examle.

let message = new Message();
message.Namespace = "default";
message.Event = "OnChat";
message.Body = pbMsg.serializeBinary();
message.SetBinary = true;
message.Room = room;
nsConn.conn.write(message);

it works, Great!

But I want an easy way to write this code. So I changed neffos.js to implement Room.emitBinary.

var Room = function () {
    function a(a, b) {
        this.nsConn = a, this.name = b
    }

    return a.prototype.emit = function (a, b) {
        var c = new Message;
        return c.Namespace = this.nsConn.namespace, c.Room = this.name, c.Event = a, c.Body = b, this.nsConn.conn.write(c)
    },a.prototype.emitBinary = function (a, b) {
        var c = new Message;
        return c.Namespace = this.nsConn.namespace, c.Room = this.name, c.Event = a, c.Body = b, c.SetBinary = !0, this.nsConn.conn.write(c)
    }, a.prototype.leave = function () {
        var a = new Message;
        return a.Namespace = this.nsConn.namespace, a.Room = this.name, a.Event = OnRoomLeave, this.nsConn.askRoomLeave(a)
    }, a
}()

just add a.prototype.emitBinary, it works.
I am not familiar with typescripts, so I make an issue whitout pull request.

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

No branches or pull requests

1 participant