Programming/node.js2018. 9. 18. 18:58

'Programming > node.js' 카테고리의 다른 글

node.js 를 이용한 HTML 데이터 추출(크롤링)  (4) 2018.09.27
npm audit  (0) 2018.09.19
node.js 동기와 비동기 그리고 promise  (0) 2018.09.18
node.js readline 자동완성(autocompletion)  (0) 2018.09.14
node.js mysql 모듈  (0) 2018.09.13
Posted by 구차니
Programming/node.js2018. 9. 18. 18:53

mysql 라이브러리가 async 하다는 명시적인 이야기는 없지만

대개는 node.js 설계 자체가 비동기로 구현하도록 된녀석이라

필연적으로(?) 콜백 지옥에 빠지게 된다.


promise 라고 ES6에 정식 도입된 녀석을 쓰면 지옥을 벗어날수 있고

그게 아니라도 익명 함수를 쓰지 않으면 그나마 낫다고


[링크 : https://joshua1988.github.io/web-development/javascript/promise-for-beginners/]

[링크 : https://programmingsummaries.tistory.com/325]

[링크 : http://bcho.tistory.com/1086]

[링크 : http://www.nextree.co.kr/p7292/]

[링크 : https://librewiki.net/wiki/콜백_지옥]

'Programming > node.js' 카테고리의 다른 글

npm audit  (0) 2018.09.19
promise-mysql  (0) 2018.09.18
node.js readline 자동완성(autocompletion)  (0) 2018.09.14
node.js mysql 모듈  (0) 2018.09.13
node.js 콘솔 입력 받기  (0) 2018.09.12
Posted by 구차니
Programming/node.js2018. 9. 14. 15:33


const readline = require('readline');


const rl = readline.createInterface({

  input: process.stdin,

  output: process.stdout,

  completer : completer

});


function completer(line) {

  const completions = '.help .error .exit .quit .q'.split(' ');

  const hits = completions.filter((c) => c.startsWith(line));

  // show all completions if none found

  return [hits.length ? hits : completions, line];

[링크 : https://nodejs.org/api/readline.html]

[링크 : https://gist.github.com/DTrejo/901104]


근데.. 해보는데 nodemon에서는 tab을 못 넘겨주도록 막는 듯?

'Programming > node.js' 카테고리의 다른 글

promise-mysql  (0) 2018.09.18
node.js 동기와 비동기 그리고 promise  (0) 2018.09.18
node.js mysql 모듈  (0) 2018.09.13
node.js 콘솔 입력 받기  (0) 2018.09.12
node.js JSON.parse()  (0) 2018.09.12
Posted by 구차니
Programming/node.js2018. 9. 13. 17:01

귀찮으면, results 필드만 쓰면 될 듯?

connection.query('SELECT * FROM `books` WHERE `author` = "David"', function (error, results, fields) {
  // error will be an Error if one occurred during the query
  // results will contain the results of the query
  // fields will contain information about the returned results fields (if any)

}); 

[링크 : https://www.npmjs.com/package/mysql]

[링크 : https://poiemaweb.com/nodejs-mysql]

[링크 : https://www.w3schools.com/nodejs/nodejs_mysql.asp]


[링크 : http://bcho.tistory.com/892]

'Programming > node.js' 카테고리의 다른 글

node.js 동기와 비동기 그리고 promise  (0) 2018.09.18
node.js readline 자동완성(autocompletion)  (0) 2018.09.14
node.js 콘솔 입력 받기  (0) 2018.09.12
node.js JSON.parse()  (0) 2018.09.12
node-rtsp-stream 사용  (2) 2018.09.12
Posted by 구차니
Programming/node.js2018. 9. 12. 18:53

node.js는 대개 서버용으로 쓰다 보니 콘솔 입력을 받을일이 없어야 하겠지만

그럼에도 불구하고 테스트 툴로 쓰려면 scanf()를 대체할 무언가가 필요하니 검색


require('readline');


[링크 : http://jam-ws.tistory.com/9]

'Programming > node.js' 카테고리의 다른 글

node.js readline 자동완성(autocompletion)  (0) 2018.09.14
node.js mysql 모듈  (0) 2018.09.13
node.js JSON.parse()  (0) 2018.09.12
node-rtsp-stream 사용  (2) 2018.09.12
node.js 글로벌 모듈 목록보기  (0) 2018.09.11
Posted by 구차니
Programming/node.js2018. 9. 12. 16:56

rest-client를 이용해서 프로그램을 짜보는데

[링크 : https://www.npmjs.com/package/node-rest-client]


헐.. 이미 json 객체인걸 또다시 파싱하려고 하면 에러나는거였구나..

undefined:1

[object Object]

 ^


SyntaxError: Unexpected token o in JSON at position 1 


Your data is already an object. No need to parse it. The javascript interpreter has already parsed it for you.

[링크 : https://stackoverflow.com/questions/15617164/parsing-json-giving-unexpected-token-o-error]





'Programming > node.js' 카테고리의 다른 글

node.js mysql 모듈  (0) 2018.09.13
node.js 콘솔 입력 받기  (0) 2018.09.12
node-rtsp-stream 사용  (2) 2018.09.12
node.js 글로벌 모듈 목록보기  (0) 2018.09.11
node-rtsp-stream 윈도우에서 설치하기는 실패?  (0) 2018.09.11
Posted by 구차니
Programming/node.js2018. 9. 12. 10:29

흐음..

일단은 되는데 안된다(응?)


app.js

Stream = require('node-rtsp-stream');

stream = new Stream({

    name: 'name',

    streamUrl: 'rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov',

    wsPort: 9999

}); 


view/index.pug

  script(src="javascripts/jsmpeg.min.js")

  div(class="jsmpeg" data-url="video.ts" disableGl="true")

  div(class="jsmpeg" data-url="ws://10.0.100.100:9999" disableGl="true") 


node_modules/node-rtsp-stream/lib/mpeg1muxer.js

//    this.stream = child_process.spawn("ffmpeg", ["-rtsp_transport", "tcp", "-i", this.url, '-f', 'mpeg1video', '-b:v', '800k', '-r', '30', '-'], {

    this.stream = child_process.spawn("ffmpeg", ["-rtsp_transport", "tcp", "-i", this.url, '-f', 'mpegts', '-codec:v', 'mpeg1video', '-b:v', '800k', '-r', '30', '-'], {


public

wget https://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_stereo.avi

ffmpeg -i big_buck_bunny_480p_stereo.avi  -f mpegts -codec:v mpeg1video video.ts



disableGl은 적용이 안되는 것으로 보이고

변환한 ts와 외부 스트리밍은 문제없이 재생된다.




+

일단은 제어를 위해서 javascript 버전으로 구현

<script src="javascripts/jsmpeg.min.js"></script>

<canvas id="video-canvas"></canvas>

<script type="text/javascript">

var canvas = document.getElementById('video-canvas');

var url = 'video.ts';

var player = new JSMpeg.Player(url, {canvas: canvas});

player.play();


setInterval(function() {console.log(player.currentTime);}, 1000);

</script><button onclick="player.pause()"></button><button onclick="player.play()"></button>


[링크 : https://github.com/phoboslab/jsmpeg/blob/master/view-stream.html]


---

영상이 블럭이 생기며 신명나게 깨진다 -_ㅠ




fork된 node-rtsp-stream-es6 참조

[링크 : https://github.com/Wifsimster/node-rtsp-stream-es6/commit/1a52492fc9bf216e8fe646e4f13148694263a282]


ffmpeg -i rtsp://192.168.168.22 -f mpegts -codec:v mpeg1video -bf 0 -codec:a mp2 -r 30 http:// localhost:8081/1234/640/480 / ” 


[링크 : https://github.com/phoboslab/jsmpeg/issues/149]



'Programming > node.js' 카테고리의 다른 글

node.js 콘솔 입력 받기  (0) 2018.09.12
node.js JSON.parse()  (0) 2018.09.12
node.js 글로벌 모듈 목록보기  (0) 2018.09.11
node-rtsp-stream 윈도우에서 설치하기는 실패?  (0) 2018.09.11
node.js HTTP 요청하기  (0) 2018.09.10
Posted by 구차니
Programming/node.js2018. 9. 11. 15:51



npm ls -g --depth 0 

[링크 : https://stackoverflow.com/..list-all-globally-installed-modules-with-one-command-in-ubuntu]


npm uninstall -g <package> 

[링크 : https://docs.npmjs.com/getting-started/uninstalling-global-packages]

'Programming > node.js' 카테고리의 다른 글

node.js JSON.parse()  (0) 2018.09.12
node-rtsp-stream 사용  (2) 2018.09.12
node-rtsp-stream 윈도우에서 설치하기는 실패?  (0) 2018.09.11
node.js HTTP 요청하기  (0) 2018.09.10
cURL 그리고 REST  (6) 2018.09.09
Posted by 구차니
Programming/node.js2018. 9. 11. 15:03

한줄 요약

ffmpeg 패키지가 node.js의 패키지가 아닌 실제 바이너리를 의미함.. -_-

윈도우건 리눅스건 상관없는데, node-rtsp-stream 문제가 있는 것으로 보임


---

패키지 까는데 윈도우에서 하고 있어서 열심히 에러 뿜뿜 해주심 -_-


C:\> npm install -g node-rtsp-stream

npm WARN notice [SECURITY] ws has the following vulnerabilities: 2 high, 1 low. Go here for more details: https://nodesecurity.io/advisories?search=ws&version=0.4.32 - Run `npm i npm@latest -g` to upgrade your npm version, and then `npm audit` to get more info.


> ws@0.4.32 install C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws

> (node-gyp rebuild 2> builderror.log) || (exit 0)



C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )

이 솔루션의 프로젝트를 한 번에 하나씩 빌드합니다. 병렬 빌드를 사용하려면 "/m" 스위치를 추가하십시오.

MSBUILD : error MSB3428: Visual C++ 구성 요소 "VCBuild.exe"을(를) 로드할 수 없습니다. 이 문제를 해결하려면 1) .NET Framework 2.0 SDK를 설치하거나, 2

) Microsoft Visual Studio 2005를 설치하거나, 3) 해당 구성 요소가 다른 위치에 설치되어 있는 경우에는 그 위치를 시스템 경 로에 추가하십시오.  [C:\Users\user\AppDa

ta\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws\build\binding.sln]

MSBUILD : error MSB3428: Visual C++ 구성 요소 "VCBuild.exe"을(를) 로드할 수 없습니다. 이 문제를 해결하려면 1) .NET Framework 2.0 SDK를 설치하거나, 2

) Microsoft Visual Studio 2005를 설치하거나, 3) 해당 구성 요소가 다른 위치에 설치되어 있는 경우에는 그 위치를 시스템 경 로에 추가하십시오.  [C:\Users\user\AppDa

ta\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws\build\binding.sln]

+ node-rtsp-stream@0.0.3

added 6 packages in 21.052s

[링크 : https://www.npmjs.com/package/node-rtsp-stream]


걍 깔았더니 또 에러 뿜뿜해주심

C:\>npm install -g windows-build-tools


> windows-build-tools@4.0.0 postinstall C:\Users\user\AppData\Roaming\npm\node_modules\windows-build-tools

> node ./dist/index.js




Downloading BuildTools_Full.exe

[============================================>] 100.0% of 3.29 MB (3.29 MB/s)

Downloaded BuildTools_Full.exe. Saved to C:\Users\user\.windows-build-tools\BuildTools_Full.exe.


Starting installation...

Please restart this script from an administrative PowerShell!

The build tools cannot be installed without administrative rights.

To fix, right-click on PowerShell and run "as Administrator".

npm ERR! code ELIFECYCLE

npm ERR! errno 1

npm ERR! windows-build-tools@4.0.0 postinstall: `node ./dist/index.js`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the windows-build-tools@4.0.0 postinstall script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


npm ERR! A complete log of this run can be found in:

npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2018-09-11T05_51_43_564Z-debug.log 

[링크 : https://superuser.com/questions/1032689/how-do-i-add-vcbuild-exe-to-windows-10-w-o-visual-studio]


C:\>npm install -g windows-build-tools


> windows-build-tools@4.0.0 postinstall C:\Users\user\AppData\Roaming\npm\node_modules\windows-build-tools

> node ./dist/index.js




Downloading BuildTools_Full.exe

[>                                            ] 0.0% (0 B/s)

Downloaded BuildTools_Full.exe. Saved to C:\Users\user\.windows-build-tools\BuildTools_Full.exe.


Starting installation...

Launched installers, now waiting for them to finish.

This will likely take some time - please be patient!


Status from the installers:

---------- Visual Studio Build Tools ----------

Successfully installed Visual Studio Build Tools.

------------------- Python --------------------

Python 2.7.15 is already installed, not installing again.


Now configuring the Visual Studio Build Tools..


All done!


+ windows-build-tools@4.0.0

added 142 packages in 102.328s 


영안되는거 같아서 삭제하고 다시 까는데 또 안되는 느낌 -_-

C:\>npm install -g node-rtsp-stream


> ws@0.4.32 install C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws

> (node-gyp rebuild 2> builderror.log) || (exit 0)



C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )

이 솔루션의 프로젝트를 한 번에 하나씩 빌드합니다. 병렬 빌드를 사용하려면 "/m" 스위치를 추가하십시오.

C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws\build\bufferutil.vcxproj(20,3): err

or MSB4019: 가져온 "C:\Microsoft.Cpp.Default.props" 프로젝트를 찾을 수 없습니다. <Import> 선언에 지정한 경로가 올바른지 그리고 파일이 디스크에 있는지 확인하십시오.

C:\Users\user\AppData\Roaming\npm\node_modules\node-rtsp-stream\node_modules\ws\build\validation.vcxproj(20,3): err

or MSB4019: 가져온 "C:\Microsoft.Cpp.Default.props" 프로젝트를 찾을 수 없습니다. <Import> 선언에 지정한 경로가 올바른지 그리고 파일이 디스크에 있는지 확인하십시오.

+ node-rtsp-stream@0.0.3

added 6 packages in 5.346s 


췟.. 모듈 인식을 못한다.

C:\tt>node app.js

module.js:549

    throw err;

    ^


Error: Cannot find module 'node-rtsp-stream'

    at Function.Module._resolveFilename (module.js:547:15)

    at Function.Module._load (module.js:474:25)

    at Module.require (module.js:596:17)

    at require (internal/module.js:11:18)

    at Object.<anonymous> (C:\Users\classact\Desktop\tt\app.js:1:72)

    at Module._compile (module.js:652:30)

    at Object.Module._extensions..js (module.js:663:10)

    at Module.load (module.js:565:32)

    at tryModuleLoad (module.js:505:12)

    at Function.Module._load (module.js:497:3) 


영 안되는 기분인데.. 

아무튼 우리의 친구 VLC를 깔고

만만한(?) 동영상 하나 받고

[링크 : https://archive.org/download/BigBuckBunny]


중요 : ffmpeg 실행파일이 필요하므로 적절한 위치에 압축풀고 윈도우 경로를 지정해준다.

[링크 : https://ffmpeg.zeranoe.com/builds/]


클라이언트에는 이거 하나 더 추가해주고

var WebSocket = require('ws') 

client = new Websocket('ws://localhost:9999');

player = new jsmpeg(client, {

    canvas: canvas // Canvas should be a canvas DOM element

});

[링크 : https://stackoverflow.com/questions/21441867/referenceerror-websocket-is-not-defined]


아놔.. window is not defined -_- 아 몰라 배째 


---

아 몰라 머리아프네 ㅠㅠ


[링크 : https://github.com/phoboslab/jsmpeg]

[링크 : https://jsmpeg.com/]

[링크 : https://www.npmjs.com/package/node-rtsp-stream]

[링크 : https://www.npmjs.com/package/jsmpeg]

[링크 : https://phoboslab.org/log/2013/05/mpeg1-video-decoder-in-javascript]

[링크 : https://github.com/Wifsimster/node-rtsp-stream-es6] <<

[링크 : https://github.com/phoboslab/jsmpeg/blob/master/view-stream.html]

'Programming > node.js' 카테고리의 다른 글

node-rtsp-stream 사용  (2) 2018.09.12
node.js 글로벌 모듈 목록보기  (0) 2018.09.11
node.js HTTP 요청하기  (0) 2018.09.10
cURL 그리고 REST  (6) 2018.09.09
node.js rtsp 스트리밍  (0) 2018.09.07
Posted by 구차니
Programming/node.js2018. 9. 10. 14:58

node.js 에서 다른 REST 서버로 요청하는걸 찾는중


option의 type을 지정하는거군..


[링크 : http://devnauts.tistory.com/95]

[링크 : http://shiya.io/send-http-requests-to-a-server-with-node-js/]

'Programming > node.js' 카테고리의 다른 글

node.js 글로벌 모듈 목록보기  (0) 2018.09.11
node-rtsp-stream 윈도우에서 설치하기는 실패?  (0) 2018.09.11
cURL 그리고 REST  (6) 2018.09.09
node.js rtsp 스트리밍  (0) 2018.09.07
RESTful  (0) 2018.09.07
Posted by 구차니