0.8.0 • Published 1 year ago
@sociably/websocket v0.8.0
WebSocket Module
This package is an underlying module of webview platform for serving WebSocket.
You might want to use @sociably/webview
unless you want to serve your own web service.
Install
npm install @sociably/core @sociably/http @sociably/websocket
# or with yarn
yarn add @sociably/core @sociably/http @sociably/websocket
Docs
Check the package reference.
Setup
Back-end
import Sociably from '@sociably/core';
import Http from '@sociably/http';
import WebSocket from '@sociably/websocket';
const DEV = process.env.NODE_ENV !== 'production';
const app = Sociably.createApp({
modules: [
Http.initModule({ /* ... */ }),
],
platforms: [
WebSocket.initModule({ entryPath: '/websocket' }),
],
service: [
{ // same origin policy
provide: WebSocket.UpgradeVerifier,
withValue: ({ headers }) => headers.origin === 'https://your.domain.com',
},
]
}).onEvent(async ({ bot, event }) => {
// send a event when a connection is open
if (event.type === 'connect') {
await bot.send({
category: 'greeting',
type: 'hello',
payload: 'world',
});
}
});
Front-end
import Client from '@sociably/websocket/client';
const client = new Client({ url: '/websocket' });
client.onEvent(async ({ event }) => {
if (event.type === 'hello') {
await client.send({
category: 'greeting',
type: 'hello',
payload: 'websocket',
});
}
});
0.9.0-alpha.46
1 year ago
0.9.0-alpha.0
2 years ago
0.9.0-alpha.4
2 years ago
0.9.0-alpha.5
2 years ago
0.9.0-alpha.6
2 years ago
0.9.0-alpha.26
2 years ago
0.9.0-alpha.12
2 years ago
0.9.0-alpha.13
2 years ago
0.8.0
2 years ago
0.8.0-alpha.15
2 years ago
0.8.0-alpha.28
2 years ago
0.8.0-alpha.43
2 years ago
0.8.0-alpha.10
2 years ago
0.8.0-alpha.12
2 years ago
0.8.0-alpha.8
2 years ago
0.8.0-alpha.0
3 years ago
0.8.0-alpha.1
3 years ago
0.7.1
3 years ago
0.7.0
3 years ago