How do I associate metadata with a specific track with webrtc?

I’ve got a peer connection with a mediaStream object to add tracks to. I obtain the tracks from several local media devices and add the tracks to the mediaStream to be sent over to the remote peer along with a datachannel message containing a mapping from streamid’s to a string representing it’s purpose. (a workaround because contentHint doesn’t work)

On the remote peer I have a addTrack event handler that needs to decide where to put the track as at this point there can be multiple video and audio tracks but the track id’s are all different so there isn’t a way to associate a mediaStream.id with a mediaStreamTrack.id

mediaStreamTrack.label gives me a generated guid if the track was sent from webrtc.

Do I really need to create multiple rtc connections for each video to get this metadata about where a video comes from?

Create structured JS object based on unstructured JS object

I have this js object data:

const content = 
  [ { h1 : 'This is title number 1'          } 
  , { h2 : 'Description'                     }
  , { p  : 'Description unique content text' }
  , { h2 : 'Content'                         }
  , { p  : 'Content unique text here 1'      }
  , { ul : [ 
           'string value 1',
           'string value 2'
       ]                       
  , } 
  , { p  : 'Content unique text here 2'      }
  , { h2 : 'CTA message'                     }
  , { p  : 'CTA message unique content here' }
  , { h2 : 'CTA button'                      }
  , { p  : 'CTA button unique content here'  }
  , { p  : ''                                }
  , { h1 : 'This is title number 2'          } 
  , { h2 : 'Description'                     }
  , { p  : 'Description unique content text' }
  , { h2 : 'Content'                         }
  , { p  : 'Content unique text here 1'      }
  , { h2 : 'CTA message'                     }
  , { p  : 'CTA message unique content here' }
  , { h2 : 'CTA button'                      }
  , { p  : 'CTA button unique content here'  }
  , { p  : ''                                }
  ]

h1 indicates a new object, the ul is optional

I want to map it to such structure:

interface Content = {
  title: string;
  description: string;
  content: [{
    p: string;
    ul: string[] //optional
  }];
  cta: {
    message: string;
    button: string;
  }
}

I am wondering what is the best way of doing that?

I think I have to loop through the items and just populate a new JSON object based on my interface. The first element is always title, then just checking if “description” then the next item is description value.

    const json = Content[];
    content.forEach(element => {
    if(element.h1) {
        // add props to new object
        // add object to json array
    }
});

I just wonder how wold you create multiple Content objects based on that original content JSON object?

Here is the result I am expecting:

json = [
  {
    title: 'This is title number 1',
    description: 'Description unique content text',
    content: [
      {
        p: 'Content unique text here 1',
        ul: [
            'string value 1',
            'string value 2'
        ]
      },
      {
        p: 'Content unique text here 2',
        ul: []
      } 
    ],
   cta: {
      message: 'CTA message unique content here'
      button: 'CTA button unique content here'
   }
  },
  ...
]

Datetime Picker Filter Exception: Call to a member function format() on bool codeigniter

Hello I’m trying to create a filter with datetime but when I tried to use datetime I have this error : Exception: Call to a member function format() on bool

but without time it works fine.

here’s my helper code:

function to_sql_date($date, $datetime = false)
{
    if ($date == '' || $date == null) {
        return null;
    }

    $to_date     = 'Y-m-d';
    $from_format = get_current_date_format(true);

    $date = hooks()->apply_filters('before_sql_date_format', $date, [
        'from_format' => $from_format,
        'is_datetime' => $datetime,
    ]);

    if ($datetime == false) {
        // Is already Y-m-d format?
        if (preg_match('/^(d{4})-(d{1,2})-(d{1,2})$/', $date)) {
            return $date;
        }

        return hooks()->apply_filters(
            'to_sql_date_formatted',
            DateTime::createFromFormat($from_format, $date)->format($to_date)
        );
    }

    if (strpos($date, ' ') === false) {
        $date .= ' 00:00:00';
    } else {
        $hour12 = (get_option('time_format') == 24 ? false : true);
        if ($hour12 == false) {
            $_temp = explode(' ', $date);
            $time  = explode(':', $_temp[1]);
            if (count($time) == 2) {
                $date .= ':00';
            }
        } else {
            $tmp  = _simplify_date_fix($date, $from_format);
            $time = date('G:i', strtotime($tmp));
            $tmp  = explode(' ', $tmp);
            $date = $tmp[0] . ' ' . $time . ':00';
        }
    }

    $date = _simplify_date_fix($date, $from_format);
    $d    = date('Y-m-d H:i:s', strtotime($date));

    return hooks()->apply_filters('to_sql_date_formatted', $d);
}

