File tree Expand file tree Collapse file tree 2 files changed +72
-0
lines changed
Expand file tree Collapse file tree 2 files changed +72
-0
lines changed Original file line number Diff line number Diff line change 1+ import { ConnectionInfo , ResponseMessage } from '../../libs/interfaces'
2+ import { RealtimeClient } from '../../libs'
3+ import { getAuthToken , config } from './../config'
4+
5+ const client = new RealtimeClient ( {
6+ websocketOptions : {
7+ maxRetries : 10 ,
8+ urlProvider : async ( ) => {
9+ const ACCESS_TOKEN = getAuthToken (
10+ config . WEBSOCKET_CLIENTS_SIGNING_KEY ,
11+ 5 ,
12+ {
13+ permissions : [ ] ,
14+ } ,
15+ config . ALGORITHM ,
16+ )
17+
18+ return `wss://${ config . CLUSTER_HOSTNAME } /apps/${ config . APP_ID } ?access_token=${ ACCESS_TOKEN } `
19+ } ,
20+ } ,
21+ } )
22+
23+ client . on ( 'session.started' , async ( info : ConnectionInfo ) => {
24+ // request time to server
25+ const [ res ] = await client
26+ . send ( '' , {
27+ messageType : 'gettime' ,
28+ } )
29+ . waitForReply ( )
30+
31+ console . log ( 'Server Time:' , res as ResponseMessage )
32+
33+ client . disconnect ( )
34+ } )
35+
36+ client . connect ( )
Original file line number Diff line number Diff line change 1+ import { ConnectionInfo , ReplyFunction } from './../../libs/interfaces'
2+ import { RealtimeClient } from './../../libs'
3+ import { getAuthToken , config } from './../config'
4+
5+ const client = new RealtimeClient ( {
6+ websocketOptions : {
7+ maxRetries : 10 ,
8+ urlProvider : async ( ) => {
9+ const ACCESS_TOKEN = getAuthToken (
10+ config . WEBSOCKET_CLIENTS_SIGNING_KEY ,
11+ 5 ,
12+ {
13+ permissions : [
14+ 'realtime:publisher:write:topic:priv/*' ,
15+ 'realtime:subscriber:read:topic:secure/inbound' ,
16+ ] ,
17+ } ,
18+ config . ALGORITHM ,
19+ )
20+
21+ return `wss://${ config . CLUSTER_HOSTNAME } /apps/${ config . APP_ID } ?access_token=${ ACCESS_TOKEN } `
22+ } ,
23+ } ,
24+ } )
25+
26+ client . on ( 'session.started' , async ( info : ConnectionInfo ) => {
27+ client . subscribeRemoteTopic ( 'secure/inbound' )
28+ } )
29+
30+ client . on ( 'secure/inbound.gettime' , async ( _ , reply : ReplyFunction ) => {
31+ console . log ( 'Responding to gettime request...' )
32+
33+ await reply ( new Date ( ) . toISOString ( ) , 'ok' ) . waitForAck ( )
34+ } )
35+
36+ client . connect ( )
You can’t perform that action at this time.
0 commit comments