Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Implement callback function to convert to JSON #116

Open
ThomasG77 opened this issue Jul 15, 2020 · 0 comments
Open

Implement callback function to convert to JSON #116

ThomasG77 opened this issue Jul 15, 2020 · 0 comments

Comments

@ThomasG77
Copy link

ThomasG77 commented Jul 15, 2020

The expected websocket response is JSON. I received some data from a third party websocket that does not use JSON but I want to convert it before.

Changing
https://github.com/nathantsoi/vue-native-websocket/blob/master/src/Observer.js#L33-L36

    if (this.format === 'json') {
      let transformFunction = function transformFunction(content) {
        return content
      };
      if ('transformFunction' in this) {
        transformFunction = this.transformFunction
      }
      if (!('sendObj' in this.WebSocket)) {
        this.WebSocket.sendObj = (obj) => this.WebSocket.send(JSON.stringify(transformFunction(obj)))
      }
    }

Tell me what you think about the proposition

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

No branches or pull requests

1 participant