# Signal

Stelace Signal enables real-time communication on your Web platform, from messaging use cases to more mission-critical notifications.

Signal API relies on Websocket and more precisely socket.io you should use for your client implementation, with JavaScript example below.

In a nutshell, any device using your platform can create or join channels and send a signal to destination being one of available channels. A signal can have message content of any type and some event string name exposed to your client.

You can find more details and a simple use case in our open-source Heroes starter kit. A Workflow notifies super hero status changes to any Web browser currently on the live demo in real-time.

# JavaScript client

You can authenticate and receive any signal sent to my_friends channel using the following code snippet:

import io from 'socket.io-client'

io('https://api.stelace.com/signal', {
  path: '/signal',
  transports: ['websocket']
})

io.on('authentication', function (id, subscribeCb) {
  if (typeof subscribeCb === "function") {
    subscribeCb({
      channel: "my_friends", // or ["my_friends", 'customers"]
      // channels added to default channel of which name is id value
      publishableKey: "pubk_test_…" // use a valid publishable API key here
      authToken: 'optional User token' // to authenticate as a user
      // and automatically join the channel of which name is user ID.
    })
  }
  console.log('unique WebSocket id to target user’s current browser', id)
})

io.on('signal', function(data) { // default event name
  // message you send via Signal API is available as data.message
  console.log(data, socket.id)
})

// custom event name you can use for specific logic
io.on('customName', function(data) {
  console.log('custom', data, socket.id)
})

# Emit signal

Here is how you can send a signal to the previous client:

curl https://api.stelace.com/signal \
  -u seck_test_rylx3ebUg0bNs1HkJKlqNHkI: \
  -d event=customName \
  -d destination=my_friends \
  -d message="Hello world"

More details are available in API reference API .