mattermost / mattermost-redux

Redux for Mattermost

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Promise returned from wsClient.initialize doesn't resolve on connect

Hunga1 opened this issue · comments

Summary

Mattermost websocket client (client/websocket_client.js) initialize method does not resolve its returned promise if a firstConnectCallback function property is not set.

Environment Information

  • Webapp or React Native app: N/A
  • Mattermost Server Version: 4.7.1

Steps to reproduce

Using the node.js Usage steps highlighted in the README, add an additional promise chain then block after the wsClient.initialize call. The returned promise from initialize only resolves if a firstConnectCallback is set.

// ...
.then(function(){
    return wsClient.initialize(token, {}, {}, {connectionUrl: 'wss://your-mattermost-url.com/api/v4/websocket'});
})
.then(function() {
  console.log('wsClient.initialize method resolved its promise!')
})
// ...

Expected behavior

The initialize method returns a Promise that should resolve when the websocket connection is complete and successful.

Observed behavior

Any promise resolve method does not execute when the websocket does successfully finish connecting.

Possible fixes

Line 104 in src/client/websocket_client.js creates a conditional that is ultimately responsible for executing the promise resolve when the websocket connects, but can only execute if a firstConnectCallback function is set and exists.

It seems like a pretty straight forward change though. I can submit a PR for this if you'd like.

Sorry about that!

PR’s are always welcome ;)