Skip to content

Commit

Permalink
Rework to tsup and publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
irdkwmnsb committed Jan 31, 2024
1 parent 125f228 commit 9901005
Show file tree
Hide file tree
Showing 16 changed files with 1,260 additions and 6,869 deletions.
1 change: 1 addition & 0 deletions packages/frontend-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
6 changes: 4 additions & 2 deletions packages/frontend-sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export {GrabberPlayerClient} from "./lib/grabber_player"
export {GrabberSocket} from "./lib/sockets"
export * from './lib/grabber_capture';
export * from './lib/grabber_player';
export * from './lib/sockets';
export * from './lib/util';
4 changes: 4 additions & 0 deletions packages/frontend-sdk/lib/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type StreamType = "desktop" | "webcam";

export type IOfferReceiveResponder = (playerId: string, offer: string, streamType: StreamType) => Promise<string>;

18 changes: 15 additions & 3 deletions packages/frontend-sdk/lib/grabber_capture.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {GrabberSocket} from "./sockets";
import {IOfferReceiveResponder, StreamType} from "./api";

export class GrabberCaptureClient { // FIXME inherit from the other client
private peerName: string;
public target: EventTarget; // FIXME: make this private and make proper on function
private socket: GrabberSocket<any>;
private offerReceiveResponder?: IOfferReceiveResponder;

constructor(peerName: string, signallingUrl?: string) {
this.peerName = peerName;
this.target = new EventTarget();
Expand All @@ -20,6 +23,11 @@ export class GrabberCaptureClient { // FIXME inherit from the other client
this.target.dispatchEvent(new CustomEvent('init_peer', {detail: {pcConfig, pingInterval}}));
};
const offer_handle = async ({offer: {peerId, offer, streamType}}: any) => { // FIXME: remove once proper types are implemented
// if (this.offerReceiveResponder === undefined) {
// console.warn("Got an incomming call, even though onOfferReceived is not called.");
// return;
// }
// await this.offerReceiveResponder(peerId, offer, streamType);
this.target.dispatchEvent(new CustomEvent('offer', {detail: {playerId: peerId, offer, streamType}}));
}
const player_ice_handle = async ({ice: {peerId, candidate}}: any) => { // FIXME: remove once proper types are implemented
Expand All @@ -31,15 +39,19 @@ export class GrabberCaptureClient { // FIXME inherit from the other client
this.socket.on("player_ice", player_ice_handle);
}

send_ping(connectionsCount: number, streamTypes: string[]) {
onOfferReceived(getAnswer: IOfferReceiveResponder) {
this.offerReceiveResponder = getAnswer;
}

sendPing(connectionsCount: number, streamTypes: string[]) {
this.socket.emit("ping", {ping: {connectionsCount: connectionsCount, streamTypes: streamTypes}});
}

send_offer_answer(playerId: string, answer: string) {
sendOfferAnswer(playerId: string, answer: string) {
this.socket.emit("offer_answer", {offerAnswer: {peerId: playerId, answer}});
}

send_grabber_ice(peerId: string, candidate: string) {
sendGrabberICE(peerId: string, candidate: string) {
this.socket.emit("grabber_ice", {ice: {peerId, candidate}});
}
}
27 changes: 23 additions & 4 deletions packages/frontend-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
{
"name": "webrtc-grabber-sdk",
"version": "0.0.1",
"version": "0.0.2",
"description": "SDK for creating and playing streams for webrtc-grabber",
"main": "index.ts",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"target": ["node18", "es2020"],
"tsup": {
"entry": [
"index.ts"
],
"target": ["node18", "es2020"],
"splitting": false,
"sourcemap": true,
"clean": true,
"dts": true,
"format": ["cjs", "esm"]
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "tsup",
"dev": "tsup --watch"
},
"repository": {
"type": "git",
Expand All @@ -19,5 +35,8 @@
"bugs": {
"url": "https://github.com/irdkwmnsb/webrtc-grabber/issues"
},
"homepage": "https://github.com/irdkwmnsb/webrtc-grabber#readme"
"homepage": "https://github.com/irdkwmnsb/webrtc-grabber#readme",
"devDependencies": {
"tsup": "^8.0.1"
}
}
2 changes: 1 addition & 1 deletion packages/frontend/pages/capture/capture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GrabberCaptureClient} from "webrtc-grabber-sdk/lib/grabber_capture";
import {GrabberCaptureClient} from "webrtc-grabber-sdk";

const webcamConstraint = {aspectRatio: 16 / 9};
const webcamAudioConstraint = true;
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/pages/index/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {GrabberPlayerClient} from "webrtc-grabber-sdk/lib/grabber_player";
import {requireAuth} from "webrtc-grabber-sdk/lib/util";
import {GrabberPlayerClient} from "webrtc-grabber-sdk";
import {requireAuth} from "webrtc-grabber-sdk";

let curGrabberId = null;
let selectedParticipantName: string | null = null;
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/pages/player/player.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {GrabberPlayerClient} from "webrtc-grabber-sdk/lib/grabber_player";
import {GrabberPlayerClient} from "webrtc-grabber-sdk";

const extractPlayerArguments = () => {
const params = new URLSearchParams(window.location.search);
Expand Down
Loading

0 comments on commit 9901005

Please sign in to comment.