@impleotv/stanag-player 0.1.6 → 0.1.8

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.
@@ -1,16 +1,24 @@
1
1
  /// <reference types="react" />
2
+ export interface StreamType {
3
+ videoWidth: number;
4
+ videoHeight: number;
5
+ }
2
6
  export interface StanagPlayerProps {
3
7
  serverUrl?: string;
8
+ width: number;
9
+ defaultAspectRatio?: number;
4
10
  controls?: boolean;
5
11
  autoplay?: boolean;
6
12
  iceServers?: string;
7
- onDataReceive?(packetTime: string, klvs: JSON): any;
8
- onConnected?(isConnected: boolean): any;
9
- onError?(error: string): any;
13
+ onDataReceive?(packetTime: string, klvs: JSON): void;
14
+ onConnected?(isConnected: boolean): void;
15
+ onStreamInfo?(streamIfo: StreamType): void;
16
+ onError?(error: string): void;
10
17
  }
11
18
  declare const StanagPlayer: {
12
19
  (props: StanagPlayerProps): JSX.Element;
13
20
  defaultProps: {
21
+ width: number;
14
22
  controls: boolean;
15
23
  autoplay: boolean;
16
24
  iceServers: string;
@@ -3,6 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
3
  declare const _default: ComponentMeta<{
4
4
  (props: import("./StanagPlayer").StanagPlayerProps): JSX.Element;
5
5
  defaultProps: {
6
+ width: number;
6
7
  controls: boolean;
7
8
  autoplay: boolean;
8
9
  iceServers: string;
@@ -12,6 +13,7 @@ export default _default;
12
13
  export declare const Player: ComponentStory<{
13
14
  (props: import("./StanagPlayer").StanagPlayerProps): JSX.Element;
14
15
  defaultProps: {
16
+ width: number;
15
17
  controls: boolean;
16
18
  autoplay: boolean;
17
19
  iceServers: string;
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t=n(e),o=function(n){var o=e.useRef(null),r=e.useRef(!0),c={iceServers:[{urls:n.iceServers}]};e.useEffect((function(){try{a.ontrack=function(e){var t=document.createElement(e.track.kind);t.srcObject=e.streams[0],t.muted=!0,t.autoplay=n.autoplay,t.controls=n.controls,t.addEventListener("pause",(function(e){r.current=!0})),t.addEventListener("play",(function(e){r.current=!1})),o.current.appendChild(t)},a.onconnectionstatechange=function(e){return console.log(a.iceConnectionState)},a.oniceconnectionstatechange=function(e){return console.log(a.iceConnectionState)},a.onicegatheringstatechange=function(e){return console.log(a.iceGatheringState)},a.addTransceiver("video",{direction:"sendrecv"});var e=a.createDataChannel("klv");e.binaryType="arraybuffer",e.onclose=function(){return console.log("dataChannel has closed")},e.onopen=function(){return console.log("dataChannel has opened")},e.onmessage=function(e){if(!r.current){var t=new DataView(e.data),o=new TextDecoder("utf8"),c=JSON.parse(o.decode(t)),a=(c.packetTime,c.klvs);n.onDataReceive&&n.onDataReceive(new Date(a[2]/1e3).toISOString(),a)}};var t=n.serverUrl?n.serverUrl:window.location.origin,c=new URL(t),i="ws";"http:"!=c.protocol&&(i+="s");var s=new WebSocket(i+"://".concat(c.host,"/ws"));s.onmessage=function(e){var n=JSON.parse(e.data);if(!n)return console.log("failed to parse msg");n.candidate?a.addIceCandidate(n):a.setRemoteDescription(n)},s.onerror=function(e){console.log("Websocket Error.")},s.onclose=function(e){n.onConnected&&n.onConnected(!1),1e3!=e.code&&(n.onError&&console.log("Websocket closed: ".concat(e.code)),n.onError("Websocket error: ".concat(e.code)))},a.onicecandidate=function(e){e.candidate&&""!==e.candidate.candidate&&s.send(JSON.stringify(e.candidate))},s.onopen=function(){n.onConnected&&n.onConnected(!0),a.createOffer().then((function(e){a.setLocalDescription(e),s.send(JSON.stringify(e))}))}}catch(e){console.log("Error: ".concat(e.message))}}),[]);var a=new RTCPeerConnection(c);return t.default.createElement("div",null,t.default.createElement("div",{ref:o}))};o.defaultProps={controls:!0,autoplay:!0,iceServers:"stun:stun.l.google.com:19302"};var r=function(e){return t.default.createElement(r,null,e.label)};exports.KlvView=r,exports.StanagPlayer=o;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=t(e),o=function(t){e.useRef(null);var o=e.useRef(null),r=e.useRef(!0),c=e.useState(16/9),a=c[0],i=c[1],d=e.useState({width:t.width,height:t.width/a}),s=d[0],u=d[1],l=e.useState({width:1920,height:1080}),h=l[0],f=l[1],g={iceServers:[{urls:t.iceServers}]};e.useEffect((function(){try{v.ontrack=function(e){null!=o.current&&(o.current.srcObject=e.streams[0],o.current.muted=!0,o.current.autoplay=t.autoplay,o.current.controls=t.controls,o.current.addEventListener("pause",(function(e){r.current=!0})),o.current.addEventListener("play",(function(e){r.current=!1})),o.current.addEventListener("loadedmetadata",(function(e){var n;f({width:o.current.videoWidth,height:o.current.videoHeight}),null===(n=t.onStreamInfo)||void 0===n||n.call(t,{videoWidth:o.current.videoWidth,videoHeight:o.current.videoHeight})})))},v.onconnectionstatechange=function(e){return console.log(v.iceConnectionState)},v.oniceconnectionstatechange=function(e){return console.log(v.iceConnectionState)},v.onicegatheringstatechange=function(e){return console.log(v.iceGatheringState)},v.addTransceiver("video",{direction:"sendrecv"});var e=v.createDataChannel("klv");e.binaryType="arraybuffer",e.onclose=function(){return console.log("dataChannel has closed")},e.onopen=function(){return console.log("dataChannel has opened")},e.onmessage=function(e){if(!r.current){var n=new DataView(e.data),o=new TextDecoder("utf8"),c=JSON.parse(o.decode(n)),a=(c.packetTime,c.klvs);t.onDataReceive&&t.onDataReceive(new Date(a[2]/1e3).toISOString(),a)}};var n=t.serverUrl?t.serverUrl:window.location.origin,c=new URL(n),a="ws";"http:"!=c.protocol&&(a+="s");var i=new WebSocket(a+"://".concat(c.host,"/ws"));i.onmessage=function(e){var t=JSON.parse(e.data);if(!t)return console.log("failed to parse msg");t.candidate?v.addIceCandidate(t):v.setRemoteDescription(t)},i.onerror=function(e){console.log("Websocket Error.")},i.onclose=function(e){t.onConnected&&t.onConnected(!1),1e3!=e.code&&(t.onError&&console.log("Websocket closed: ".concat(e.code)),t.onError("Websocket error: ".concat(e.code)))},v.onicecandidate=function(e){e.candidate&&""!==e.candidate.candidate&&i.send(JSON.stringify(e.candidate))},i.onopen=function(){t.onConnected&&t.onConnected(!0),v.createOffer().then((function(e){v.setLocalDescription(e),i.send(JSON.stringify(e))}))}}catch(e){console.log("Error: ".concat(e.message))}}),[]),e.useEffect((function(){try{console.log("Video dimensions: ".concat(h.width,"x").concat(h.height));var e=h.width/h.height;i(e),u({width:t.width,height:t.width/e})}catch(e){}}),[h.width,h.height,t.width]);var v=new RTCPeerConnection(g),w={width:s.width,height:s.height};return n.default.createElement("video",{style:w,ref:o})};o.defaultProps={width:360,controls:!0,autoplay:!0,iceServers:"stun:stun.l.google.com:19302"};var r=function(e){return n.default.createElement(r,null,e.label)};exports.KlvView=r,exports.StanagPlayer=o;
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/components/StanagPlayer/StanagPlayer.tsx","../../src/components/KlvView/KlvView.tsx"],"sourcesContent":[null,null],"names":["StanagPlayer","props","videoWindow","useRef","isPaused","configuration","iceServers","urls","useEffect","pc","ontrack","event","el","document","createElement","track","kind","srcObject","streams","muted","autoplay","controls","addEventListener","current","appendChild","onconnectionstatechange","e","console","log","iceConnectionState","oniceconnectionstatechange","onicegatheringstatechange","iceGatheringState","addTransceiver","direction","dataChannel","createDataChannel","binaryType","onclose","onopen","onmessage","dataView","DataView","data","decoder","TextDecoder","_a","JSON","parse","decode","klvs","onDataReceive","Date","toISOString","location_1","serverUrl","window","location","origin","uri","URL","wsProto","protocol","socket_1","WebSocket","concat","host","msg","candidate","addIceCandidate","setRemoteDescription","onerror","onConnected","code","onError","onicecandidate","send","stringify","createOffer","then","offer","setLocalDescription","error","message","RTCPeerConnection","React","ref","defaultProps","KlvView","label"],"mappings":"8KAeMA,EAAe,SAACC,GACpB,IAAMC,EAAcC,SAAO,MACrBC,EAAWD,UAAO,GAElBE,EAAgB,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":3,"file":"index.js","sources":["../../src/components/StanagPlayer/StanagPlayer.tsx","../../src/components/KlvView/KlvView.tsx"],"sourcesContent":[null,null],"names":["StanagPlayer","props","useRef","videoPlayer","isPaused","_a","useState","aspectRatio","setAspectRatio","_b","width","height","playerSize","setPlayerSize","_c","videoDimension","setVideoDimension","configuration","iceServers","urls","useEffect","pc","ontrack","event","current","srcObject","streams","muted","autoplay","controls","addEventListener","videoWidth","videoHeight","onStreamInfo","call","onconnectionstatechange","e","console","log","iceConnectionState","oniceconnectionstatechange","onicegatheringstatechange","iceGatheringState","addTransceiver","direction","dataChannel","createDataChannel","binaryType","onclose","onopen","onmessage","dataView","DataView","data","decoder","TextDecoder","JSON","parse","decode","klvs","onDataReceive","Date","toISOString","location_1","serverUrl","window","location","origin","uri","URL","wsProto","protocol","socket_1","WebSocket","concat","host","msg","candidate","addIceCandidate","setRemoteDescription","onerror","onConnected","code","onError","onicecandidate","send","stringify","createOffer","then","offer","setLocalDescription","error","message","curAspectRatio","RTCPeerConnection","playerStyle","React","createElement","style","ref","defaultProps","KlvView","label"],"mappings":"8KAyBMA,EAAe,SAACC,GACGC,EAAAA,OAAoB,MAC3C,IAAMC,EAAcD,SAAO,MACrBE,EAAWF,UAAO,GAClBG,EAAgCC,EAAAA,SAAS,GAAG,GAA3CC,EAAWF,EAAA,GAAEG,OACdC,EAA8BH,EAAAA,SAAS,CAACI,MAAOT,EAAMS,MAAOC,OAAQV,EAAMS,MAAMH,IAA/EK,EAAUH,EAAA,GAAEI,EAAaJ,EAAA,GAC1BK,EAAsCR,EAAAA,SAAS,CAACI,MAAO,KAAMC,OAAQ,OAApEI,OAAgBC,OAGjBC,EAAgB,CACpBC,WAAY,CAAC,CAAEC,KAAMlB,EAAMiB,cAG7BE,EAAAA,WAAU,WAER,IAEEC,EAAGC,QAAU,SAAUC,GAEM,MAAvBpB,EAAYqB,UACdrB,EAAYqB,QAAQC,UAAYF,EAAMG,QAAQ,GAC9CvB,EAAYqB,QAAQG,OAA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OAAQV,EAAMS,MAAMmF,GAGxD,CAFC,MAAOF,GAER,CACH,GAAE,CAAC5E,EAAeL,MAAOK,EAAeJ,OAAQV,EAAMS,QAGtD,IAAIW,EAAK,IAAIyE,kBAAkB7E,GAEzB8E,EAAc,CACdrF,MAAOE,EAAWF,MAClBC,OAAQC,EAAWD,QAGzB,OAGMqF,EAAA,QAAAC,cAAA,QAAA,CAAOC,MAAOH,EAAaI,IAAKhG,GAGxC,EAGAH,EAAaoG,aAAe,CAC1B1F,MAAO,IACPmB,UAAU,EACVD,UAAU,EACVV,WAAY,gCC7KR,IAAAmF,EAAU,SAACpG,GACf,OAAO+F,EAAAA,sBAACK,EAAO,KAAEpG,EAAMqG,MACzB"}
@@ -1,16 +1,24 @@
1
1
  /// <reference types="react" />
2
+ export interface StreamType {
3
+ videoWidth: number;
4
+ videoHeight: number;
5
+ }
2
6
  export interface StanagPlayerProps {
3
7
  serverUrl?: string;
8
+ width: number;
9
+ defaultAspectRatio?: number;
4
10
  controls?: boolean;
5
11
  autoplay?: boolean;
6
12
  iceServers?: string;
7
- onDataReceive?(packetTime: string, klvs: JSON): any;
8
- onConnected?(isConnected: boolean): any;
9
- onError?(error: string): any;
13
+ onDataReceive?(packetTime: string, klvs: JSON): void;
14
+ onConnected?(isConnected: boolean): void;
15
+ onStreamInfo?(streamIfo: StreamType): void;
16
+ onError?(error: string): void;
10
17
  }
11
18
  declare const StanagPlayer: {
12
19
  (props: StanagPlayerProps): JSX.Element;
13
20
  defaultProps: {
21
+ width: number;
14
22
  controls: boolean;
15
23
  autoplay: boolean;
16
24
  iceServers: string;
@@ -3,6 +3,7 @@ import { ComponentStory, ComponentMeta } from '@storybook/react';
3
3
  declare const _default: ComponentMeta<{
4
4
  (props: import("./StanagPlayer").StanagPlayerProps): JSX.Element;
5
5
  defaultProps: {
6
+ width: number;
6
7
  controls: boolean;
7
8
  autoplay: boolean;
8
9
  iceServers: string;
@@ -12,6 +13,7 @@ export default _default;
12
13
  export declare const Player: ComponentStory<{
13
14
  (props: import("./StanagPlayer").StanagPlayerProps): JSX.Element;
14
15
  defaultProps: {
16
+ width: number;
15
17
  controls: boolean;
16
18
  autoplay: boolean;
17
19
  iceServers: string;
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import e,{useRef as n,useEffect as o}from"react";var t=function(t){var c=n(null),r=n(!0),a={iceServers:[{urls:t.iceServers}]};o((function(){try{i.ontrack=function(e){var n=document.createElement(e.track.kind);n.srcObject=e.streams[0],n.muted=!0,n.autoplay=t.autoplay,n.controls=t.controls,n.addEventListener("pause",(function(e){r.current=!0})),n.addEventListener("play",(function(e){r.current=!1})),c.current.appendChild(n)},i.onconnectionstatechange=function(e){return console.log(i.iceConnectionState)},i.oniceconnectionstatechange=function(e){return console.log(i.iceConnectionState)},i.onicegatheringstatechange=function(e){return console.log(i.iceGatheringState)},i.addTransceiver("video",{direction:"sendrecv"});var e=i.createDataChannel("klv");e.binaryType="arraybuffer",e.onclose=function(){return console.log("dataChannel has closed")},e.onopen=function(){return console.log("dataChannel has opened")},e.onmessage=function(e){if(!r.current){var n=new DataView(e.data),o=new TextDecoder("utf8"),c=JSON.parse(o.decode(n)),a=(c.packetTime,c.klvs);t.onDataReceive&&t.onDataReceive(new Date(a[2]/1e3).toISOString(),a)}};var n=t.serverUrl?t.serverUrl:window.location.origin,o=new URL(n),a="ws";"http:"!=o.protocol&&(a+="s");var s=new WebSocket(a+"://".concat(o.host,"/ws"));s.onmessage=function(e){var n=JSON.parse(e.data);if(!n)return console.log("failed to parse msg");n.candidate?i.addIceCandidate(n):i.setRemoteDescription(n)},s.onerror=function(e){console.log("Websocket Error.")},s.onclose=function(e){t.onConnected&&t.onConnected(!1),1e3!=e.code&&(t.onError&&console.log("Websocket closed: ".concat(e.code)),t.onError("Websocket error: ".concat(e.code)))},i.onicecandidate=function(e){e.candidate&&""!==e.candidate.candidate&&s.send(JSON.stringify(e.candidate))},s.onopen=function(){t.onConnected&&t.onConnected(!0),i.createOffer().then((function(e){i.setLocalDescription(e),s.send(JSON.stringify(e))}))}}catch(e){console.log("Error: ".concat(e.message))}}),[]);var i=new RTCPeerConnection(a);return e.createElement("div",null,e.createElement("div",{ref:c}))};t.defaultProps={controls:!0,autoplay:!0,iceServers:"stun:stun.l.google.com:19302"};var c=function(n){return e.createElement(c,null,n.label)};export{c as KlvView,t as StanagPlayer};
1
+ import e,{useRef as n,useState as t,useEffect as o}from"react";var r=function(r){n(null);var c=n(null),i=n(!0),a=t(16/9),d=a[0],s=a[1],l=t({width:r.width,height:r.width/d}),u=l[0],h=l[1],g=t({width:1920,height:1080}),f=g[0],v=g[1],w={iceServers:[{urls:r.iceServers}]};o((function(){try{p.ontrack=function(e){null!=c.current&&(c.current.srcObject=e.streams[0],c.current.muted=!0,c.current.autoplay=r.autoplay,c.current.controls=r.controls,c.current.addEventListener("pause",(function(e){i.current=!0})),c.current.addEventListener("play",(function(e){i.current=!1})),c.current.addEventListener("loadedmetadata",(function(e){var n;v({width:c.current.videoWidth,height:c.current.videoHeight}),null===(n=r.onStreamInfo)||void 0===n||n.call(r,{videoWidth:c.current.videoWidth,videoHeight:c.current.videoHeight})})))},p.onconnectionstatechange=function(e){return console.log(p.iceConnectionState)},p.oniceconnectionstatechange=function(e){return console.log(p.iceConnectionState)},p.onicegatheringstatechange=function(e){return console.log(p.iceGatheringState)},p.addTransceiver("video",{direction:"sendrecv"});var e=p.createDataChannel("klv");e.binaryType="arraybuffer",e.onclose=function(){return console.log("dataChannel has closed")},e.onopen=function(){return console.log("dataChannel has opened")},e.onmessage=function(e){if(!i.current){var n=new DataView(e.data),t=new TextDecoder("utf8"),o=JSON.parse(t.decode(n)),c=(o.packetTime,o.klvs);r.onDataReceive&&r.onDataReceive(new Date(c[2]/1e3).toISOString(),c)}};var n=r.serverUrl?r.serverUrl:window.location.origin,t=new URL(n),o="ws";"http:"!=t.protocol&&(o+="s");var a=new WebSocket(o+"://".concat(t.host,"/ws"));a.onmessage=function(e){var n=JSON.parse(e.data);if(!n)return console.log("failed to parse msg");n.candidate?p.addIceCandidate(n):p.setRemoteDescription(n)},a.onerror=function(e){console.log("Websocket Error.")},a.onclose=function(e){r.onConnected&&r.onConnected(!1),1e3!=e.code&&(r.onError&&console.log("Websocket closed: ".concat(e.code)),r.onError("Websocket error: ".concat(e.code)))},p.onicecandidate=function(e){e.candidate&&""!==e.candidate.candidate&&a.send(JSON.stringify(e.candidate))},a.onopen=function(){r.onConnected&&r.onConnected(!0),p.createOffer().then((function(e){p.setLocalDescription(e),a.send(JSON.stringify(e))}))}}catch(e){console.log("Error: ".concat(e.message))}}),[]),o((function(){try{console.log("Video dimensions: ".concat(f.width,"x").concat(f.height));var e=f.width/f.height;s(e),h({width:r.width,height:r.width/e})}catch(e){}}),[f.width,f.height,r.width]);var p=new RTCPeerConnection(w),m={width:u.width,height:u.height};return e.createElement("video",{style:m,ref:c})};r.defaultProps={width:360,controls:!0,autoplay:!0,iceServers:"stun:stun.l.google.com:19302"};var c=function(n){return e.createElement(c,null,n.label)};export{c as KlvView,r as StanagPlayer};
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/components/StanagPlayer/StanagPlayer.tsx","../../src/components/KlvView/KlvView.tsx"],"sourcesContent":[null,null],"names":["StanagPlayer","props","videoWindow","useRef","isPaused","configuration","iceServers","urls","useEffect","pc","ontrack","event","el","document","createElement","track","kind","srcObject","streams","muted","autoplay","controls","addEventListener","current","appendChild","onconnectionstatechange","e","console","log","iceConnectionState","oniceconnectionstatechange","onicegatheringstatechange","iceGatheringState","addTransceiver","direction","dataChannel","createDataChannel","binaryType","onclose","onopen","onmessage","dataView","DataView","data","decoder","TextDecoder","_a","JSON","parse","decode","klvs","onDataReceive","Date","toISOString","location_1","serverUrl","window","location","origin","uri","URL","wsProto","protocol","socket_1","WebSocket","concat","host","msg","candidate","addIceCandidate","setRemoteDescription","onerror","onConnected","code","onError","onicecandidate","send","stringify","createOffer","then","offer","setLocalDesc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D,UAAU,EACVd,WAAY,gCCvIR,IAAAkF,EAAU,SAACvF,GACf,OAAOoF,gBAACG,EAAO,KAAEvF,EAAMwF,MACzB"}
1
+ {"version":3,"file":"index.js","sources":["../../src/components/StanagPlayer/StanagPlayer.tsx","../../src/components/KlvView/KlvView.tsx"],"sourcesContent":[null,null],"names":["StanagPlayer","props","useRef","videoPlayer","isPaused","_a","useState","aspectRatio","setAspectRatio","_b","width","height","playerSize","setPlayerSize","_c","videoDimension","setVideoDimension","configuration","iceServers","urls","useEffect","pc","ontrack","event","current","srcObject","streams","muted","autoplay","controls","addEventListener","videoWidth","videoHeight","onStreamInfo","call","onconnectionstatechange","e","console","log","iceConnectionState","oniceconnectionstatechange","onicegatheringstatechange","iceGatheringState","addTransceiver","direction","dataChannel","createDataChannel","binaryType","onclose","onopen","onmessage","dataView","DataView","data","decoder","TextDecoder","JSON","parse","decode","klvs","onDataReceive","Date","toISOString","location_1","serverUrl","window","location","origin","uri","URL","wsProto","protocol","socket_1","WebSocket","concat","host","msg","candidate","addIceCandidate","setRemoteDescription","onerror","onConnected","code","onError","onicecandidate","send","stringify","createOffer","then","offer","setLocalDescription","error","message","curAspectRatio","RTCPeerConnection","playerStyle","React","createElement","style","ref","defaultProps","KlvView","label"],"mappings":"+DAyBM,IAAAA,EAAe,SAACC,GACGC,EAAoB,MAC3C,IAAMC,EAAcD,EAAO,MACrBE,EAAWF,GAAO,GAClBG,EAAgCC,EAAS,GAAG,GAA3CC,EAAWF,EAAA,GAAEG,OACdC,EAA8BH,EAAS,CAACI,MAAOT,EAAMS,MAAOC,OAAQV,EAAMS,MAAMH,IAA/EK,EAAUH,EAAA,GAAEI,EAAaJ,EAAA,GAC1BK,EAAsCR,EAAS,CAACI,MAAO,KAAMC,OAAQ,OAApEI,OAAgBC,OAGjBC,EAAgB,CACpBC,WAAY,CAAC,CAAEC,KAAMlB,EAAMiB,cAG7BE,GAAU,WAER,IAEEC,EAAGC,QAAU,SAAUC,GAEM,MAAvBpB,E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MAAQK,EAAeJ,OAC7DH,EAAeqF,GACfhF,EAAc,CAACH,MAAOT,EAAMS,MAAOC,OAAQV,EAAMS,MAAMmF,GAGxD,CAFC,MAAOF,GAER,CACH,GAAE,CAAC5E,EAAeL,MAAOK,EAAeJ,OAAQV,EAAMS,QAGtD,IAAIW,EAAK,IAAIyE,kBAAkB7E,GAEzB8E,EAAc,CACdrF,MAAOE,EAAWF,MAClBC,OAAQC,EAAWD,QAGzB,OAGMqF,EAAAC,cAAA,QAAA,CAAOC,MAAOH,EAAaI,IAAKhG,GAGxC,EAGAH,EAAaoG,aAAe,CAC1B1F,MAAO,IACPmB,UAAU,EACVD,UAAU,EACVV,WAAY,gCC7KR,IAAAmF,EAAU,SAACpG,GACf,OAAO+F,gBAACK,EAAO,KAAEpG,EAAMqG,MACzB"}
package/dist/index.d.ts CHANGED
@@ -1,16 +1,24 @@
1
1
  /// <reference types="react" />
2
+ interface StreamType {
3
+ videoWidth: number;
4
+ videoHeight: number;
5
+ }
2
6
  interface StanagPlayerProps {
3
7
  serverUrl?: string;
8
+ width: number;
9
+ defaultAspectRatio?: number;
4
10
  controls?: boolean;
5
11
  autoplay?: boolean;
6
12
  iceServers?: string;
7
- onDataReceive?(packetTime: string, klvs: JSON): any;
8
- onConnected?(isConnected: boolean): any;
9
- onError?(error: string): any;
13
+ onDataReceive?(packetTime: string, klvs: JSON): void;
14
+ onConnected?(isConnected: boolean): void;
15
+ onStreamInfo?(streamIfo: StreamType): void;
16
+ onError?(error: string): void;
10
17
  }
11
18
  declare const StanagPlayer: {
12
19
  (props: StanagPlayerProps): JSX.Element;
13
20
  defaultProps: {
21
+ width: number;
14
22
  controls: boolean;
15
23
  autoplay: boolean;
16
24
  iceServers: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@impleotv/stanag-player",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Impleotv web player",
5
5
  "private": false,
6
6
  "scripts": {},