Skip to content

Commit

Permalink
feat: add rollup plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
zhensherlock committed Apr 25, 2023
1 parent fed5df6 commit f45a75b
Show file tree
Hide file tree
Showing 12 changed files with 10,327 additions and 1,831 deletions.
11,906 changes: 10,092 additions & 1,814 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 22 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,29 @@
},
"homepage": "https://github.com/zhensherlock/webrtc-streamer-helper#readme",
"devDependencies": {
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-eslint": "^9.0.3",
"@rollup/plugin-node-resolve": "^15.0.2",
"@rollup/plugin-strip": "^3.0.2",
"@rollup/plugin-typescript": "^11.0.0",
"@typescript-eslint/parser": "^5.56.0",
"concurrently": "^7.6.0",
"@rollup/plugin-terser": "^0.4.1",
"@rollup/plugin-typescript": "^11.1.0",
"@typescript-eslint/parser": "^5.59.1",
"autoprefixer": "^10.4.14",
"concurrently": "^8.0.1",
"cssnano": "^6.0.0",
"eslint-config-semistandard": "^17.0.0",
"rollup": "^3.20.0",
"typescript": "^5.0.2"
}
"rollup": "^3.21.0",
"rollup-plugin-filesize": "^10.0.0",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-sass": "^1.12.19",
"typescript": "^5.0.4"
},
"browserslist": [
"defaults",
"not ie < 8",
"last 2 versions",
"> 1%",
"iOS 7",
"last 3 iOS versions"
]
}
63 changes: 55 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,72 @@
import filesize from 'rollup-plugin-filesize'
import typescript from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'
import strip from '@rollup/plugin-strip'
import eslint from '@rollup/plugin-eslint'
import babel from '@rollup/plugin-babel'
import terser from '@rollup/plugin-terser'
import postcss from 'rollup-plugin-postcss'
import autoprefixer from 'autoprefixer'
import cssnano from 'cssnano'
// import sass from 'rollup-plugin-sass'

const output = [
{
format: 'esm',
file: 'dist/webrtc-streamer-helper.esm.js'
},
{
format: 'umd',
name: 'webrtc-streamer-helper',
file: 'dist/webrtc-streamer-helper.umd.js'
},
{
format: 'iife',
file: 'dist/webrtc-streamer-helper.browser.js'
},
{
format: 'esm',
file: 'dist/webrtc-streamer-helper.esm.min.js',
plugins: [terser()]
},
{
format: 'umd',
name: 'webrtc-streamer-helper',
file: 'dist/webrtc-streamer-helper.umd.min.js',
plugins: [terser()]
},
{
format: 'iife',
file: 'dist/webrtc-streamer-helper.browser.min.js',
plugins: [terser()]
}
]

export default [
{
input: 'src/main.ts',
output: [
{
file: 'dist/webrtc-streamer-helper.esm.js',
format: 'esm'
}
],
output,
plugins: [
eslint({
throwOnError: true,
throwOnWarning: true,
include: ['src/**'],
exclude: ['node_modules/**']
exclude: ['node_modules/**', 'src/style/**']
}),
resolve(),
strip(),
typescript()
typescript(),
postcss({
plugins: [
autoprefixer(),
cssnano()
]
}),
// sass({
// insert: true
// }),
babel({ babelHelpers: 'runtime', exclude: ['node_modules/**'] }),
filesize()
]
}
]
140 changes: 140 additions & 0 deletions src/core/webRTCStreamer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { WebRTCStreamerOptions } from '../types'
// import { initialOptions } from '../utils/initialization'

