@fishjam-cloud/js-server-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Fishjam server SDK for JavaScript
1
+ # Fishjam Cloud Server SDK for JavaScript
2
2
 
3
- JavaScript server-side SDK for [Fishjam](https://github.com/fishjam-cloud/fishjam).
3
+ JavaScript server-side SDK for [Fishjam Cloud](https://cloud.fishjam.stream).
4
4
 
5
5
  ## Installation
6
6
 
@@ -10,41 +10,25 @@ You can install the library using `npm`:
10
10
  npm install @fishjam-cloud/js-server-sdk
11
11
  ```
12
12
 
13
+ or `yarn`:
14
+
15
+ ```bash
16
+ yarn add @fishjam-cloud/js-server-sdk
17
+ ```
18
+
13
19
  ## Documentation
14
20
 
15
- The documentation for the latest release is available [here](https://fishjam-cloud.github.io/js-server-sdk/latest).
21
+ The documentation for the latest release is available [here](https://fishjam-cloud.github.io/js-server-sdk/).
16
22
  To generate it locally, run:
17
23
 
18
24
  ```bash
19
- npm run docs
25
+ yarn docs
20
26
  ```
21
27
 
22
- For more comprehensive tutorial on the Fishjam Server, its capabilites and production usage, refer to
23
- [Fishjam docs](https://fishjam-cloud.github.io/fishjam-docs/).
24
-
25
28
  ## Examples
26
29
 
27
30
  See [examples](https://github.com/fishjam-cloud/js-server-sdk/tree/main/examples) directory.
28
31
 
29
- ## Fishjam ecosystem
30
-
31
- | | |
32
- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
33
- | 📱 Client SDKs | [TypeScript](https://github.com/fishjam-cloud/ts-client-sdk/) <br/> [React](https://github.com/fishjam-cloud/react-client-sdk) <br/> [iOS](https://github.com/fishjam-cloud/ios-client-sdk) <br/> [Android](https://github.com/fishjam-cloud/android-client-sdk) <br/> [React Native](https://github.com/fishjam-cloud/react-native-client-sdk) |
34
- | ⚙️ Server SDKs | [JavaScript](https://github.com/fishjam-cloud/js-server-sdk) <br/> [Python](https://github.com/fishjam-cloud/python-server-sdk) <br/> [Elixir](https://github.com/fishjam-cloud/elixir_server_sdk) |
35
- | 📚 Resources | [Fishjam Docs](https://fishjam-cloud.github.io/fishjam-docs/) <br/> [Membrane Framework](https://membrane.stream/) <br/> [Join Membrane Discord!](https://discord.gg/nwnfVSY) |
36
- | 🪼 Services | [Videoroom](https://github.com/fishjam-cloud/fishjam-videoroom) <br/> A videoconferencing app built on top of Fishjam <br/><br/> [Dashboard](https://github.com/fishjam-cloud/fishjam-dashboard) <br/> An all-around development tool for Fishjam |
37
-
38
- ## Contributing
39
-
40
- We welcome contributions to this SDK. Please report any bugs or issues you find or feel free to make a pull request
41
- with your own bug fixes or features.
42
-
43
- ### Releasing new versions
44
-
45
- To release a new version of the package, go to `Actions` > `Release package` workflow and trigger it with the chosen release type.
46
- The workflow will bump the package version in `package.json`, release the package to NPM, create a new git tag and a GitHub release.
47
-
48
32
  ## Copyright and License
49
33
 
50
34
  Copyright 2024, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=fishjam)
@@ -0,0 +1 @@
1
+ import{ServerMessage as s,ServerMessage_AuthRequest as t,ServerMessage_EventType as v}from"@fishjam-cloud/fishjam-proto";export{s as a,t as b,v as c};
@@ -0,0 +1,62 @@
1
+ import { Peer, RoomConfig, PeerOptions } from '@fishjam-cloud/fishjam-openapi';
2
+ export { Peer, PeerOptions, PeerStatus, RoomConfig } from '@fishjam-cloud/fishjam-openapi';
3
+ import TypedEmitter from 'typed-emitter';
4
+ import { ServerMessage } from '@fishjam-cloud/fishjam-proto';
5
+
6
+ type Room = {
7
+ id: string;
8
+ peers: Peer[];
9
+ config: RoomConfig;
10
+ };
11
+ type FishjamConfig = {
12
+ fishjamUrl: string;
13
+ serverToken: string;
14
+ };
15
+
16
+ declare const allowedNotifications: readonly ["roomCreated", "roomDeleted", "roomCrashed", "peerAdded", "peerDeleted", "peerConnected", "peerDisconnected", "peerMetadataUpdated", "peerCrashed", "trackAdded", "trackRemoved", "trackMetadataUpdated"];
17
+ type ErrorEventHandler = (msg: Error) => void;
18
+ type CloseEventHandler = (code: number, reason: string) => void;
19
+ type NotificationEvents = Record<(typeof allowedNotifications)[number], (message: ServerMessage) => void>;
20
+ declare const FishjamWSNotifier_base: new () => TypedEmitter<NotificationEvents>;
21
+ declare class FishjamWSNotifier extends FishjamWSNotifier_base {
22
+ private readonly client;
23
+ constructor(config: FishjamConfig, onError: ErrorEventHandler, onClose: CloseEventHandler, onConnectionFailed: ErrorEventHandler);
24
+ private dispatchNotification;
25
+ private setupConnection;
26
+ private isAllowedNotification;
27
+ }
28
+
29
+ declare class FishjamClient {
30
+ private readonly roomApi;
31
+ constructor(config: FishjamConfig);
32
+ createPeer(roomId: string, options?: PeerOptions): Promise<{
33
+ peer: Peer;
34
+ token: string;
35
+ }>;
36
+ createRoom(config?: RoomConfig): Promise<Room>;
37
+ getAllRooms(): Promise<Room[]>;
38
+ getRoom(roomId: string): Promise<Room>;
39
+ deletePeer(roomId: string, peerId: string): Promise<void>;
40
+ deleteRoom(roomId: string): Promise<void>;
41
+ }
42
+
43
+ declare class BaseException extends Error {
44
+ constructor(message: string);
45
+ }
46
+ declare class BadRequestException extends BaseException {
47
+ constructor();
48
+ }
49
+ declare class UnauthorizedException extends BaseException {
50
+ constructor();
51
+ }
52
+ declare class RoomNotFoundException extends BaseException {
53
+ constructor();
54
+ }
55
+ declare class PeerNotFoundException extends BaseException {
56
+ constructor();
57
+ }
58
+ declare class ServiceUnavailableException extends BaseException {
59
+ constructor();
60
+ }
61
+
62
+ export { BadRequestException, FishjamClient, type FishjamConfig, FishjamWSNotifier, PeerNotFoundException, type Room, RoomNotFoundException, ServiceUnavailableException, UnauthorizedException };
package/dist/index.d.ts CHANGED
@@ -1 +1,62 @@
1
- export * from "./openapi";
1
+ import { Peer, RoomConfig, PeerOptions } from '@fishjam-cloud/fishjam-openapi';
2
+ export { Peer, PeerOptions, PeerStatus, RoomConfig } from '@fishjam-cloud/fishjam-openapi';
3
+ import TypedEmitter from 'typed-emitter';
4
+ import { ServerMessage } from '@fishjam-cloud/fishjam-proto';
5
+
6
+ type Room = {
7
+ id: string;
8
+ peers: Peer[];
9
+ config: RoomConfig;
10
+ };
11
+ type FishjamConfig = {
12
+ fishjamUrl: string;
13
+ serverToken: string;
14
+ };
15
+
16
+ declare const allowedNotifications: readonly ["roomCreated", "roomDeleted", "roomCrashed", "peerAdded", "peerDeleted", "peerConnected", "peerDisconnected", "peerMetadataUpdated", "peerCrashed", "trackAdded", "trackRemoved", "trackMetadataUpdated"];
17
+ type ErrorEventHandler = (msg: Error) => void;
18
+ type CloseEventHandler = (code: number, reason: string) => void;
19
+ type NotificationEvents = Record<(typeof allowedNotifications)[number], (message: ServerMessage) => void>;
20
+ declare const FishjamWSNotifier_base: new () => TypedEmitter<NotificationEvents>;
21
+ declare class FishjamWSNotifier extends FishjamWSNotifier_base {
22
+ private readonly client;
23
+ constructor(config: FishjamConfig, onError: ErrorEventHandler, onClose: CloseEventHandler, onConnectionFailed: ErrorEventHandler);
24
+ private dispatchNotification;
25
+ private setupConnection;
26
+ private isAllowedNotification;
27
+ }
28
+
29
+ declare class FishjamClient {
30
+ private readonly roomApi;
31
+ constructor(config: FishjamConfig);
32
+ createPeer(roomId: string, options?: PeerOptions): Promise<{
33
+ peer: Peer;
34
+ token: string;
35
+ }>;
36
+ createRoom(config?: RoomConfig): Promise<Room>;
37
+ getAllRooms(): Promise<Room[]>;
38
+ getRoom(roomId: string): Promise<Room>;
39
+ deletePeer(roomId: string, peerId: string): Promise<void>;
40
+ deleteRoom(roomId: string): Promise<void>;
41
+ }
42
+
43
+ declare class BaseException extends Error {
44
+ constructor(message: string);
45
+ }
46
+ declare class BadRequestException extends BaseException {
47
+ constructor();
48
+ }
49
+ declare class UnauthorizedException extends BaseException {
50
+ constructor();
51
+ }
52
+ declare class RoomNotFoundException extends BaseException {
53
+ constructor();
54
+ }
55
+ declare class PeerNotFoundException extends BaseException {
56
+ constructor();
57
+ }
58
+ declare class ServiceUnavailableException extends BaseException {
59
+ constructor();
60
+ }
61
+
62
+ export { BadRequestException, FishjamClient, type FishjamConfig, FishjamWSNotifier, PeerNotFoundException, type Room, RoomNotFoundException, ServiceUnavailableException, UnauthorizedException };
package/dist/index.js CHANGED
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./openapi"), exports);
1
+ "use strict";var C=Object.create;var v=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var T=Object.getPrototypeOf,M=Object.prototype.hasOwnProperty;var _=(t,e)=>{for(var o in e)v(t,o,{get:e[o],enumerable:!0})},y=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of N(e))!M.call(t,s)&&s!==o&&v(t,s,{get:()=>e[s],enumerable:!(r=S(e,s))||r.enumerable});return t};var E=(t,e,o)=>(o=t!=null?C(T(t)):{},y(e||!t||!t.__esModule?v(o,"default",{value:t,enumerable:!0}):o,t)),j=t=>y(v({},"__esModule",{value:!0}),t);var H={};_(H,{BadRequestException:()=>m,FishjamClient:()=>w,FishjamWSNotifier:()=>g,Peer:()=>i.Peer,PeerNotFoundException:()=>f,PeerOptions:()=>i.PeerOptions,PeerStatus:()=>i.PeerStatus,RoomConfig:()=>i.RoomConfig,RoomNotFoundException:()=>u,ServiceUnavailableException:()=>h,UnauthorizedException:()=>l});module.exports=j(H);var i=require("@fishjam-cloud/fishjam-openapi");var x=E(require("websocket")),b=require("events");var n=require("@fishjam-cloud/fishjam-proto");var F=["roomCreated","roomDeleted","roomCrashed","peerAdded","peerDeleted","peerConnected","peerDisconnected","peerMetadataUpdated","peerCrashed","trackAdded","trackRemoved","trackMetadataUpdated"],g=class extends b.EventEmitter{client;constructor(e,o,r,s){super(),this.client=new x.client;let R=`${e.fishjamUrl.replace("http","ws")}/socket/server/websocket`;this.client.on("connectFailed",p=>s(p)),this.client.on("connect",p=>this.setupConnection(p,e.serverToken,o,r)),this.client.connect(R)}dispatchNotification(e){if(e.type=="utf8"){console.warn("UTF-8 is an invalid notification type");return}try{let o=n.ServerMessage.toJSON(n.ServerMessage.decode(e.binaryData)),[r]=Object.keys(o);if(!this.isAllowedNotification(r))return;this.emit(r,o)}catch(o){console.error("Couldn't decode websocket server message."),console.error(o),console.error(e)}}setupConnection(e,o,r,s){let R=n.ServerMessage.encode({authRequest:{token:o}}).finish(),p=n.ServerMessage.encode({subscribeRequest:{eventType:n.ServerMessage_EventType.EVENT_TYPE_SERVER_NOTIFICATION}}).finish();e.send(R),e.send(p),e.on("message",d=>this.dispatchNotification(d)),e.on("error",d=>r(d)),e.on("close",(d,k)=>s(d,k))}isAllowedNotification(e){return F.includes(e)}};var P=E(require("axios")),A=require("@fishjam-cloud/fishjam-openapi");var a=class extends Error{constructor(e){super(e),this.name=this.constructor.name}},m=class extends a{constructor(){super("Invalid request body structure")}},l=class extends a{constructor(){super("Unauthorized")}},u=class extends a{constructor(){super("Room not found")}},f=class extends a{constructor(){super("Peer not found")}},h=class extends a{constructor(){super("Service unavailable")}};var c=(t,e)=>{switch(t){case 400:throw new m;case 401:throw new l;case 404:switch(e){case"peer":throw new f;case"room":throw new u;default:return}case 503:throw new h;default:return}};var w=class{roomApi;constructor(e){let o=P.default.create({validateStatus:r=>[200,201,400,401,404,503].includes(r),headers:{Authorization:`Bearer ${e.serverToken}`}});this.roomApi=new A.RoomApi(void 0,e.fishjamUrl,o)}async createPeer(e,o={}){let r=await this.roomApi.addPeer(e,{type:"webrtc",options:o});c(r.status);let{data:{data:s}}=r;return{peer:s.peer,token:s.token}}async createRoom(e={}){let o=await this.roomApi.createRoom(e);c(o.status);let{data:{data:{room:{components:r,...s}}}}=o;return s}async getAllRooms(){let e=await this.roomApi.getAllRooms();return c(e.status),e.data.data.map(({components:o,...r})=>r)??[]}async getRoom(e){let o=await this.roomApi.getRoom(e);c(o.status,"room");let{components:r,...s}=o.data.data;return s}async deletePeer(e,o){let r=await this.roomApi.deletePeer(e,o);c(r.status,"peer")}async deleteRoom(e){let o=await this.roomApi.deleteRoom(e);c(o.status,"room")}};0&&(module.exports={BadRequestException,FishjamClient,FishjamWSNotifier,Peer,PeerNotFoundException,PeerOptions,PeerStatus,RoomConfig,RoomNotFoundException,ServiceUnavailableException,UnauthorizedException});
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{a as d,c as g}from"./chunk-PVJVFZZS.mjs";import{Peer as I,PeerStatus as q,RoomConfig as z,PeerOptions as V}from"@fishjam-cloud/fishjam-openapi";import*as R from"websocket";import{EventEmitter as E}from"events";var b=["roomCreated","roomDeleted","roomCrashed","peerAdded","peerDeleted","peerConnected","peerDisconnected","peerMetadataUpdated","peerCrashed","trackAdded","trackRemoved","trackMetadataUpdated"],v=class extends E{client;constructor(e,o,t,r){super(),this.client=new R.client;let h=`${e.fishjamUrl.replace("http","ws")}/socket/server/websocket`;this.client.on("connectFailed",a=>r(a)),this.client.on("connect",a=>this.setupConnection(a,e.serverToken,o,t)),this.client.connect(h)}dispatchNotification(e){if(e.type=="utf8"){console.warn("UTF-8 is an invalid notification type");return}try{let o=d.toJSON(d.decode(e.binaryData)),[t]=Object.keys(o);if(!this.isAllowedNotification(t))return;this.emit(t,o)}catch(o){console.error("Couldn't decode websocket server message."),console.error(o),console.error(e)}}setupConnection(e,o,t,r){let h=d.encode({authRequest:{token:o}}).finish(),a=d.encode({subscribeRequest:{eventType:g.EVENT_TYPE_SERVER_NOTIFICATION}}).finish();e.send(h),e.send(a),e.on("message",c=>this.dispatchNotification(c)),e.on("error",c=>t(c)),e.on("close",(c,y)=>r(c,y))}isAllowedNotification(e){return b.includes(e)}};import x from"axios";import{RoomApi as P}from"@fishjam-cloud/fishjam-openapi";var n=class extends Error{constructor(e){super(e),this.name=this.constructor.name}},p=class extends n{constructor(){super("Invalid request body structure")}},m=class extends n{constructor(){super("Unauthorized")}},l=class extends n{constructor(){super("Room not found")}},u=class extends n{constructor(){super("Peer not found")}},f=class extends n{constructor(){super("Service unavailable")}};var i=(s,e)=>{switch(s){case 400:throw new p;case 401:throw new m;case 404:switch(e){case"peer":throw new u;case"room":throw new l;default:return}case 503:throw new f;default:return}};var w=class{roomApi;constructor(e){let o=x.create({validateStatus:t=>[200,201,400,401,404,503].includes(t),headers:{Authorization:`Bearer ${e.serverToken}`}});this.roomApi=new P(void 0,e.fishjamUrl,o)}async createPeer(e,o={}){let t=await this.roomApi.addPeer(e,{type:"webrtc",options:o});i(t.status);let{data:{data:r}}=t;return{peer:r.peer,token:r.token}}async createRoom(e={}){let o=await this.roomApi.createRoom(e);i(o.status);let{data:{data:{room:{components:t,...r}}}}=o;return r}async getAllRooms(){let e=await this.roomApi.getAllRooms();return i(e.status),e.data.data.map(({components:o,...t})=>t)??[]}async getRoom(e){let o=await this.roomApi.getRoom(e);i(o.status,"room");let{components:t,...r}=o.data.data;return r}async deletePeer(e,o){let t=await this.roomApi.deletePeer(e,o);i(t.status,"peer")}async deleteRoom(e){let o=await this.roomApi.deleteRoom(e);i(o.status,"room")}};export{p as BadRequestException,w as FishjamClient,v as FishjamWSNotifier,I as Peer,u as PeerNotFoundException,V as PeerOptions,q as PeerStatus,z as RoomConfig,l as RoomNotFoundException,f as ServiceUnavailableException,m as UnauthorizedException};
@@ -0,0 +1 @@
1
+ export { ServerMessage, ServerMessage_AuthRequest, ServerMessage_EventType } from '@fishjam-cloud/fishjam-proto';
@@ -0,0 +1 @@
1
+ export { ServerMessage, ServerMessage_AuthRequest, ServerMessage_EventType } from '@fishjam-cloud/fishjam-proto';
package/dist/proto.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";var a=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var o=Object.prototype.hasOwnProperty;var p=(r,e)=>{for(var v in e)a(r,v,{get:e[v],enumerable:!0})},u=(r,e,v,g)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of S(e))!o.call(r,t)&&t!==v&&a(r,t,{get:()=>e[t],enumerable:!(g=M(e,t))||g.enumerable});return r};var _=r=>u(a({},"__esModule",{value:!0}),r);var f={};p(f,{ServerMessage:()=>s.ServerMessage,ServerMessage_AuthRequest:()=>s.ServerMessage_AuthRequest,ServerMessage_EventType:()=>s.ServerMessage_EventType});module.exports=_(f);var s=require("@fishjam-cloud/fishjam-proto");0&&(module.exports={ServerMessage,ServerMessage_AuthRequest,ServerMessage_EventType});
package/dist/proto.mjs ADDED
@@ -0,0 +1 @@
1
+ import{a,b,c}from"./chunk-PVJVFZZS.mjs";export{a as ServerMessage,b as ServerMessage_AuthRequest,c as ServerMessage_EventType};
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/js-server-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Fishjam server SDK for JavaScript",
5
5
  "homepage": "https://github.com/fishjam-cloud/js-server-sdk",
6
+ "author": "Fishjam Cloud Team",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "https://github.com/fishjam-cloud/js-server-sdk.git"
@@ -24,28 +25,41 @@
24
25
  ],
25
26
  "exports": {
26
27
  ".": "./dist/index.js",
27
- "./proto": "./dist/protos/fishjam/index.js"
28
+ "./proto": "./dist/proto.js"
28
29
  },
29
30
  "scripts": {
30
- "build": "tsc",
31
- "build:check": "tsc --noEmit",
31
+ "build": "tsup",
32
32
  "format": "prettier --write .",
33
33
  "format:check": "prettier --check .",
34
- "docs": "typedoc src src/protos/fishjam",
35
- "gen:proto": "sh codegen/protobuf.sh",
36
- "gen:api": "sh codegen/openapi.sh",
37
- "prepare": "tsc"
34
+ "typecheck": "tsc --noEmit"
35
+ },
36
+ "tsup": {
37
+ "entry": [
38
+ "src/index.ts",
39
+ "src/proto.ts"
40
+ ],
41
+ "dts": true,
42
+ "minify": true,
43
+ "format": [
44
+ "cjs",
45
+ "esm"
46
+ ],
47
+ "outDir": "dist"
38
48
  },
39
49
  "dependencies": {
50
+ "@fishjam-cloud/fishjam-openapi": "0.1.1",
51
+ "@fishjam-cloud/fishjam-proto": "0.1.0",
40
52
  "axios": "^1.6.8",
41
- "protobufjs": "^7.2.6"
53
+ "websocket": "^1.0.35"
42
54
  },
43
55
  "devDependencies": {
44
56
  "@openapitools/openapi-generator-cli": "^2.13.4",
45
57
  "@types/node": "^20.12.7",
58
+ "@types/websocket": "^1.0.10",
46
59
  "prettier": "3.2.5",
47
- "ts-proto": "^1.172.0",
60
+ "tsup": "^8.1.0",
61
+ "typed-emitter": "^2.1.0",
48
62
  "typedoc": "^0.25.13",
49
- "typescript": "^5.4.5"
63
+ "typescript": "~5.4.5"
50
64
  }
51
- }
65
+ }