question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make the "receive" function available to caller

See original GitHub issue

Hello, I just started playing with phoenix’s channels and found a small issue with this library. I try to get information from the reply of the “join” call. According to the doc, this could be done using the receive function :

channel.join()
  .receive("ok", resp => { console.log("Joined successfully", resp) })

But when I try to use ember-phoenix :

const channel = this.joinChannel("room:123", {
  nickname: "Mike"
  })
  .receive("ok", resp => { console.log("Joined successfully", resp) });

this throws a “receive function is not defined” So I had to make ember-phoenix return the channel.join() object instead of the channel object, and it works. But now, to access the channel object itself, I have to do this :

    const channel = this.joinChannel("room:123", {
      nickname: "Mike"
    });
    // add message handlers
    channel.channel.on("notification", () => _onNotification(...arguments));

Is there a more “elegant” way to address this issue ? Thanks !

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
bkboothcommented, Dec 19, 2017

I just ran into this issue. I ended up writing my own joinChannel() method in my service that extends PhoenixSocket and made it return a Promise so that I can know if the connection worked or not:

joinChannel(name, params) {
  return new Ember.RSVP.Promise((resolve, reject) => {
    const socket = get(this, 'socket')
    Ember.assert('Must connect to a socket first', socket)

    const channel = socket.channel(name, params)
    channel.join()
      .receive('ok', () => resolve(channel))
      .receive('error', (message) => reject(new Error(message)))
  })
},
0reactions
greyhwndzcommented, Jun 28, 2017

any say on this? @mike-north

Read more comments on GitHub >

github_iconTop Results From Across the Web

Function.prototype.caller - JavaScript - MDN Web Docs - Mozilla
The caller accessor property of Function instances represents the function that invoked this function. For strict, arrow, async, and generator ...
Read more >
Call Function (GNU make)
The call function is unique in that it can be used to create new parameterized functions. You can write a complex expression as...
Read more >
Make variables declared in caller function available in the ...
For logging purposes, I will write a f2() function that will be called by f1(). My f2() function will refer back to f1()...
Read more >
Make & receive phone calls - Phone app Help - Google Support
You can make phone calls from the Phone app and other apps or widgets that show your contacts. Wherever you see a phone...
Read more >
How to use low level call for contract function ... - Kush's blog
function myFunction(uint _x, address _addr) public returns(uint, uint) { // do something return (a, b); } // function signature string should ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found