export default class WebRTCStreamer {
// private element: Element
// private options: WebRTCStreamerOptions
//
// private pc: any
// private mediaConstraints = { offerToReceiveAudio: true, offerToReceiveVideo: true }
// private iceServers = null
// private earlyCandidates = []
constructor (args: Partial<WebRTCStreamerOptions> = {}) {
const a = 1
const b = 1
const c = a + b
document.title = c.toString()
// this.options = Object.assign({}, initialOptions, args)
// this.changeElement(this.options.element)
}

// connect (videURL, audioURL, options, localStream) {
// this.disconnect()
//
// if (!this.iceServers) {
// fetch(`${this.options.url}/api/getIceServers`)
// .then(this.handleHttpErrors)
// .then((res) => (res.json()))
// .then((resp) => this.onReceiveGetIceServers(resp, videURL, audioURL, options, localStream))
// .catch((error) => this.onError(`getIceServers ${error}`))
// } else {
// this.onReceiveGetIceServers(this.iceServers, videURL, audioURL, options, localStream);
// }
// }
//
// disconnect () {
// if (this.element?.srcObject) {
// this.element.srcObject.getTracks().forEach(track => {
// track.stop()
// this.element.srcObject.removeTrack(track)
// })
// }
// if (this.pc) {
// fetch(`${this.options.url}/api/hangup?peerid=${this.pc.peerid}`)
// .then(this.handleHttpErrors)
// .catch((error) => this.onError(`hangup ${error}`))
//
// try {
// this.pc.close()
// }
// catch (e) {
// console.log(`Failure close peer connection:${e}`)
// }
// this.pc = null
// }
// }
//
// private changeElement (ele: Element | string) {
// if (typeof ele === 'string') {
// const dom = document.querySelector(ele)
// dom && (this.element = dom)
// } else {
// this.element = ele
// }
// }
//
// private handleHttpErrors (resp) {
// if (!resp.ok) {
// throw Error(resp.statusText)
// }
// return resp
// }
//
// private onReceiveGetIceServers (iceServers, videourl, audiourl, options, stream) {
// this.iceServers = iceServers;
// this.pcConfig = iceServers || {"iceServers": [] };
// try {
// this.createPeerConnection();
//
// var callurl = this.srvurl + "/api/call?peerid=" + this.pc.peerid + "&url=" + encodeURIComponent(videourl);
// if (audiourl) {
// callurl += "&audiourl="+encodeURIComponent(audiourl);
// }
// if (options) {
// callurl += "&options="+encodeURIComponent(options);
// }
//
// if (stream) {
// this.pc.addStream(stream);
// }
//
// // clear early candidates
// this.earlyCandidates.length = 0;
//
// // create Offer
// this.pc.createOffer(this.mediaConstraints).then((sessionDescription) => {
// console.log("Create offer:" + JSON.stringify(sessionDescription));
//
// this.pc.setLocalDescription(sessionDescription)
// .then(() => {
// fetch(callurl, { method: "POST", body: JSON.stringify(sessionDescription) })
// .then(this.handleHttpErrors)
// .then( (response) => (response.json()) )
// .catch( (error) => this.onError("call " + error ))
// .then( (response) => this.onReceiveCall(response) )
// .catch( (error) => this.onError("call " + error ))
//
// }, (error: any) => {
// console.log ("setLocalDescription error:" + JSON.stringify(error));
// });
//
// }, (error: any) => {
// alert("Create offer error: " + JSON.stringify(error));
// });
//
// } catch (e) {
// this.disconnect()
// alert('connect error: ' + e)
// }
// }
//
// private onError(status: any) {
// console.log(`onError:${status}`)
// }
//
// private onReceiveCall(dataJson) {
// console.log("offer: " + JSON.stringify(dataJson));
// var descr = new RTCSessionDescription(dataJson);
// this.pc.setRemoteDescription(descr).then(() => {
// console.log ("setRemoteDescription ok");
// while (this.earlyCandidates.length) {
// var candidate = this.earlyCandidates.shift();
// this.addIceCandidate(this.pc.peerid, candidate);
// }
//
// this.getIceCandidate()
// }, (error) => {
// console.log ("setRemoteDescription error:" + JSON.stringify(error))
// })
// }
}
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default {
text: 'hello world!'
}
import WebRTCStreamer from './core/webRTCStreamer'
import './style'

export default WebRTCStreamer
4 changes: 4 additions & 0 deletions src/style/foo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
body {
background-color: red;
display: flex;
}
1 change: 1 addition & 0 deletions src/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './foo.scss'
4 changes: 4 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface WebRTCStreamerOptions {
element: Element | string;
url: string;
}
3 changes: 3 additions & 0 deletions src/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"//": "this file is here to make typescript happy when moduleResolution=node16+"
}
Empty file added src/utils/bootstrap.ts
Empty file.
Empty file added src/utils/index.ts
Empty file.
2 changes: 2 additions & 0 deletions src/utils/initialization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const initialOptions = {
}

0 comments on commit f45a75b

Please sign in to comment.