How to get connection data in websocket client with ws library

Websocket client is running a script below:

let WebSocket = require('ws');
let readline = require('readline');

let url = 'wss://***.execute-api.us-east-1.amazonaws.com/test';
let ws = new WebSocket(url);

ws.on('open',  () => {
  console.log('...client.on.open: connected')
});

ws.on('message', data => {
  console.log(`...client.on.message: received from server: ${data}`)
});

ws.on('close', () => {
  console.log('...client.on.close: disconnected');
  process.exit();
});



readline.createInterface({
  input: process.stdin,
  output: process.stdout,
}).on('line', data => {
  console.log(`...client.sending to server: ${data}`)
  ws.send(data);
});

Is there an unique websocket’s connection id that could be queried from within ws.on('open') function?

How to rotate around the Y axis when scrolling down?

I am using Three.js to make a 3D frontend and after constructing the basic layout and added some test geometry I want to test how the camera rotates and can’t figure out how exactly to make it rotate around the Y axis solely when trying to scroll up/down. I am using Vanilla JS. If anyone has any tips on how to approach this, thanks.

Using zoom with Swiper JS for React

I have a slider which is rendered using map(). I need to apply zoom to an img, SwiperJS documentation for React doesn’t say anything about it 🙁
I used zoom from swiperJS modules, didn’t help

const Blog = () => {
  return ( <
    <
    Swiper modules = {
      [Navigation]
    }
    slidesPerView = {
      2
    }
    spaceBetween = {
      40
    }
    navigation > {
      slideObj.map((obj) => ( <
        SwiperSlide key = {
          obj.imageUrl
        } >
        <
        img className = "blog__image "
        src = {
          obj.imageUrl
        }
        alt = "Photo" / >
        <
        div className = "blog__text" > {
          obj.discription
        } < /div> < /
        SwiperSlide >
      ))
    } <
    /Swiper> < /
  );
};

export default Blog;

Get data in bootstrap modal

I am trying to get collected data in Bootstrap modal but it is not working. This code was working ok in bootstrap 4 but not in 5.
Here I am collecting data from php

    <ul class="list-inline hstack gap-2 mb-0">
<li class="list-inline-item edit" title="Edit">
    <a href="" data-bs-toggle="modal" class="text-primary d-inline-block edit-item-btn" data-branch-id="<?php echo $row3["branch_id"]; ?>"  data-bs-target="#editLocation" ><i class="ri-pencil-fill fs-16"></i></a>
</li>
<li class="list-inline-item" data-bs-toggle="tooltip" data-bs-trigger="hover" data-bs-placement="top" title="Remove">                                                                                               <a class="text-danger d-inline-block remove-item-btn" data-bs-toggle="modal" href="#deleteRecordModal"><i class="ri-delete-bin-5-fill fs-16"></i></a>
</li>

This is my modal

    <div class="modal fade" id="editLocation" tabindex="-1" aria-hidden="true" role="dialog">
                                    
                                    <div class="modal-dialog modal-dialog-centered">
                                        <div class="modal-content">
                                            <div class="modal-header bg-light p-3">
                                                <h5 class="modal-title">Edit Location</h5>
                                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close" id="close-modal"></button>
                                            </div>
                                            <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                                                <div class="modal-body">
                                                    <div class="mb-3">
                                                        <label for="branchname" class="form-label">Branch Name</label>
                                                        <input type="text" class="form-control" name="branchname" placeholder="Enter branch identification label" required />
                                                        
                                                    </div>

                                                    <div class="mb-3">
                                                        <label for="branchstreet" class="form-label">Street Address</label>
                                                        <input type="text" id="branchstreet" class="form-control" name="branchstreet" placeholder="76, Great North Road" />
                                                    </div>

                                                    <div class="mb-3">
                                                        <label for="branchsuburb" class="form-label">Suburb</label>
                                                        <input type="text" id="branchsuburb" class="form-control" name="branchsuburb" placeholder="" />
                                                    </div>
                                                    
                                                    <div class="mb-3">
                                                        <label for="branchcity" class="form-label">City</label>
                                                        <input type="text" id="branchcity" class="form-control" name="branchcity" placeholder="" />
                                                    </div>
                                                    <div class="mb-3">
                                                        <label for="branchzip" class="form-label">Zip</label>
                                                        <input type="text" id="branchzip" class="form-control" name="branchzip" placeholder="" />
                                                    </div>
                                                    
                                                    <div class="mb-3">
                                                        <label for="branchstate" class="form-label">State</label>
                                                        <input type="text" id="branchstate" class="form-control" name="branchstate" placeholder="" />
                                                    </div>
                                                    <div class="mb-3">
                                                        <label for="branchcountry" class="form-label">Country</label>
                                                        <input type="text" id="branchcountry" class="form-control" name="branchcountry" placeholder="" />
                                                    </div>
                                                    
                                                </div>
                                                <div class="modal-footer">
                                                    <div class="hstack gap-2 justify-content-end">
                                                        <button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
                                                        <button type="submit" class="btn btn-success" id="addbranch" name="addbranch">Add Location</button>
                                                        <button type="submit" class="btn btn-success" id="updatebranch" name="updatebranch">Update</button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>

Here how I am trying to get branchid

   <script>
    $('#editLocation').on('show.bs.modal',  function(e){
    var branchId = $(e.relatedTarget).data('branch-id');
   
    $(e.currentTarget).find('input[name="branchname"]').val(branchId);
    
    }); 
    </script>

Can anyone tell me why I am not getting branchid in the modal please?

why this use of Apply() method doesn’t work? [duplicate]

I want the following code to alert “John Doe,Bogotá”, but it doesn’t because of an error that says cannot read properties of undefined. I’ve read that the first argument that receives this function is the object which is going to be applied the function in, and the following arguments are the parameters that receives the function.

const person = {
  fullName: function(city) {
    return this.firstName + " " + this.lastName + "," + city.name;
  }
}

const person1 = {
  firstName:"John",
  lastName: "Doe"
}

const city1 = {
  name:"Bogotá"
}
alert(person.fullName.apply(person1, city1)); 

Doesn’t work with call() either.

Bad Formed XML Server Response, how to convert to JSON? [closed]

May someone help with a little bug here?
I have this request from a asp server that returns a XML-Like Result as follow:

response from server

And I Expected that it comes more like this:

i expected this

Can anyone give some direction here?
I´ve already tried lot of tutorials, and helpers and plugins, but it´s still bugging.
The responseXml doesn´t work, and this result only appears with responseText function from XMLHttpRequest method. I´m not getting it converted any to object or array that I can access it content. Please, I´ll apprecciate a lot!

Looking for a clean function implementation of a switch statement in JavaScript

I am teaching a course that includes explaining functional JavaScript and I want to have a really good example of functional programming that is hopefully cleaner then non-functional. I want to convert the following switch statement to functional. I’ve made an example of that conversion myself, but hoping there is a simpler solution.

Here is the switch statement version:

let animalType = "Poodle";
switch (animalType) {
  case "Poodle":
  case "Beagle":
  case "Bulldog":
    console.log(animalType + " is a dog.");
    break;
  case "Bengal":
  case "Siamese":
    console.log(animalType + " is a cat.");
    break;
  default:
    console.log(animalType + " is not a dog or cat.");
    break;
}

And here is what I came up with as functional that I’m not that happy about

const result = getAnimalType("Poodle");
console.log("result:" + result)

function getAnimalType(animal) {
  function isDog(animal) {
    const dogs = ["Poodle", "Beagle", "Bulldog"];
    return dogs.includes(animal)
  }
  function isCat(animal) {
    const cats = ["Bengal", "Siamese"];
    return cats.includes(animal)
  }
  return isDog(animal)
    ? animal + " is a dog."
    : isCat(animal)
    ? animal + " is a cat."
    : animal + " is not a dog or cat.";
}

How to Return a Sum in JavaScript Based on Characters in Text File [duplicate]

I have a text file that includes both ‘(‘ and ‘)’ parentheses characters. Each of these represents either adding or subtracting a numerical value of 1. I am trying to find out the result of a text file that includes many of these characters. So far I have used a fs.readFile for JavaScript to read the text file and have converted it to a string using toString(‘utf8’). I have tried using if when the character is present to add or subtract from the original value. I know this should be very easy and feel like I’m forgetting something very simple.

Here is what I have so far:

const fs = require('fs');
const floor = 0;
const goUp = '(';
const goDown = ')';
const instructions = './instructions.txt'

fs.readFile('./instructions.txt', (err, data) => {
    console.time('santachallenge');
    if (err) {
        console.log('There has been an error. Please try again.');
    }
    
    data.toString('utf8');

    if (instructions === goUp) {
        floor + 1
    }

    if (instructions === goDown) {
        floor - 1
    }

    console.log(floor);
    console.timeEnd('santachallenge');
})

and the text file:

((((()(()(((((((()))(((()((((()())(())()(((()((((((()((()(()(((()(()((())))()((()()())))))))))()((((((())((()))(((((()(((((((((()()))((()(())()((())((()(()))((()))()))()(((((()(((()()))()())((()((((())()())()((((())()(()(()(((()(())(()(())(((((((())()()(((())(()(()(()(())))(()((((())((()))(((()(()()(((((()()(()(((()(((((())()))()((()(()))()((()((((())((((())(()(((())()()(()()()()()(())((((())((())(()()))()((((())))((((()())()((((())((()())((())(())(((((()((((()(((()((((())(()(((()()))()))((((((()((())()())))(((()(()))(()()(()(((()(()))((()()()())((()()()(((())())()())())())((()))(()(()))(((((()(()(())((()(())(())()((((()())()))((((())(())((())())((((()(((())(())((()()((((()((((((()(())()()(()(()()((((()))(())()())()))(())))(())))())()()(())(()))()((()(()(())()()))(()())))))(()))(()()))(())(((((()(()(()()((())()())))))((())())((())(()(())((()))(())(((()((((((((()()()(()))()()(((()))()((()()(())(())())()(()(())))(((((()(())(())(()))))())()))(()))()(()(((((((()((((())))())())())())()((((((((((((((()()((((((()()()())())()())())())(())(())))())((()())((()(()))))))()))))))))))))))))())((())((())()()))))))(((()((()(()()))((())(()()))()()())))(())))))))(()(((())))())()())))()()(())()))()(()))())((()()))))(()))))()))(()()(())))))))()(((()))))()(()))(())())))))()))((()))((()))())(())))))))))((((())()))()))()))())(())()()(())))())))(()())()))((()()(())))(())((((((()(())((()(((()(()()(())))()))))))()))()(()((()))()(()))(()(((())((((())())(())(()))))))))())))))))())())))))())))))()()(((())()(()))))))))())))))(())()()()))()))()))(()(())()()())())))))))())()(()(()))))()()()))))())(()))))()()))))()())))))(((())()()))(()))))))))))()()))))()()()))))(()())())()()())()(()))))()(()))(())))))))(((((())(())())()()))()()))(())))))()(()))))(())(()()))()())()))()))()))()))))())()()))())())))(()))(()))))))())()(((())()))))))))()))()())))())))())))()))))))))))()()))(()()))))))(())()(()))))())(()))))(()))))(()())))))())())()()))))())()))))))))(()))))()))))))()(()())))))))()))())))())))())))())))))))())(()()))))))(()())())))()())()))))))))))))))())))()(())))()))())()()(())(()()))(())))())()())(()(()(()))))())))))))))))())(()))()))()))))(())()())()())))))))))))()()))))))))))))())())))))(()())))))))))))())(())))()))))))))())())(()))()))(())))()))()()(())()))))))()((((())()))())())))))()))()))))((()())()))))())))(())))))))))))))))))()))))()()())()))()()))))())()))((()())))())))(()))(()())))))))()))()))))(())))))))(())))))())()()(()))())()))()()))))())()()))))())()))())))))))(()))))()())()))))))))(()))())))(()))()))))(())()))())())(())())())))))))((((())))))()))()))()())()(())))()))()))()())(()())()()(()())()))))())())))))(()))()))))())(()()(())))))(())()()((())())))))(())(())))))))())))))))))()(())))))))()())())())()(()))))))))(()))))))))())()()))()(()))))))()))))))())))))))(())))()()(())()())))))(((())))()((())()))())))(()()))())(())())))()(((()())))))()(()()())))()()(()()(()()))())()(()()()))())()()))()())(()))))())))))())))(())()()))))(()))))(())(()))(())))))()()))()))))())()))()()(())())))((()))())()))))))()()))))((()(()))))()()))))))())))))())(()((()())))))))))))()())())))()))(()))))))(()))(())()())))(()))))))))())()()()()))))(()())))))))((())))()))(()))(())(())()())()))))))))(())))())))(()))()()))(()()))(()))())))()(())))())((()((()(())))((())))()))))((((())())()())))(())))()))))))())(()()((())))())()(()())))))(()())()))())))))))((())())))))))(()(()))())()()(()()(((()(((()())))))()))))))()(())(()()((()()(())()()))())()())()))()())())())))))))(((())))))))()()))))))(((())()))(()()))(()()))))(()(()()((((())()())((()()))))(()(())))))()((()()()())()()((()((()()))(()))(((()()()))(((())))()(((())()))))))((()(())())))(()())(((((()(()))(()((()))(()())()))))(()(()))()(()))(())(((())(()()))))()()))(((()))))(()()()()))())))((()()()(())()))()))))()()))()))))))((((((()()()))))())((()()(((()))))(()(())(()()())())())))()(((()()))(())((())))(()))(()()()())((())())())(()))))()))()((()(())()(()()(())(()))(())()))(())(()))))(())(())())(()()(()((()()((())))((()))()((())))(((()()()()((((()))(()()))()()()(((())((())())(()()(()()()))()((())(())()))())(((()()(())))()((()()())()())(()(())())(((())(())())((())(())()(((()()))(())))((())(()())())(())((()()()((((((())))((()(((((())()))()))(())(()()))()))(())()()))(())((()()())()()(()))())()((())))()((()()())((((()())((())())())((()((()))()))((())((()()(()((()()(((())(()()))))((()((())()(((())(()((())())((())(()((((((())())()(()())()(())(((())((((((()(())(()((()()()((()()(()()()())))()()(((((()()))()((((((()))()(()(()(()(((()())((()))())()((()))(())))()))()()))())()()))())((((())(()(()))(((((((())(((()(((((()(((()()((((())(((())())))(()()()(()(()))()))((((((()))((()(((()(())((()((((()((((((())(((((())))(((()(()))))(((()(((())()((())(()((()))(((()()(((())((((()(()(((((()))(((()(((((((()(()()()(()(()(()()())(())(((((()(())())()())(()(()(()))()(()()()())(()()(()((()))()((())())()(()))((())(()))()(()))()(((()(()(()((((((()()()()())()(((((()()(((()()()((()(((((()))((((((((()()()(((((()))))))(()()()(())(()))(()()))))(())()))(((((()(((((()()(()(()())(((()))((((()((()(()(()((()(()((())))()(((()((()))((()))(((((((((()((()((()(())))()((((()((()()))((())(((()(((((()()(()(()()((()(()()()(((((((())())()())))))((((()()(()))()))(()((())()(()(((((((((()()(((()(()())(()((()())((())())((((()(((()(((()((((()((()((((()(()((((((())((((((((((((()()(()()((((((((((((((()((()()))()((((((((((((())((((()(()())((()(()(()))()(((((()()(((()()))()())(())((()(((((()((())(((((()((()(((((()))()()((((())()((((())(((((((((()(())(()(())))())(()((())(((())(())(())())(()(()(())()()((()((())()(((()(((((()(())))()(((()((())))((()()()(((()(((()((()(()(())(()((()())(()(()(((()(((((((((())(()((((()()))(()((((()()()()(((()((((((((()(()()((((((()(()()(()((()((((((((((()()(((((((()())(())))(((()()))(((((()((()()())(()()((((())((()((((()))))(())((()(()()(((()(()(((()((((()(((((()))())())(()((())()))(((()())((())((())((((()((()((((((())(()((((()()))((((((())()(()))((()(((())((((((((((()()(((((()(((((()((()()()((((())))(()))()((()(())()()((()((((((((((()((())(())(((((()(()(()()))((((()((((()()((()(((()(((((((((()(()((()((()))((((((()(((())()()((()(((((((()())))()()(()((()((()()(((()(()()()()((((()((())((((()(((((((((()(((()()(((()(()(((()(((()((())()(()((()(()(()(()))()(((()))(()((((()((())((((())((((((())(()))(()((((())((()(()((((((((()()((((((()(()(()()()(())((()((()()(((()(((((((()()((()(((((((()))(((((()(((()(()()()(()(((()((()()((())(()(((((((((()(()((()((((((()()((())()))(((((()((())()())()(((((((((((()))((((()()()()())(()()(()(()()))()))(()))(()(((()()))())(()(()))()()((())(()())()())()(()))()))(()()(()((((((())((()(((((((((((()(())()((()(()((()((()(()((()((((((((((()()())((())()(())))((())()())()(((((()(()())((((()((()(())(()))(((())()((()))(((((())(()))()()(()))(((())((((()((((()(())))(((((((()))))())()())(())((())()(()()((()(()))()(()()(()()((()())((())((()()))((((()))()()))(()()(())()()(((((()(())((()((((()))()))(()())())(((()()(()()))(())))))(()))((())(((((()((((()))()((((()))()((())(((())))(((()())))((()(()()((

Formik not sending values from populated Autocomplete from external Source

Using React, Formik and Tailwind to send a form. I have some inputs that populate from Address autocomplete API(CanadaPost). Because I do not finish typing all the characters and API suggest some options for me, I just click the suggestions from the API. These options populates to the remain fields. Formik does not capture the state. It only captures what I typed. How do I I let Formik capture the remaining characters.

Fields are : address1,address2,city,state…
On adddress1, I type 8303, it will give me suggestions of addresses starting with 8303 then I will choose the correct one which then populate the correct data and pass them to input fields. The problem is Formik does not capture the states becuase the fields were not touched.

<Formik
initialValues = {{
address1: ""
address2: "",
city: "", 
zipCode: "",
state: "",
country: "",
}}

 onSubmit={(values, { setSubmitting, resetForm }) => {
 setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 2000);
resetForm();
}}
  validationSchema={validateSchema}
>

.......
</Formik>

I have tried
example 1

<label htmlFor="" className="relative block">
<span className="my-3">Address 1</span>
<input
type="text"
name="address1"
id=""
 onChange={(e, value) => {
setValidateBlur(false);
console.log(e.target.value);
setFieldValue("address1", value);
}}
 onBlur={handleBlur}
 defaultValue={values.address1}
 className="w-full py-2 pl-4 pr-3 mb-4 border rounded-md shadow-sm border-slate-300 focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm"
 />
{errors.address1 && touched.address1 && (
 <div className="w-full px-3 mb-4 text-red-900 bg-red-200 rounded-sm md:py-3 ">
 {errors.address1}
</div>
 )}
</label>

Example 2

<label htmlFor="" className="relative block">
<span className="my-3"> Address 1</span>
<input
 type="text"
name="address1"
id=""
onChange={handleChange}
onBlur={handleBlur}
value={values.address1}
className="w-full py-2 pl-4 pr-3 mb-4 border rounded-md shadow-sm border-slate-300 focus:outline-none focus:border-sky-500 focus:ring-sky-500 focus:ring-1 sm:text-sm"
/>
{errors.address1 && touched.address1 && (
 <div className="w-full px-3 mb-4 text-red-900 bg-red-200 rounded-sm md:py-3 ">
 {errors.address1}
</div>
)}
</label>

Is this possible without a database? [closed]

I need to create a website that has a form where a user can upload a document. Once they upload the document then a staff member will review the document and approve it or deny it. The user who uploaded the document will then get an email stating that their document has been approved or denied. If approved the user then and can finish filling out the form and submit the rest of their information. My question is… is this possible to do without having a database?