npm i ew-sdk
import { EWServer } from 'ew-sdk'
const server = new EWServer({
encryption: 'AUTO' | 'NONE' | { publicKey: '', privateKey: '' },
log: false | true,
serverLocation: 'INDIA-CENTRAL',
})
server.connect(SERVER_TOKEN, [
{
name: "topic1",
},
...
])
server.connect()
is an async method. SERVER_TOKEN
will be provided from the dashboard after adding your server. All the configuration will be fetched from cloud. You can use you RSA keypairs or use AUTO encryption mode for SDK to generate keypairs automatically.
This is an event based custom authentication hook. You can access or use query section of Client for custom authentication.
server.customAuthentication(({ query, client_socket_id }) => {
// some calculation
// authentication code
return true | false
})
This method can be used to recieve messages from any clients.
server.on_client_msg(data => {})
await server.broadcast(data)
await server.publish(topicName, data)
import { EWClient } from "ew-sdk"
const client = new EWClient({
namespace: NAMESPACE,
log: false | true,
serverLocation: "INDIA-CENTRAL",
})
await client.connect({
token: CLIENT_TOKEN,
type: "ANONYMOUS",
ref: "SERVER",
topics: [
{
name: "topic1",
},
...
],
query:{
...
}
})
You can use query section for any data to pass along with the connection request. It can also be used for custom authentication.
Note: Client automatically syncs encryption settings with the server its connected to.
await client.subscribe(['Topic1', 'Topic2',...])
await client.unsubscribe(['Topic1', 'Topic2',...])
client.on(topicName, (...publishedData) => {})
Note: You can have multiple hooks on same topic!
client.onBroadcast((...broadcastedData) => {})
Note: You can have multiple hooks.
await client.send(data)
If E2EE is on, SDK will handle the encryption and decryption of data automatically.