Socket
Socket
Sign inDemoInstall

lanyard-wrapper

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 2.0.0

2

dist/index.browser.js

@@ -1,1 +0,1 @@

var LanyardWrapper=function(e){"use strict";function n(e,n,t,r){return new(t||(t=Promise))((function(o,s){function c(e){try{E(r.next(e))}catch(e){s(e)}}function i(e){try{E(r.throw(e))}catch(e){s(e)}}function E(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,i)}E((r=r.apply(e,n||[])).next())}))}const t={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var r,o;return function(e){e[e.EVENT=0]="EVENT",e[e.HELLO=1]="HELLO",e[e.INITIALIZE=2]="INITIALIZE",e[e.HEARTBEAT=3]="HEARTBEAT"}(r||(r={})),function(e){e.INIT_STATE="INIT_STATE",e.PRESENCE_UPDATE="PRESENCE_UPDATE"}(o||(o={})),e.connectWebSocket=function(e,n,s){if(!("WebSocket"in window||"MozWebSocket"in window))return s(new Error("Browser doesn't support WebSocket connections.")),null;const c=new WebSocket(t.WEBSOCKET_URL),i="string"==typeof e?{subscribe_to_id:e}:{subscribe_to_ids:e};let E=null;return c.addEventListener("open",(()=>{c.send(JSON.stringify({op:r.INITIALIZE,d:i})),E=setInterval((()=>{c.send(JSON.stringify({op:r.HEARTBEAT}))}),t.HEARTBEAT_PERIOD)})),c.addEventListener("message",(({data:e})=>{const{t:t,d:r}=JSON.parse(e);t!==o.INIT_STATE&&t!==o.PRESENCE_UPDATE||n(r)})),c.onclose=e=>{clearInterval(E),s(new Error(`Socket closed with code ${e.code}`))},c},e.fetchUserData=function(e){return n(this,void 0,void 0,(function*(){return new Promise(((n,r)=>{fetch(`${t.API_URL}/users/${e}`).then((e=>e.json())).then((e=>{var t;e.success||r(new Error((null===(t=e.error)||void 0===t?void 0:t.message)||"An invalid error occured")),n(e.data)})).catch((e=>r(e)))}))}))},e.fetchUserDataForMultipleUsers=function(e){return n(this,void 0,void 0,(function*(){return new Promise(((n,r)=>{const o=[];for(const s of e)fetch(`${t.API_URL}/users/${s}`).then((e=>e.json())).then((t=>{var s;t.success||r(new Error((null===(s=t.error)||void 0===s?void 0:s.message)||"An invalid error occured")),o.push(t.data),o.length===e.length&&n(o)})).catch((e=>r(e)))}))}))},e}({});
var LanyardWrapper=function(t){"use strict";function e(t,e,n,o){return new(n||(n=Promise))((function(r,i){function s(t){try{d(o.next(t))}catch(t){i(t)}}function c(t){try{d(o.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,c)}d((o=o.apply(t,e||[])).next())}))}const n={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var o,r;function i(t){var o;return e(this,void 0,void 0,(function*(){const e=yield fetch(`${n.API_URL}/users/${t}`),r=yield e.json();if(!r.success)throw new Error((null===(o=r.error)||void 0===o?void 0:o.message)||"An invalid error occured");return r.data}))}return function(t){t[t.EVENT=0]="EVENT",t[t.HELLO=1]="HELLO",t[t.INITIALIZE=2]="INITIALIZE",t[t.HEARTBEAT=3]="HEARTBEAT"}(o||(o={})),function(t){t.INIT_STATE="INIT_STATE",t.PRESENCE_UPDATE="PRESENCE_UPDATE"}(r||(r={})),t.connectWebSocket=function(t,i){return e(this,void 0,void 0,(function*(){if(!("WebSocket"in window||"MozWebSocket"in window))throw new Error("Browser doesn't support WebSocket connections.");const e=new WebSocket(n.WEBSOCKET_URL),s="string"==typeof t?{subscribe_to_id:t}:{subscribe_to_ids:t};let c=null;return e.addEventListener("open",(()=>{e.send(JSON.stringify({op:o.INITIALIZE,d:s})),c=setInterval((()=>{e.send(JSON.stringify({op:o.HEARTBEAT}))}),n.HEARTBEAT_PERIOD)})),e.addEventListener("message",(({data:t})=>{const{t:e,d:n}=JSON.parse(t);e!==r.INIT_STATE&&e!==r.PRESENCE_UPDATE||i(n)})),e.onclose=t=>{throw clearInterval(c),new Error(`Socket closed with code ${t.code}`)},e}))},t.deleteKV=function(t,o,r){return e(this,void 0,void 0,(function*(){const e=`${n.API_URL}/users/${t}/kv/${o}`,i={Authorization:r},s=yield fetch(e,{method:"DELETE",headers:i});if(!s.ok)throw new Error(`Failed to delete Lanyard KV for user ${t} and key ${o}: ${s.status} - ${yield s.text()}`)}))},t.fetchUserData=i,t.fetchUserDataForMultipleUsers=function(t){return e(this,void 0,void 0,(function*(){const e=[];for(const n of t){const t=yield i(n);e.push(t)}return e}))},t.getKV=function(t,n){return e(this,void 0,void 0,(function*(){try{return(yield i(t)).kv[n]}catch(e){throw new Error(`Failed to get Lanyard KV for user ${t} and key ${n}: ${e}`)}}))},t.mergeKV=function(t,o,r){return e(this,void 0,void 0,(function*(){const e=`${n.API_URL}/users/${t}/kv`,i={Authorization:r,"Content-Type":"application/json"},s=JSON.stringify(o),c=yield fetch(e,{method:"PATCH",headers:i,body:s});if(!c.ok)throw new Error(`Failed to merge Lanyard KV for user ${t}: ${c.status} - ${yield c.text()}`)}))},t.setKV=function(t,o,r,i){return e(this,void 0,void 0,(function*(){const e=`${n.API_URL}/users/${t}/kv/${o}`,s={Authorization:i,"Content-Type":"application/json"},c=JSON.stringify(r),d=yield fetch(e,{method:"PUT",headers:s,body:c});if(!d.ok)throw new Error(`Failed to set Lanyard KV for user ${t} and key ${o}: ${d.status} - ${yield d.text()}`)}))},t}({});

@@ -62,5 +62,69 @@ type Activity = {

};
export declare function connectWebSocket(userId: string | string[], onUpdate: (data: Data) => void, onError: (error: Error) => void): WebSocket | null;
/**
* Connects to the Lanyard WebSocket API
* @param userId The user ID to connect to
* @param onUpdate Callback function that is called when the user's presence is updated
* @returns The WebSocket connection
* @throws Error if the browser doesn't support WebSocket connections
* @throws Error if the WebSocket connection is closed
*/
export declare function connectWebSocket(userId: string | string[], onUpdate: (data: Data) => void): Promise<WebSocket>;
/**
* Fetches the user data from the Lanyard API
* @param userId The user ID to fetch the data for
* @returns The user data
* @throws Error if the request failed
*/
export declare function fetchUserData(userId: string): Promise<Data>;
/**
* Fetches the user data from the Lanyard API for multiple users
* @param userIds The user IDs to fetch the data for
* @returns The user data
* @throws Error if the request failed
* @throws Error if the request failed for one of the users
*/
export declare function fetchUserDataForMultipleUsers(userIds: string[]): Promise<Data[]>;
/**
* Fetches the user data KV from the Lanyard API
* @param userId The user ID to fetch the data for
* @param key The key to fetch the data for
* @returns The user data KV
* @throws Error if the request failed
*/
export declare function getKV(userId: string, key: string): Promise<string>;
/**
* Sets the user data KV from the Lanyard API
* @param userId The user ID to fetch the data for
* @param key The key to fetch the data for
* @param value The value to set
* @param apiKey The API key to use
* @throws Error if the request failed
* @throws Error if the API key is invalid
* @throws Error if the user ID is invalid
*/
export declare function setKV(userId: string, key: string, value: any, apiKey: string): Promise<void>;
/**
* Merges the user data KV from the Lanyard API
* @param userId The user ID to fetch the data for
* @param kvPairs The key-value pairs to merge
* @param apiKey The API key to use
* @throws Error if the request failed
* @throws Error if the API key is invalid
* @throws Error if the user ID is invalid
* @throws Error if the key-value pairs are invalid
*/
export declare function mergeKV(userId: string, kvPairs: {
[key: string]: any;
}, apiKey: string): Promise<void>;
/**
* Deletes the user data KV from the Lanyard API
* @param userId The user ID to fetch the data for
* @param key The key to fetch the data for
* @param apiKey The API key to use
* @throws Error if the request failed
* @throws Error if the API key is invalid
* @throws Error if the user ID is invalid
* @throws Error if the key is not set
*/
export declare function deleteKV(userId: string, key: string, apiKey: string): Promise<void>;
export {};

@@ -1,1 +0,1 @@

function n(n,e,t,o){return new(t||(t=Promise))((function(r,s){function c(n){try{E(o.next(n))}catch(n){s(n)}}function i(n){try{E(o.throw(n))}catch(n){s(n)}}function E(n){var e;n.done?r(n.value):(e=n.value,e instanceof t?e:new t((function(n){n(e)}))).then(c,i)}E((o=o.apply(n,e||[])).next())}))}const e={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var t,o;function r(n,r,s){if(!("WebSocket"in window||"MozWebSocket"in window))return s(new Error("Browser doesn't support WebSocket connections.")),null;const c=new WebSocket(e.WEBSOCKET_URL),i="string"==typeof n?{subscribe_to_id:n}:{subscribe_to_ids:n};let E=null;return c.addEventListener("open",(()=>{c.send(JSON.stringify({op:t.INITIALIZE,d:i})),E=setInterval((()=>{c.send(JSON.stringify({op:t.HEARTBEAT}))}),e.HEARTBEAT_PERIOD)})),c.addEventListener("message",(({data:n})=>{const{t:e,d:t}=JSON.parse(n);e!==o.INIT_STATE&&e!==o.PRESENCE_UPDATE||r(t)})),c.onclose=n=>{clearInterval(E),s(new Error(`Socket closed with code ${n.code}`))},c}function s(t){return n(this,void 0,void 0,(function*(){return new Promise(((n,o)=>{fetch(`${e.API_URL}/users/${t}`).then((n=>n.json())).then((e=>{var t;e.success||o(new Error((null===(t=e.error)||void 0===t?void 0:t.message)||"An invalid error occured")),n(e.data)})).catch((n=>o(n)))}))}))}function c(t){return n(this,void 0,void 0,(function*(){return new Promise(((n,o)=>{const r=[];for(const s of t)fetch(`${e.API_URL}/users/${s}`).then((n=>n.json())).then((e=>{var s;e.success||o(new Error((null===(s=e.error)||void 0===s?void 0:s.message)||"An invalid error occured")),r.push(e.data),r.length===t.length&&n(r)})).catch((n=>o(n)))}))}))}!function(n){n[n.EVENT=0]="EVENT",n[n.HELLO=1]="HELLO",n[n.INITIALIZE=2]="INITIALIZE",n[n.HEARTBEAT=3]="HEARTBEAT"}(t||(t={})),function(n){n.INIT_STATE="INIT_STATE",n.PRESENCE_UPDATE="PRESENCE_UPDATE"}(o||(o={}));export{r as connectWebSocket,s as fetchUserData,c as fetchUserDataForMultipleUsers};
function t(t,n,e,o){return new(e||(e=Promise))((function(r,i){function s(t){try{c(o.next(t))}catch(t){i(t)}}function d(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var n;t.done?r(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(s,d)}c((o=o.apply(t,n||[])).next())}))}const n={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var e,o;function r(r,i){return t(this,void 0,void 0,(function*(){if(!("WebSocket"in window||"MozWebSocket"in window))throw new Error("Browser doesn't support WebSocket connections.");const t=new WebSocket(n.WEBSOCKET_URL),s="string"==typeof r?{subscribe_to_id:r}:{subscribe_to_ids:r};let d=null;return t.addEventListener("open",(()=>{t.send(JSON.stringify({op:e.INITIALIZE,d:s})),d=setInterval((()=>{t.send(JSON.stringify({op:e.HEARTBEAT}))}),n.HEARTBEAT_PERIOD)})),t.addEventListener("message",(({data:t})=>{const{t:n,d:e}=JSON.parse(t);n!==o.INIT_STATE&&n!==o.PRESENCE_UPDATE||i(e)})),t.onclose=t=>{throw clearInterval(d),new Error(`Socket closed with code ${t.code}`)},t}))}function i(e){var o;return t(this,void 0,void 0,(function*(){const t=yield fetch(`${n.API_URL}/users/${e}`),r=yield t.json();if(!r.success)throw new Error((null===(o=r.error)||void 0===o?void 0:o.message)||"An invalid error occured");return r.data}))}function s(n){return t(this,void 0,void 0,(function*(){const t=[];for(const e of n){const n=yield i(e);t.push(n)}return t}))}function d(n,e){return t(this,void 0,void 0,(function*(){try{return(yield i(n)).kv[e]}catch(t){throw new Error(`Failed to get Lanyard KV for user ${n} and key ${e}: ${t}`)}}))}function c(e,o,r,i){return t(this,void 0,void 0,(function*(){const t=`${n.API_URL}/users/${e}/kv/${o}`,s={Authorization:i,"Content-Type":"application/json"},d=JSON.stringify(r),c=yield fetch(t,{method:"PUT",headers:s,body:d});if(!c.ok)throw new Error(`Failed to set Lanyard KV for user ${e} and key ${o}: ${c.status} - ${yield c.text()}`)}))}function u(e,o,r){return t(this,void 0,void 0,(function*(){const t=`${n.API_URL}/users/${e}/kv`,i={Authorization:r,"Content-Type":"application/json"},s=JSON.stringify(o),d=yield fetch(t,{method:"PATCH",headers:i,body:s});if(!d.ok)throw new Error(`Failed to merge Lanyard KV for user ${e}: ${d.status} - ${yield d.text()}`)}))}function a(e,o,r){return t(this,void 0,void 0,(function*(){const t=`${n.API_URL}/users/${e}/kv/${o}`,i={Authorization:r},s=yield fetch(t,{method:"DELETE",headers:i});if(!s.ok)throw new Error(`Failed to delete Lanyard KV for user ${e} and key ${o}: ${s.status} - ${yield s.text()}`)}))}!function(t){t[t.EVENT=0]="EVENT",t[t.HELLO=1]="HELLO",t[t.INITIALIZE=2]="INITIALIZE",t[t.HEARTBEAT=3]="HEARTBEAT"}(e||(e={})),function(t){t.INIT_STATE="INIT_STATE",t.PRESENCE_UPDATE="PRESENCE_UPDATE"}(o||(o={}));export{r as connectWebSocket,a as deleteKV,i as fetchUserData,s as fetchUserDataForMultipleUsers,d as getKV,u as mergeKV,c as setKV};

@@ -1,1 +0,1 @@

"use strict";function e(e,n,t,r){return new(t||(t=Promise))((function(o,s){function c(e){try{E(r.next(e))}catch(e){s(e)}}function i(e){try{E(r.throw(e))}catch(e){s(e)}}function E(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,i)}E((r=r.apply(e,n||[])).next())}))}const n={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var t,r;!function(e){e[e.EVENT=0]="EVENT",e[e.HELLO=1]="HELLO",e[e.INITIALIZE=2]="INITIALIZE",e[e.HEARTBEAT=3]="HEARTBEAT"}(t||(t={})),function(e){e.INIT_STATE="INIT_STATE",e.PRESENCE_UPDATE="PRESENCE_UPDATE"}(r||(r={})),exports.connectWebSocket=function(e,o,s){if(!("WebSocket"in window||"MozWebSocket"in window))return s(new Error("Browser doesn't support WebSocket connections.")),null;const c=new WebSocket(n.WEBSOCKET_URL),i="string"==typeof e?{subscribe_to_id:e}:{subscribe_to_ids:e};let E=null;return c.addEventListener("open",(()=>{c.send(JSON.stringify({op:t.INITIALIZE,d:i})),E=setInterval((()=>{c.send(JSON.stringify({op:t.HEARTBEAT}))}),n.HEARTBEAT_PERIOD)})),c.addEventListener("message",(({data:e})=>{const{t:n,d:t}=JSON.parse(e);n!==r.INIT_STATE&&n!==r.PRESENCE_UPDATE||o(t)})),c.onclose=e=>{clearInterval(E),s(new Error(`Socket closed with code ${e.code}`))},c},exports.fetchUserData=function(t){return e(this,void 0,void 0,(function*(){return new Promise(((e,r)=>{fetch(`${n.API_URL}/users/${t}`).then((e=>e.json())).then((n=>{var t;n.success||r(new Error((null===(t=n.error)||void 0===t?void 0:t.message)||"An invalid error occured")),e(n.data)})).catch((e=>r(e)))}))}))},exports.fetchUserDataForMultipleUsers=function(t){return e(this,void 0,void 0,(function*(){return new Promise(((e,r)=>{const o=[];for(const s of t)fetch(`${n.API_URL}/users/${s}`).then((e=>e.json())).then((n=>{var s;n.success||r(new Error((null===(s=n.error)||void 0===s?void 0:s.message)||"An invalid error occured")),o.push(n.data),o.length===t.length&&e(o)})).catch((e=>r(e)))}))}))};
"use strict";function t(t,e,o,n){return new(o||(o=Promise))((function(r,i){function s(t){try{d(n.next(t))}catch(t){i(t)}}function c(t){try{d(n.throw(t))}catch(t){i(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,c)}d((n=n.apply(t,e||[])).next())}))}const e={API_URL:"https://api.lanyard.rest/v1",WEBSOCKET_URL:"wss://api.lanyard.rest/socket",HEARTBEAT_PERIOD:3e4};var o,n;function r(o){var n;return t(this,void 0,void 0,(function*(){const t=yield fetch(`${e.API_URL}/users/${o}`),r=yield t.json();if(!r.success)throw new Error((null===(n=r.error)||void 0===n?void 0:n.message)||"An invalid error occured");return r.data}))}!function(t){t[t.EVENT=0]="EVENT",t[t.HELLO=1]="HELLO",t[t.INITIALIZE=2]="INITIALIZE",t[t.HEARTBEAT=3]="HEARTBEAT"}(o||(o={})),function(t){t.INIT_STATE="INIT_STATE",t.PRESENCE_UPDATE="PRESENCE_UPDATE"}(n||(n={})),exports.connectWebSocket=function(r,i){return t(this,void 0,void 0,(function*(){if(!("WebSocket"in window||"MozWebSocket"in window))throw new Error("Browser doesn't support WebSocket connections.");const t=new WebSocket(e.WEBSOCKET_URL),s="string"==typeof r?{subscribe_to_id:r}:{subscribe_to_ids:r};let c=null;return t.addEventListener("open",(()=>{t.send(JSON.stringify({op:o.INITIALIZE,d:s})),c=setInterval((()=>{t.send(JSON.stringify({op:o.HEARTBEAT}))}),e.HEARTBEAT_PERIOD)})),t.addEventListener("message",(({data:t})=>{const{t:e,d:o}=JSON.parse(t);e!==n.INIT_STATE&&e!==n.PRESENCE_UPDATE||i(o)})),t.onclose=t=>{throw clearInterval(c),new Error(`Socket closed with code ${t.code}`)},t}))},exports.deleteKV=function(o,n,r){return t(this,void 0,void 0,(function*(){const t=`${e.API_URL}/users/${o}/kv/${n}`,i={Authorization:r},s=yield fetch(t,{method:"DELETE",headers:i});if(!s.ok)throw new Error(`Failed to delete Lanyard KV for user ${o} and key ${n}: ${s.status} - ${yield s.text()}`)}))},exports.fetchUserData=r,exports.fetchUserDataForMultipleUsers=function(e){return t(this,void 0,void 0,(function*(){const t=[];for(const o of e){const e=yield r(o);t.push(e)}return t}))},exports.getKV=function(e,o){return t(this,void 0,void 0,(function*(){try{return(yield r(e)).kv[o]}catch(t){throw new Error(`Failed to get Lanyard KV for user ${e} and key ${o}: ${t}`)}}))},exports.mergeKV=function(o,n,r){return t(this,void 0,void 0,(function*(){const t=`${e.API_URL}/users/${o}/kv`,i={Authorization:r,"Content-Type":"application/json"},s=JSON.stringify(n),c=yield fetch(t,{method:"PATCH",headers:i,body:s});if(!c.ok)throw new Error(`Failed to merge Lanyard KV for user ${o}: ${c.status} - ${yield c.text()}`)}))},exports.setKV=function(o,n,r,i){return t(this,void 0,void 0,(function*(){const t=`${e.API_URL}/users/${o}/kv/${n}`,s={Authorization:i,"Content-Type":"application/json"},c=JSON.stringify(r),d=yield fetch(t,{method:"PUT",headers:s,body:c});if(!d.ok)throw new Error(`Failed to set Lanyard KV for user ${o} and key ${n}: ${d.status} - ${yield d.text()}`)}))};
{
"name": "lanyard-wrapper",
"description": "Fully-typed Lanyard API wrapper for JavaScript/TypeScript (in browser environment)",
"version": "1.0.3",
"version": "2.0.0",
"repository": "https://github.com/brokiem/lanyard-wrapper.git",

@@ -31,2 +31,3 @@ "author": "brokiem <milyhqvideo@gmail.com>",

"rollup": "^3.17.2",
"typedoc": "^0.23.25",
"typescript": "^4.9.5"

@@ -39,5 +40,6 @@ },

"lint:fix": "eslint src --ext .ts --fix",
"rollup": "rollup --config rollup.config.mjs"
"rollup": "rollup --config rollup.config.mjs",
"generate-docs": "typedoc --out docs src/index.ts"
},
"dependencies": {}
}

@@ -7,14 +7,20 @@ # Lanyard Wrapper

Looking for Node.js? Check out [node-lanyard-wrapper](https://github.com/brokiem/node-lanyard-wrapper)
Looking for Node.js version? Check out [node-lanyard-wrapper](https://github.com/brokiem/node-lanyard-wrapper)
## Features
- Fully-typed
- Supports WebSocket connection
- Supports REST API
- Supports managing Lanyard KV
## Installation
### NPM
#### NPM
```bash
npm i lanyard-wrapper
```
### Yarn
#### Yarn
```bash
yarn add lanyard-wrapper
```
## CDN
#### CDN
```html

@@ -26,2 +32,4 @@ <script src="https://cdn.jsdelivr.net/npm/lanyard-wrapper/dist/index.browser.js"></script>

Check out [Lanyard Wrapper Documentation](https://brokiem.is-a.dev/lanyard-wrapper/) for more information about the data object.
### Browser

@@ -38,10 +46,13 @@ #### Connecting with WebSocket

function onError(err) {
// err is an error object
console.error(err);
}
const ws = LanyardWrapper.connectWebSocket("USER_ID", onUpdate, onError);
LanyardWrapper.connectWebSocket("USER_ID", onUpdate)
.then(ws => {
// ws is a WebSocket object
console.log(ws);
})
.catch(err => {
console.error(err);
});
</script>
```
<br>

@@ -71,7 +82,11 @@ #### OR Using the REST API

### CommonJS
### CommonJS / ES Modules / TypeScript
#### Connecting with WebSocket
```js
```ts
// Use require() if you are using CommonJS
const LanyardWrapper = require("lanyard-wrapper");
// Use import if you are using ES Modules
import { connectWebSocket } from "lanyard-wrapper";
function onUpdate(data) {

@@ -82,17 +97,6 @@ // data is a Lanyard data object

function onError(err) {
// err is an error object
console.error(err);
}
const ws = LanyardWrapper.connectWebSocket("USER_ID", onUpdate, onError);
```
#### OR Using the REST API
```js
const LanyardWrapper = require("lanyard-wrapper");
LanyardWrapper.fetchUserData("USER_ID")
.then(data => {
console.log(data);
connectWebSocket("USER_ID", onUpdate)
.then(ws => {
// ws is a WebSocket object
console.log(ws);
})

@@ -102,32 +106,11 @@ .catch(err => {

});
LanyardWrapper.fetchUserDataForMultipleUsers(["USER_ID_1", "USER_ID_2"])
.then(data => {
console.log(data);
})
.catch(err => {
console.error(err);
});
```
<br>
### ES Modules / TypeScript
#### Connecting with WebSocket
#### OR Using the REST API
```ts
import { connectWebSocket } from "lanyard-wrapper";
// Use require() if you are using CommonJS
const LanyardWrapper = require("lanyard-wrapper");
function onUpdate(data) {
// data is a Lanyard data object
console.log(data);
}
function onError(err) {
// err is an error object
console.error(err);
}
const ws = connectWebSocket("USER_ID", onUpdate, onError);
```
#### OR Using the REST API
```ts
// Use import if you are using ES Modules
import { fetchUserData, fetchUserDataForMultipleUsers } from "lanyard-wrapper";

@@ -134,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc