stop or kill node media server - javascript

I am trying to implement stop feature for live video streaming using node-media-server.
Basically I want to stop node-media-server completely, restart it later.
const NodeMediaServer = require("node-media-server");
let config = {
logType: 3,
rtmp: {
port: rtmpPort,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30,
},
http: {
port: httpPort,
allow_origin: "*",
},
relay: {
ffmpeg: "/usr/bin/ffmpeg",
tasks: [
{
app: "cctv",
mode: "static",
edge: "rtsp://" + cameraUrl + "/h264_ulaw.sdp",
name: "uterum",
rtsp_transport: "udp",
},
],
},
};
let nms = new NodeMediaServer(config);
nms.run();

I see on the project github that there is a stop method.
Have you try to use it ?
https://github.com/illuspas/Node-Media-Server/blob/master/node_media_server.js
nms.stop();
Answer to comment:
Goto the github repo :
Express file is the app.js
Inside it you see
const NodeMediaServer = require('./');
...
let nms = new NodeMediaServer(config)
nms.run();
You see the NodeMediaServer ?
There is another file in the same folder node_media_server.js which exports module.exports = NodeMediaServer
Just a look at this file and you see the stop method.
That's all.

Related

Cypress: How to test upload a folder with files and subfolders?

I'm having an issue to test uploading a folder with files and subfolders. If I add folder structure to the fixture then cy.fixture() command doesn't recognize that is a directory that I want to upload but it looks inside the directory to find the files. I have tries also to use the cy.readFile() but I couldn't make it to work.
I have tried to create drag and drop command like this:
Cypress.Commands.add('dragAndDropFolder', (fileUrl, type = '') => {
return cy.readFile(fileUrl, 'binary')
.then(Cypress.Blob.binaryStringToArrayBuffer)
.then(blob => {
const nameSegments = fileUrl.split('/');
const name = nameSegments[nameSegments.length - 1];
const testFile = new File([blob], name, { type });
const event = {
dataTransfer: {
isDirectory: true,
isFile: false,
fullPath: `#${fileUrl}`,
files: [testFile],
items: [{ kind: 'file', type }],
types: ['Files'],
},
};
return cy
.get('[data-test-dropzone="true"]')
.first()
.trigger('dragenter', event)
.trigger('drop', event);
});
});
Another thing I have tried to use a our different functionality which is simple upload button and the attachFile() plugin:
cy.readFile('client/testfolder', 'binary').then(file => {
cy.get('#multiple_file_uploads_input').attachFile(file)
});
Drag and drop functionality is written in Elixir and this is how data transfer looks like:
{
isDirectory: true,
isFile: false,
fullPath: '#{path}',
createReader() {
return {
sentEntries: false,
readEntries(callback) {
if (!this.sentEntries) {
this.sentEntries = true;
callback([#{Enum.join(entries, ",")}]);
} else {
callback([]);
}
},
};
},
}
At least on Elixir side the fullPath: '#{path}', will be substituted by the real path like fullPath: '/some/path', so you need to remove hash (#) from your path at JavaScript side here fullPath: '#${fileUrl}',, probably could be just fullPath: fileUrl,

YouTube Downloader using node.js

So I'm creating YouTube Downloader using node.js. The problem is the files are already created after I ran the code, but the files are 0kb and it prints Successfully. What I want is the program must be print successfully when I successfully download the video, also must not be created the file yet. the file must be created after the one video successfully downloaded
const playlist = [
{
title: "What is DevOps",
videoUrl: "https://www.youtube.com/watch?v=mBBgRdlC4sc",
},
{
title: "Introduction To DevOps ",
videoId: "Me3ea4nUt0U",
videoUrl: "https://www.youtube.com/watch?v=Me3ea4nUt0U",
},
{
title: "DevOps Tutorial For Beginners ",
videoId: "YSkDtQ2RA_c",
videoUrl: "https://www.youtube.com/watch?v=YSkDtQ2RA_c",
},
];
const fs = require("fs");
const ytdl = require("ytdl-core");
const length = playlist.length;
playlist.forEach((pl, i) => {
const { videoUrl, title } = pl;
const item = i + 1;
ytdl(videoUrl, {
format: "mp4",
}).pipe(fs.createWriteStream(`${title}.mp4`));
console.log(`${item}/${length} - ${title} downloaded successfully`);
});
You are logging "downloaded successfully" before the writing is finished. You have a few possibilities. One might be listening on certain events on the "WriterStream".
from the docs : https://nodejs.org/dist/latest-v12.x/docs/api/fs.html#fs_fs_createwritestream_path_options
// Create WriteableStream
const writeableStream = fs.createWriteStream(`${title}.mp4`);
// Listening for the 'finish' event
writeableStream .on('finish', () => {
console.log(`${item}/${length} - ${title} downloaded successfully`);
});
// Plug it into the ReadableStream
ytdl(videoUrl, {
format: "mp4",
}).pipe(writeableStream);
Now this will create a new file as soon the writing starts. I suggest using a temporary name like filename.temp.mp4 and then rename it after it finished writing.

React download an image from uri and put in static folder? [duplicate]

I am building an app with React Native, for Android and iOS. I am trying to let the user download a PDF file when clicking on a button.
react-native-file-download does not support Android
react-native-fs does nothing when I trigger downloadFile (nothing shows up on the notification bar), and I am not able to find the file after that. I added android.permission.WRITE_EXTERNAL_STORAGE to the Android Manifest file. I double-checked that the file I am trying to download exists (when it does not, the library throws an error)
I do not find other solutions for this problem. I have found libraries for viewing a PDF, but I would like to let the user download the PDF.
Just implemented the download feature an hour ago :p
Follow these steps:
a) npm install rn-fetch-blob
b) follow the installation instructions.
b2) if you want to manually install the package without using rnpm, go to their wiki.
c) Finally, that's how I made it possible to download files within my app:
const { config, fs } = RNFetchBlob
let PictureDir = fs.dirs.PictureDir // this is the pictures directory. You can check the available directories in the wiki.
let options = {
fileCache: true,
addAndroidDownloads : {
useDownloadManager : true, // setting it to true will use the device's native download manager and will be shown in the notification bar.
notification : false,
path: PictureDir + "/me_"+Math.floor(date.getTime() + date.getSeconds() / 2), // this is the path where your downloaded file will live in
description : 'Downloading image.'
}
}
config(options).fetch('GET', "http://www.example.com/example.pdf").then((res) => {
// do some magic here
})
If you're using Expo, react-native-fetch-blob won't work. Use FileSystem.
Here's a working example:
const { uri: localUri } = await FileSystem.downloadAsync(remoteUri, FileSystem.documentDirectory + 'name.ext');
Now you have localUri with the path to the downloaded file. Feel free to set your own filename instead of name.ext.
I Followed the solution from Jonathan Simonney, above on this post. But I had to change it a little:
const { config, fs } = RNFetchBlob;
const date = new Date();
const { DownloadDir } = fs.dirs; // You can check the available directories in the wiki.
const options = {
fileCache: true,
addAndroidDownloads: {
useDownloadManager: true, // true will use native manager and be shown on notification bar.
notification: true,
path: `${DownloadDir}/me_${Math.floor(date.getTime() + date.getSeconds() / 2)}.pdf`,
description: 'Downloading.',
},
};
config(options).fetch('GET', 'http://www.africau.edu/images/default/sample.pdf').then((res) => {
console.log('do some magic in here');
});
GetItem_downloadbtn = (item, itemname) => {
console.log("fiel url comiugn jdd " + item);
console.log("item name checkoing " + itemname);
const android = RNFetchBlob.android;
const filename = itemname;
const filepath = RNFetchBlob.fs.dirs.DownloadDir + '/foldernamae/' + filename;
const downloadAppUrl = item;
RNFetchBlob.config({
addAndroidDownloads: {
useDownloadManager: true,
title: 'great, download success',
description:'an apk that will be download',
mime: 'application/vnd.android.package-archive',
// mime: 'image/jpeg',
// mediaScannable: true,
notification: true,
path: filepath
}
})
.fetch('GET', downloadAppUrl)
.then((res) => {
// console.log('res.path ', res.path());
alert('res.path ', res.path());
android.actionViewIntent(res.path(), 'application/vnd.android.package-archive');
})
.catch((err) => {
alert('download error, err is', JSON.stringify(err));
});
}
I had the same issue, got it working using Expo WebBrowser Module
// install module
npm install react-native-webview
// import the module
import * as WebBrowser from 'expo-web-browser';
// then in your function you can call this function
await WebBrowser.openBrowserAsync(file_ur);
it will open preview of the file and then user can download using share button.

