I'm working with PubNub. I have a standard WebRTC string being published with PubNub.
self.pubnub.publish(channel: self.channels[0], message: ["type": "offer", "sdp": sessionDesc.sdp]) { result in
Then the PubNub Listener listens to the Published signals on the Channel.
let listener = SubscriptionListener(queue: .main)
listener.didReceiveMessage = { message in
print("[Did Receive Message]: \(message)")
}
pubnub.add(listener)
pubnub.subscribe(to: channels, withPresence: true)
That works just fine, I get my SDP strings.
[Did Receive Message]: User 'pn-4D77E0B5-0145-ACAC-0366CB301ABC' sent '{"type":"offer","sdp":"v=0\r\no=- 4836309355638585269 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE audio video\r\na=msid-semantic: WMS ARDAMS\r\nm=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 102 0 8 106 105 13 110 112 113 126\r\nc=IN IP4 0.0.0.0\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=ice-ufrag:tKqW\r\na=ice-pwd:KNDM86R+JqsLqupw3J288kmJ\r\na=ice-options:trickle renomination\r\na=fingerprint:sha-256.....
My problem is that from within 'message'. How do I capture the 'type' and 'sdp' strings???
listener.didReceiveMessage = { message in
print("[Did Receive Message]: \(message)")
var type = message["type"] as? String <---- this does not work.
}
Thank you
Related
I am trying to call a 3rd Party API when a Client goes to a specific route using Swift and Vapor 3; however, I am met with errors despite being able to make the call.
I have taken steps to ensure the error is caused by the get request to the API. Currently, I do nothing with the request other than print the response. Removing the request stops the error from happening.
// Route the user to HomePage
router.get { req -> Future<View> in
let token: String = "THATS_MY_TOKEN"
let client = try req.client()
let bcmsrequest = try client.get("https://api.buttercms.com/v2/posts/?page=1&page_size=10&auth_token=" + token)
print(bcmsrequest)
print("This line prints.")
// Removing the above get request stops the error below from happening
return try req.view().render("welcome")
}
// Here is the stdout printed by the server process:
Server starting on http://localhost:8080
NIO.EventLoopFuture<Vapor.Response>
This line prints.
2019-07-27 11:49:12.249196-0400 Run[6348:121267] [] nw_endpoint_get_type called with null endpoint
2019-07-27 11:49:12.249420-0400 Run[6348:121267] [] nw_endpoint_get_type called with null endpoint, dumping backtrace:
[x86_64] libnetcore-1872
0 libnetwork.dylib 0x00007fff6d188fc8 __nw_create_backtrace_string + 120
1 libnetwork.dylib 0x00007fff6ce12af4 nw_endpoint_get_type + 180
2 libboringssl.dylib 0x00007fff6b6e3af2 nw_protocol_boringssl_get_subject_name + 178
3 libboringssl.dylib 0x00007fff6b6e6997 nw_protocol_boringssl_connected + 916
4 libnetwork.dylib 0x00007fff6ce5d145 nw_socket_handle_socket_event + 1733
5 libdispatch.dylib 0x00000001017fd82f _dispatch_client_callout + 8
6 libdispatch.dylib 0x0000000101800689 _dispatch_continuation_pop + 585
7 libdispatch.dylib 0x0000000101816608 _dispatch_source_invoke + 2135
8 libdispatch.dylib 0x0000000101807665 _dispatch_workloop_invoke + 3477
9 libdispatch.dylib 0x0000000101813025 _dispatch_workloop_worker_thread + 676
10 libsystem_pthread.dylib 0x000000010188f343 _pthread_wqthread.cold.1 + 125
11 libsystem_pthread.dylib 0x0000000101889196 _pthread_wqthread + 203
12 libsystem_pthread.dylib 0x0000000101889057 start_wqthread + 15
I can see that a Future Object is being printed out, I would expect to see response content (a JSON string) - but I believe that the response has no content and is actually failing to make a request at all.
I can see that a Future Object is being printed out, I would expect to see response content
So this is the crux of the problem. Because Vapor is asynchronous, you're printing the Future<Response> as soon as you send the request, meaning it hasn't returned yet. If you change it to:
router.get { req -> Future<View> in
let token: String = "THATS_MY_TOKEN"
let client = try req.client()
let bcmsrequest = try client.get("https://api.buttercms.com/v2/posts/?page=1&page_size=10&auth_token=" + token)
return bcmsrequest.flatMap { response in
print(response)
return try req.view().render("welcome")
}
}
You'll see the full response body and see what errors you're getting (if any)
I am experiencing strange behavior in Scrapy. I collect status codes by calling response.status, by not all of them are present (Seems to be 3xx). I see in the log the following thing:
downloader/response_status_count/200: 8150
downloader/response_status_count/301: 226
downloader/response_status_count/302: 67
downloader/response_status_count/303: 1
downloader/response_status_count/307: 48
downloader/response_status_count/400: 7
downloader/response_status_count/403: 44
downloader/response_status_count/404: 238
downloader/response_status_count/405: 8
downloader/response_status_count/406: 26
downloader/response_status_count/410: 7
downloader/response_status_count/500: 12
downloader/response_status_count/502: 6
downloader/response_status_count/503: 3
whereas my csv file has only 200, 404, 403, 406, 502, 400, 405, 410, 500, 503. I set HTTPERROR_ALLOW_ALL=True in the settings.py. Can I force Scrapy to provide information about redirects? Right know I am taking it from response.meta['redirect_times'] and response.meta['redirect_urls'], but status code is still 200, instead of 3xx.
30X responses will never reach your callback (parse method) because they are being handles by a redirect middleware before that.
However all of the response statuses are already stored in scrapy stats as you have pointed out yourself which means you can easily pull them in your crawler at any point:
In your callback:
def parse(self, response):
stats = self.crawler.stats.get_stats()
status_stats = {
k: v for k, v in stats.items()
if 'status_count' in k
}
# {'downloader/response_status_count/200': 1}
In your pipeline (see docs for how to use pipelines):
class SaveStatsPipeline:
"""Save response status stats in a stats.json file"""
def close_spider(self, spider):
"""When spider closes save all status stats in a stats.json file"""
stats = spider.crawler.stats.get_stats()
status_stats = {
k: v for k, v in stats.items()
if 'status_count' in k
}
with open('stats.json', 'w') as f:
f.write(json.dumps(status_stats))
Anywhere where you have access to crawler object really!
Trying to use the following piece of code to trigger email notifications for a multi-branch pipeline job:
1 def emailNotification() {
2 def to = emailextrecipients([[$class: 'CulpritsRecipientProvider'],
3 [$class: 'DevelopersRecipientProvider'],
4 [$class: 'RequesterRecipientProvider']])
5
6 //def to = "firstname.lastname#domain.com"
7 //String currentResult = currentBuild.result
8 String currentResult = manager.build.getResult()
9 echo "CurrentResult1=${currentResult}"
10 echo "CurrentResult2=${manager.build.getResult()}"
11 echo "CurrentResult3=${manager.build.result}"
12 String previousResult = currentBuild.getPreviousBuild().result
13
14 def causes = currentBuild.rawBuild.getCauses()
15 // E.g. 'started by user', 'triggered by scm change'
16 def cause = null
17 if (!causes.isEmpty()) {
18 cause = causes[0].getShortDescription()
19 }
20
21 // Ensure we don't keep a list of causes, or we get
22 // "java.io.NotSerializableException: hudson.model.Cause$UserIdCause"
23 // see http://stackoverflow.com/a/37897833/509706
25 causes = null
26
27 String subject = "${env.JOB_NAME} ${env.BUILD_NUMBER}: ${currentResult}"
28
29 String body = """
30 <p>Triggered by: <b>${cause}</b></p>
31
32 <p>Last build result: <b>${previousResult}</b></p>
33
34
35 <p>Build <b>${env.BUILD_NUMBER}</b> ran on <b>${env.NODE_NAME}</b> and terminated with <b>${currentResult}</b>.
36 </p>
37
38 <p>See: ${env.BUILD_URL}</p>
39
40 """
41
42 String log = currentBuild.rawBuild.getLog(40).join('\n')
43 if (currentBuild != 'SUCCESS') {
44 body = body + """
45 <h2>Last lines of output</h2>
46 <pre>${log}</pre>
47 """
48 }
49
50 if (to != null && !to.isEmpty()) {
51 // Email on any failures, and on first success.
52 if (currentResult != 'SUCCESS' || currentResult != previousResult) {
53 mail to: to, subject: subject, body: body, mimeType: "text/html"
54 }
55 echo 'Sent email notification'
56 }
57 }
Now, the problems that I'm facing:
def to = emailextrecipients... is not working. I found this and this Jenkins Jira issues that this may be the causes, but no workaround. Although it seems weird that if the build is started manually, say by me a user authenticated through Github Oauth, the mail can be sent. If the Github is starting the build through the webhook, I'm getting this in the Jenkins logs:
Not sending mail to user firstname.lastname#domain.com with no
permission to view
The second issue that I'm seeing is with the PostBuild email trigger.
The Pipeline looks like this:
def emailNotification() {
//the one from above
}
try {
stage('Stage1') {
/*
creating multiple nodes based on an array provided
each node will execute:
checkout scm
buildSolution() //custom method defined
*/
parallel <stuff_above>
}
stage('Stage2') {
//do other stuff
parallel <other_stuff_above>
}
} finally {
emailNotification()
}
The echoes from above (rows 9-11) are all showing null
CurrentResult1=null
CurrentResult2=null
CurrentResult3=null
Using currentBuild.currentResult will show me only SUCCESS or FAILED, but not UNSTABLE, in case some of the tests failed.
Any ideas where the problem is?
Build status is null until something sets it or until the job finishes. Are you using any unit test steps that would cause the build to be unstable?
You don't need to use emailextrecipients instead use.
emailext body: body, mimeType: 'text/html', recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']], subject: subject
Not sending mail to user firstname.lastname#domain.com with no
permission to view
Means that either no jenkins user has this email address associated or the user it is associated with does not have permission to the job
Also for causes put that logic inside a different function and add #NonCPS annotation which will stop jenkins trying to serialise state while that function is running, as you currently have it there is a small chance it will still break with that exception, see https://stackoverflow.com/a/38439681/963402
I'm using the Sdp class from the Microsoft.Rtc.Signaling namespace.
Now I want to parse the following Sdp-Text:
v=0
o=- 0 0 IN IP4 192.168.253.202
s=session
c=IN IP4 239.168.253.202
t=0 0
m=message 5060 sip null
a=accept-types:text/plain
using the following code:
var text = #"v=0
o=- 0 0 IN IP4 192.168.253.202
s=session
c=IN IP4 239.168.253.202
t=0 0
m=message 5060 sip null
a=accept-types:text/plain
";
Sdp<SdpGlobalDescription, SdpMediaDescription> sessionDescription2 = new Sdp<SdpGlobalDescription, SdpMediaDescription>();
var encodedText = Encoding.ASCII.GetBytes(text);
if (sessionDescription2.TryParse(encodedText, 0, encodedText.Length, false))
{
sessionDescription2.Dump();
IList<SdpMediaDescription> activeMediaTypes = sessionDescription2.MediaDescriptions;
foreach (var sdpMediaDescription in activeMediaTypes)
{
sdpMediaDescription.Dump();
foreach (var sdpBandwidth in sdpMediaDescription.Bandwidths)
{
sdpBandwidth.Dump();
}
foreach (var sdpAttribute in sdpMediaDescription.Attributes)
{
sdpAttribute.Dump();
}
}
}
else
{
sessionDescription2.LastParseErrorMessage.Dump();
sessionDescription2.LastParseErrorLineNumber.Dump();
}
Console.ReadLine();
.Dump() is from nuget ConsoleDump Package.
All information is parsed but the 'c' connection is set to null.
Any hint?
That was easy.
I must look in sessionDescription2.GlobalDescription - there it is!
I created a new Play 2.5.3 project and I'm getting this error.
I read in another answer the driver was out of date, so I added what I believe to be the latest driver like this:
I added the postgress driver dependency like this:
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)
But still getting the error. Any idea how to fix this?
It seems that this function is really not implemented in version 9.1-901 of the driver
see a source code:
http://grepcode.com/file/repo1.maven.org/maven2/postgresql/postgresql/9.1-901.jdbc4/org/postgresql/jdbc4/AbstractJdbc4Connection.java#AbstractJdbc4Connection.isValid%28int%29
117 public boolean isValid(int timeout) throws SQLException
118 {
119 checkClosed();
120 throw org.postgresql.Driver.notImplemented(this.getClass(), "isValid(int)");
121 }
You can use a newer version of the driver, currently the newest driver is: Version 9.4-1208, see this link: https://jdbc.postgresql.org/
Or you can implement this funcion on your own - you can copy their implementation from here:
http://grepcode.com/file/repo1.maven.org/maven2/org.postgresql/postgresql/9.4-1201-jdbc41/org/postgresql/jdbc4/AbstractJdbc4Connection.java#AbstractJdbc4Connection.isValid%28int%29
127 public boolean isValid(int timeout) throws SQLException
128 {
129 if (isClosed()) {
130 return false;
131 }
132 if (timeout < 0) {
133 throw new PSQLException(GT.tr("Invalid timeout ({0}<0).", timeout), PSQLState.INVALID_PARAMETER_VALUE);
134 }
135 boolean valid = false;
136 Statement stmt = null;
137 try {
138 if (!isClosed()) {
139 stmt = createStatement();
140 stmt.setQueryTimeout( timeout );
141 stmt.executeUpdate( "" );
142 valid = true;
143 }
144 }
145 catch ( SQLException e) {
146 getLogger().log(GT.tr("Validating connection."),e);
147 }
148 finally
149 {
150 if(stmt!=null) try {stmt.close();}catch(Exception ex){}
151 }
152 return valid;
153}