@auxilium/socket-client
v1.0.0
Published
Client library to communicate with Datalynk's socket server
Downloads
67
Readme
Socket Client
Client library for communicating with Datalynk's Socket Server.
Setup
Prerequisites
Instructions
- Install library:
npm install --save @auxilium/socket-client
Prerequisites
Instructions
- Install dependencies:
npm install
- Build or watch library:
npm run [build|watch]
- Create an npm link:
npm link
- Install library to client for testing:
npm link @auxilium/client-socket
Quick Start
Minimal
import { AuxiliumSocketClient } from '@auxilium/socket-client';
const socket = new AuxiliumSocketClient('Optional URL Override, defaults to production');
Angular Wrapper
import { Injectable } from '@angular/core';
import { AuxiliumSocketClient} from '@auxilium/socket-client';
@Injectable({
providedIn: 'root'
})
export class SocketService extends AuxiliumSocketClient {
constructor() {
super('Optional URL Override, defaults to production');
}
}
const socket = new SocketService();
Examples
// call this if your token changes
socket.resume("1uf0dfbhr1g2efdoihqdubovsq", "sandbox");
// listen to records changing...
socket.onRecordChanges(52116, "sandbox")
.subscribe(
(changes: SliceRecordChanges) => {
console.log('heard changes', changes);
})
// listens to comment changes on a slice
socket.onCommentChanges(slice: number, spoke = this.defaultSpokeName);
// listens to changes on the slice itself (note, still janky)
socket.onSliceChanges(slice: number, spoke = this.defaultSpokeName);
Notes
socketId
is a readonly property that is set when a connection to the server is established. if you attach this to your api call request objectreq.socket = socket.socketId
, it will be theoriginator
in the response calls- where arguments accept spokes, if not provided, they will default to the one set in the
defaultSpoke
... so... if you're only doing shit on one spoke, set it..