Giter Site home page Giter Site logo

Comments (12)

retendo avatar retendo commented on May 5, 2024 2

socket.channel('realtime:public') works, though. Just omit the last colon.

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024 2

Yeah especially in authorization. We are working on it now, so it's good to get more perspectives/approaches.

Thanks for pitching in here. If you get stuck with anything else just let us know. I'll leave this to close unless you have anything remaining

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024

Hey @retendo ! Thanks for persisting long enough to make it work.

// related to node/browser difference?

You nailed it. The example at the the top is for "browser" JS and the one at the bottom is for "server" JS.

As a short (not entirely accurate) history of JS: at the start Javascript was only really used to do little things in the browser (little animations). Then people started building whole websites with it.

Then google thought.. perhaps we can run this JS on a server too, not just in a browser? So they created a "subset" of Javascript - nodejs, and they created an "engine" which could run it called v8.

But NodeJS doesn't really have the same "dialect". (Look up CommonJS vs AMD vs UMD.) This is why tools like babel exist. They "translate" JS between the different JS dialects.

Anyhow - you nailed it with the require('@supabase/realtime-js'); for Node

If you have a nice simple example working, perhaps you could even add it as a node-js example in the /examples folder? We're very open to contributors.

from realtime.

retendo avatar retendo commented on May 5, 2024

I think the more important change should be the ".channel" in between join() and on( ... ).
This seems unrelated to node.js/browser differences.
Or is this somehow working in the browser?
It seems that .join() returns a Push object instead of a Channel.

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024

I'll have to check this out. Do you have an existing repo that I can fork? If it's private no probs, I'll create a small express demo in this repo

from realtime.

retendo avatar retendo commented on May 5, 2024

Got some example code right here:
https://gist.github.com/retendo/3e2ddb90a29dfd0f5a2ab81729c7ed29

This works with the adjusted sample code

from realtime.

Overdozed avatar Overdozed commented on May 5, 2024

in addition to that wildcart paths doest work on channel path.
socket.channel('realtime:public:users') -> works
socket.channel('') -> broken
socket.channel('realtime:
') -> broken
socket.channel('realtime:public:*') -> broken

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024

Hey @retendo sorry for the incommunicado - I'm looking at this & building a basic nodejs example now, but probably won't finish until tomorrow morning my time.

FYI: These shouldn't work

socket.channel('') -> broken
socket.channel('realtime:') -> broken
socket.channel('realtime:public:*') -> broken (see realtime:public below)

But these should

socket.channel('realtime:*') -> listen to changes in the database
socket.channel('realtime:public') -> listen to changes in the public schema
socket.channel('realtime:public:users') -> listen to changes in the users table

Use the "on" to listen to different "event types". Using the code in your gist:

// INSERTS
socket.channel('realtime:public')
  .join()
  .channel
  .on('INSERT', payload => {});

// UPDATES
socket.channel('realtime:public')
  .join()
  .channel
  .on('UPDATE', payload => {});

// DELETES
socket.channel('realtime:public')
  .join()
  .channel
  .on('DELETE', payload => {});

// ALL 
socket.channel('realtime:public')
  .join()
  .channel
  .on('*', payload => {});

Hope that helps a bit! I haven't tested your code yet but it looks great! I see exactly where you're going with it - creating a proxy (maybe for auth purposes?)

from realtime.

retendo avatar retendo commented on May 5, 2024

For auth, specialized socket APIs that hide the underlying database structure and some payload modifications.

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024

Small example pushed for you @retendo. I used your code as a baseline so thanks for contributing

think the more important change should be the ".channel" in between join() and on( ... ).

Check out the difference between my first commit and my second: d4c9ece

Basically socket.channel() returns the channel, and socket.channel.join() returns the join event. So you were "accessing" the channel through the join event.

Please keep me update on your proxy - if you can keep it generic enough I'll add it to the examples folder.

from realtime.

retendo avatar retendo commented on May 5, 2024

That makes sense. In the original browser based example it was all chained together, so I tried to replicate it that way. But the changes in your second commit actually make it clearer.

Regarding the proxy example: I’ll see what I can do. You are probably most interested in how authentication fits into the picture, right? Because the other things that I mentioned should be straightforward.

from realtime.

kiwicopple avatar kiwicopple commented on May 5, 2024

Closing now, feel free to reopen at any stage

from realtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.