Disable/Deny all protocols except ws:// in Node Media Server (Nodejs)

I would like to deny access to anyone trying to read my stream from http or rtmp protocols.
I am learning on the fly, so I'm no dev, kinda rookie actually.. so if you could explain to me how to do this in simple terms.. I'd really much appreciate it !
Here the code I'm using right now and that allows every protocols to be played...
const { NodeMediaServer } = require('node-media-server');
const config = {
logType: 3,
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30
},
http: {
port: 8080,
allow_origin: '*',
},
};
var nms = new NodeMediaServer(config)
nms.run();
The best would be an if statement, but I've been searching/testing but I didn't succeed.
Thank you for your help and time !

IOS: "Failed: Method is not implemented" error when I tried to perform some touch actions

I am testing Hybrid app and I tried to perform some touch actions on iOS like doubleTap and tapAndHold on WebView. And I get "Failed: Method is not implemented" error.
I tried the below code :
browser.switchTo().frame(0);
return browser.touchActions().doubleTap(element).perform();
But when I try
return browser.touchActions().tap(element).perform();
everything is ok.
For Android this code works fine.
Appium: 1.7.1
Protractor: 5.1.2
webdriver-manager 12.0.6.
MacOS High Sierra
So how can I perform this touch actions on iOS?
conf.js:
var wd = require('wd'),
wdBridge = require('wd-bridge')(require('protractor'), wd);
const config = {
sync: false,
seleniumAddress: 'http://localhost:4723/wd/hub',
capabilities: {
browserName: '',
appiumVersion: "1.7.1",
deviceName: "iPhone 8",
deviceOrientation: "portrait",
platformName: "iOS",
platformVersion: "11.0",
app:"",
bundleId:'',
launchTimeout: 20000,
webviewConnectRetries: 1,
autoAcceptAlerts: true,
autoWebview: true,
waitForAppScript: 'true',
nativeInstrumentsLib:'false',
showIOSLog:'false',
newCommandTimeout: 5000
},
framework: 'jasmine2',
allScriptsTimeout: 1500000,
jasmineNodeOpts: {
showColors: true,
print: function () {
},
isVerbose: true,
includeStackTrace: true,
defaultTimeoutInterval: 1500000
},
suites: {
smoke: ['./automation/smoke/*.js'],
},
beforeLaunch: function () {
return new Promise(function (resolve) {
reporter.beforeLaunch(resolve);
});
},
onPrepare: function () {
wdBridge.initFromProtractor(exports.config);
browser.ignoreSynchronization = true;
browser.wBridge=wdBridge;
browser.getProcessedConfig()
.then(function (config) {
browser.appPackage = config.capabilities.appPackage;
browser.bundleId = config.capabilities.bundleId;
browser.deviceProperties = config.capabilities.deviceProperties;
browser.platformname = config.capabilities.platformName;
var iOSProperties = {'identifier': browser.bundleId},
androidProperties = {'identifier': browser.appPackage},
params = browser.platformname.toLowerCase() === 'iOS' ? androidProperties : iOSProperties;
browser.ignoreSynchronization = true;
wdBrowser.currentContext().then(function(context) {
console.log('#context');
console.log(context);
});
});
},
useAllAngular2AppRoots: true,
restartBrowserBetweenTests: false
};
exports.config = config;
There is no doubleTap function in wd project, so the error you get is expected to see.
If you check appium server commands for doubleTap, you will notice that for wd client code is the same to tap code, so it really looks like doubleTap is not supported by wd yet
So far I see 2 options:
1) Play more with existing functions in wd touch actions, e.g. try
const location = await element.getLocation()
const action = new wd.TouchAction()
action.press({x: location.x, y: location.y})
.release()
.press({x: location.x, y: location.y})
.release()
await browser.performTouchAction(action)
2) Implement doubleTap in wd project looking into examples from java or python client.

Categories

Resources